ajout d'un boutton poussoir
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#define NUM_LEDS 12
|
||||
#define DATA_PIN 4 // Change this to match your LED strip's data pin
|
||||
#define BUTTON_PIN 2 // Change this to match your LED strip's data pin
|
||||
#define BRIGHTNESS 25
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
@@ -17,17 +18,28 @@ int second=0;
|
||||
void setup() {
|
||||
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
|
||||
FastLED.setBrightness(BRIGHTNESS);
|
||||
|
||||
|
||||
Serial.begin(115200);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
int buttonState = digitalRead(BUTTON_PIN);
|
||||
uint8_t ledhour = (hour * NUM_LEDS) / 24;
|
||||
uint8_t ledmin =(minute * NUM_LEDS) / 60;
|
||||
uint8_t ledsec =(second * NUM_LEDS) / 60;
|
||||
for(uint8_t dot=0 ; dot< NUM_LEDS ; dot++) {
|
||||
leds[dot].setRGB( 255*(ledhour==dot) , 255*(ledsec==dot), 255*(ledmin==dot));
|
||||
if(buttonState == LOW ) {
|
||||
|
||||
leds[dot].setRGB( 255*(ledhour==dot) ,
|
||||
255*(ledsec==dot)+ 64 * ( (ledsec-1) ==dot ) + 16 *((ledsec-2)==dot),
|
||||
255*(ledmin==dot));
|
||||
|
||||
} else {
|
||||
leds[dot].setRGB(0,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user