Hi!
I want to build a lamp for a friend using WS2812B adressable LEDs and an ESP8266.
Therefore there is a user-input of three buttons. One for brightness, one for color and one for mode - control. Using the WS2812B LEDs on the ESP8266 isnt the problem, it already works fine.
What is causing me headaches is the use of interrupts to read the user inputs. It should work like this:
button press -> ISR -> brightness ++/mode++/color++
I therefore wrote a small code to test the interrupts but I didnt get it work yet. Maybe someone could have a look over it and let me know what my mistake is.
The buttons are connecting the pins to GND when being pressed and are pulled to 3.3V through the uC. Futhermore those are debounced on the hardware-side (RC-network to increase the time constant).
Here is my test code:
uint8_t brightness = 0, mode = 0, color = 0;
void setup() {
Serial.begin(9600);
pinMode(14, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(14), func_brightness, LOW);
attachInterrupt(digitalPinToInterrupt(12), func_mode, LOW);
attachInterrupt(digitalPinToInterrupt(13), func_color, LOW);
}
void loop() {
Serial.println("loop");
delay(500);
}
void func_brightness() {
brightness ++;
Serial.println("brightness: " + brightness);
}
void func_mode() {
mode ++;
Serial.println("mode: " + mode);
}
void func_color() {
color ++;
Serial.println("color: " + color);
}
According to it I would expect an increase in brightness, mode and color when I press the buttons as well as a new line in the SerialMonitor. However none of this happens.
Greetings from Germany,
Vince