Hey everyone, I'm still new to Arduino coding. So far I've been able to put this together, it's a code to control a LED strip. there's a button for colour (BTN), brightness (BTN2) and patterns (BTN3). Wanted to add a double press to go to the previous colour (BTN) and pattern (BTN3). Just wondering if anyone has any suggestions or a good tutorial to look at. Thanks
#include <FastLED.h>
#include <OneButton.h>
#define LED_PIN 2
#define BTN_PIN 3
#define BTN2_PIN 4
#define BTN3_PIN 5
#define NUM_LEDS 72
CRGB leds[NUM_LEDS];
uint8_t patternCounter = 0;
uint8_t patternCounter2 = 0;
uint8_t patternCounter3 = 0;
OneButton btn = OneButton(BTN_PIN, true, true);
OneButton btn2 = OneButton(BTN2_PIN, true, true);
OneButton btn3 = OneButton(BTN3_PIN, true, true);
int a = 4;
int b = 30;
int c = 40;
int d = 40;
int e = 40;
int f = c;
int x = 0;
int y = 0;
int z = 100;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
btn.attachClick(nextPattern);
btn2.attachClick(nextPattern2);
btn3.attachClick(nextPattern3);
}
void loop() {
switch (patternCounter) {
}
switch (patternCounter2) {
}
switch (patternCounter3) {
}
fadeToBlackBy(leds, NUM_LEDS, a);
FastLED.show();
btn.tick();
btn2.tick();
btn3.tick();
}
void nextPattern() {
patternCounter = (patternCounter + 1) % 21;
}
void nextPattern2() {
patternCounter2 = (patternCounter2 + 1) % 3;
}
void nextPattern3() {
patternCounter3 = (patternCounter3 + 1) % 16;
}
//colour
//Brightness
//Pattern
Yes - the library he is already using supports double click detection. As @LarryD indicated it’s just about registering the callback for it and providing that callback.