Hi all,
I just wired up a SR1230rotary encoder to a nano and it works, using the below code. (arduino 2.3.3, linux appimage on Fedora40)
Wondering how it's calling the encoder routine here, as the output value does change with rotation of the encoder. All the void loop () appears to be doing is printing out the value, doesn't appear to be calling the subroutine for the value - has there been a change in logic that I'm not aware of.
Glad it works, but would like to understand how the subroutine is being called, if that makes sense.
Purchased the encoder from here:
https://www.electusdistribution.com.au/dbdocument/746336/sr1230_manual_26279.pdf , and figured their instructions would be a good starting point.
used INPUT_PULLUP without the capacitors to see if it worked.
Any advice you can offer would be greatly appreciated.
A
#define enc_a 2
#define enc_b 3
volatile int encoderValue = 0;
void setup() {
Serial.begin(9600);
pinMode(enc_a, INPUT_PULLUP);
pinMode(enc_b, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(enc_a), encoder, FALLING);
}
void loop() {
Serial.println(encoderValue);
delay(100);
}
void encoder() {
if (digitalRead(enc_a) == digitalRead(enc_b)) {
encoderValue++;
}
else {
encoderValue--;
}
}
Background,
I'm a classically trained musician as well as an engineer.
Setting up a metronome on Arduino to mimic the conductor's baton (two servos crossed at 90Ā°) as there's no way I can hear a regular metronome while I'm practising.
Going to set up a rotary encoder to adjust tempo, and two rotary switches for time signature (eg: 12/3, 12/8, etc...)