@@ -45,7 +45,8 @@ using namespace arythmatik;
4545// Declare A-RYTH-MATIK hardware variable.
4646Arythmatik hw;
4747
48- byte counter = 0 ;
48+ // Since counter is modified in the CLK/RST handler, it should be volatile.
49+ volatile int counter;
4950
5051void setup () {
5152 // Inside the setup, set config values prior to calling hw.Init().
@@ -60,6 +61,10 @@ void setup() {
6061 hw.eb.setEncoderHandler(UpdateRotate);
6162 hw.eb.setClickHandler(UpdatePress);
6263
64+ // Attach CLK & RST pin change handlers.
65+ hw.AttachClockHandler(HandleClockPinChange);
66+ hw.AttachResetHandler(HandleResetPinChange);
67+
6368 // Initialize the A-RYTH-MATIK peripherials.
6469 hw.Init();
6570}
@@ -68,11 +73,6 @@ void loop() {
6873 // Read cv inputs and process encoder state to determine state for this loop.
6974 hw.ProcessInputs();
7075
71- // Advance the counter on CLK input
72- if (hw.clk.State() == DigitalInput::STATE_RISING) {
73- counter = ++counter % OUTPUT_COUNT;
74- }
75-
7676 // Activate the current counter output.
7777 for (int i = 0; i < OUTPUT_COUNT; i++) {
7878 (i == counter)
@@ -87,6 +87,19 @@ void loop() {
8787 hw.display.display();
8888}
8989
90+ void HandleClockPinChange () {
91+ // Advance the counter on CLK input
92+ if (hw.clk.Read() == HIGH) {
93+ counter = ++counter % OUTPUT_COUNT;
94+ }
95+ }
96+
97+ void HandleResetPinChange () {
98+ if (hw.rst.Read() == HIGH) {
99+ counter = 0;
100+ }
101+ }
102+
90103void UpdateRotate (EncoderButton &eb) {
91104 // Read the configured encoder direction (according to hw.config.ReverseEncoder setting).
92105 Direction dir = hw.EncoderDirection();
0 commit comments