Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Gerhard34
#31086 hi brutzler,
do you finally have a working rotary encoder? Could you pls share your code?

I'm trying to build a follow focus with a rotary on the remote control. The encoder information will be transmitted via UDP to a central unit.
I didn't get any eupts - what's wrong?
Code: Select all#define encoder0PinA  2
#define encoder0PinB  14

void setup() {
  Serial.begin(115200);

//Set ENCODER
  pinMode(encoder0PinA, INPUT_PULLUP);
  pinMode(encoder0PinB, INPUT_PULLUP);
  attachInterrupt(0, doEncoder, CHANGE);
}

void doEncoder() {  //Read encoder and set manualy defined temperature.
  if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
    Serial.println("+");
  }
  else {
    Serial.println("-");
  }
}

void loop() {
    Serial.print("   ");Serial.print(byte(digitalRead(encoder0PinA)));
    Serial.print("   ");Serial.println(byte(digitalRead(encoder0PinB)));
delay(1000);
}
thx
Gerhard
User avatar
By Caio Pedreira
#57965 Here's how one can use an interrupt service routine (ISR) on the FLASH button of an ESP-12E module, as known as NodeMCU:

Code: Select all#define FLASH_BUTTON_PIN    0         // FLASH BUTTON in NodeMCU at pin GPIO0
#define LED                 16        // Led in NodeMCU at pin GPIO16 (D0).
volatile byte LED_state = HIGH;

void setup() {
  pinMode(LED, OUTPUT);   // LED pin as output.
  pinMode(FLASH_BUTTON_PIN, INPUT_PULLUP); // ==> FLASH BUTTON DEFAULT IS HIGH !!
  digitalWrite(LED, HIGH);         // turn the LED off.
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(FLASH_BUTTON_PIN), pressedButton, FALLING); // USER PRESSED FLASH BUTTON !
}

void loop() {
  //Serial.println(digitalRead(FLASH_BUTTON_PIN)); // PRINT HIGH == 1
  digitalWrite(LED, LED_state);
}

void pressedButton() {
  Serial.println(F("BUTTON PRESSED !!!"));
  LED_state = !LED_state;   // interrupt service routine (ISR) can ONLY modify VOLATILE variables
  /*
  // LED BLINKS:
  // function delay() does NOT work inside interrupt service routine (ISR)
  digitalWrite(LED, LOW);          // turn the LED on. 
  Serial.println(millis());
  delayMicroseconds(1000); // function delayMicroseconds works !
  Serial.println(millis());
  digitalWrite(LED, HIGH);         // turn the LED off.
  */
}
User avatar
By mars000
#74429 has anybody been able to confirm support more than 3 interrupts on esp8266. I'm using wemos min pro but when using below code - it compiles fine but only the first 3 get activated. Is there a limit with ESP8266 ?

Code: Select all      attachInterrupt(sensorPin_1, pulseCounter_1, FALLING);
      attachInterrupt(sensorPin_2, pulseCounter_2, FALLING);
      attachInterrupt(sensorPin_3, pulseCounter_3, FALLING);
      attachInterrupt(sensorPin_4, pulseCounter_4, FALLING);