no encoder readings..
-
Hi all, I'm trying to work with this incremental rotary encoder connected straight on GROVE port (no resistence), with this sketch:
#include <M5Stack.h> float XA_SIG = 0, XB_SIG = 1, YA_SIG = 0, YB_SIG = 1; volatile float pulsesX, pulsesY; void setup() { M5.begin(); pinMode(22, INPUT_PULLUP); // internal pullup input pin pinMode(21, INPUT_PULLUP); // internalเป็น pullup input pin attachInterrupt(22, XA_RISE, RISING); // Pin 2 stack 22? attachInterrupt(21, XB_RISE, RISING); // Pin 3 stack 21? Serial.begin(115200); delay(100); Serial.println("Connected"); }//setup void loop() { Serial.print("x"); Serial.print(pulsesX); Serial.println("end"); delay(20); } //X-Axis void XA_RISE() { detachInterrupt(22); //delay(1); XA_SIG = 1; if (XB_SIG == 0) { pulsesX++;//moving forward } if (XB_SIG == 1) { pulsesX--;//moving reverse } attachInterrupt(22, XA_FALL, FALLING); } void XA_FALL() { detachInterrupt(22); //delay(1); XA_SIG = 0; if (XB_SIG == 1) { pulsesX++;//moving forward } if (XB_SIG == 0) { pulsesX--;//moving reverse } attachInterrupt(22, XA_RISE, RISING); } void XB_RISE() { detachInterrupt(21); //delay(1); XB_SIG = 1; if (XA_SIG == 1) { pulsesX++;//moving forward } if (XA_SIG == 0) { pulsesX--;//moving reverse } attachInterrupt(21, XB_FALL, FALLING); } void XB_FALL() { detachInterrupt(21); //delay(1); XB_SIG = 0; if (XA_SIG == 0) { pulsesX++;//moving forwar } if (XA_SIG == 1) { pulsesX--;//moving reverse } attachInterrupt(21, XB_RISE, RISING); }
but, when I touch the encoder I have no readings on serial monitor..
x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end x0.00end
whats wrong??
maybe something about IRAM_ATTR ISR() ??
tnks
-
nobody??