![]() Int encoder_y_som = (encoder_y_encoded_laatste << 2) | encoder_y_encoded //adding it to the previous encoded value Int encoder_y_encoded = (encoder_y_msb << 1) | encoder_y_lsb //converting the 2 pin value to single number Int encoder_y_lsb = digitalRead(encoder_y_pin_b) //LSB = least significant bit Int encoder_y_msb = digitalRead(encoder_y_pin_a) //MSB = most significant bit If(encoder_x_som = 0b1110 || encoder_x_som = 0b0111 ||encoder_x_som = 0b0001 || encoder_x_som = 0b1000)Įncoder_x_encoded_laatste = encoder_x_encoded //store this value for next time Int encoder_x_som = (encoder_x_encoded_laatste << 2) | encoder_x_encoded //adding it to the previous encoded value Int encoder_x_encoded = (encoder_x_msb << 1) | encoder_x_lsb //converting the 2 pin value to single number Int encoder_x_lsb = digitalRead(encoder_x_pin_b) //LSB = least significant bit Int encoder_x_msb = digitalRead(encoder_x_pin_a) //MSB = most significant bit ![]() Volatile int encoder_z_encoded_laatste = 0 ĪttachInterrupt(0, encoder_x, CHANGE) // INT4 -> Pin 2ĪttachInterrupt(1, encoder_x, CHANGE) // INT5 -> Pin 3ĪttachInterrupt(2, encoder_y, CHANGE) // INT0 -> Pin 21ĪttachInterrupt(3, encoder_y, CHANGE) // INT1 -> Pin 20ĪttachInterrupt(4, encoder_z, CHANGE) // INT2 -> Pin 19ĪttachInterrupt(5, encoder_z, CHANGE) // INT3 -> Pin 18 Volatile int encoder_y_encoded_laatste = 0 Volatile int encoder_x_encoded_laatste = 0 I use binary to save the last state of the encoder decide which way the encoder is rotating.the functions that are executed on the interrupts are 3 of the same.My guesses are that I have to disable or enable something to be able to use pins 20 & 21 as external interrups, but I can't seem to make that happen. I've been browsing on the web for hours now and every example that I could find was talking about other boards than the Mega 2560 or were talking about the switch-cases 0 & 1 of the attachInterrupt function (which are perfectly working for me, I have problems with cases 2 & 3). This shouldn't be a problem since the Arduino Mega 2560 has 6 external interrupt pins (2, 3, 18, 19, 20, 21).īut now comes the problem, I can make pin 2 (INT4), pin 3 (INT5), pin 18 (INT3) & pin 19 (INT2) to work, but whatever I try, I cant seem to get the pins 21 & 20 (INT1 & INT0) to work.įirst I thought that the pin mapping was off, but I later found out that the attachInterrupt function uses a switch statement which creates all the confusion. I've been cracking my brains over this the last few days.įor a project for my study I have to develop a model gantry crane which will use 3 rotary encoders.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |