From 549425dbcae41dc5a9de244f32d7445e7bf5d203 Mon Sep 17 00:00:00 2001 From: JbLb Date: Fri, 20 May 2022 11:10:29 +0200 Subject: [PATCH] led power control --- src/hoverserial.ino | 55 ++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/hoverserial.ino b/src/hoverserial.ino index 64e15b3..203113b 100644 --- a/src/hoverserial.ino +++ b/src/hoverserial.ino @@ -88,14 +88,15 @@ int consigne_speed = 10; int actual_speed = 0; int btn_control = 20; -bool run_mode, last_run, last_plus, last_moins, last_marche = false; +bool last_run, last_plus, last_moins, last_marche = false; bool rel_marche = true; +bool run_mode = false; // false by default - + CRGB powerled; // ################ Led definition ######################## #define LED_PIN 7 -#define NUM_LEDS 10 +#define NUM_LEDS 9 #define LED_TYPE WS2812B #define COLOR_ORDER GRB @@ -120,10 +121,12 @@ void setup() consigne_speed = MAX_SPEED ; } LEDS.addLeds(leds,NUM_LEDS); - LEDS.setBrightness(64); - FastLED.clear (); - // leds[0] = CRGB(255,0,0); - // LEDS.show(); + LEDS.setBrightness(32); + memset(leds, 0, NUM_LEDS * 3); // all leds off + // FastLED.clear (); + powerled = CRGB(128,32,0); + leds[0] = powerled; + LEDS.show(); Serial.begin(SERIAL_BAUD); if (Serial) { @@ -304,13 +307,14 @@ void loop(void) // Check for new received data Receive(); - Send(0,actual_speed); - if ( actual_speed != accel_speed){ - accel_speed = actual_speed; - if (Serial) Serial.println(actual_speed); - } + // Send(0,actual_speed); + + // if (Serial) Serial.println(actual_speed); + if (iTimeSend > timeNow) return; + iTimeSend = timeNow + TIME_SEND; + Send(0,actual_speed); if (Serial) { if (run_mode != last_run) { last_run = run_mode; @@ -330,29 +334,40 @@ void loop(void) actual_speed --; } } - + // indication vitesse sur barre leds int max_vit = int(actual_speed / 70); - for (int i_led = 1; i_led < max_vit; i_led = i_led +1 ) - { - leds[i_led] = CRGB(0,255,0); + memset(leds, 0, NUM_LEDS * 3); // all leds off + leds[0] = powerled; + + for (int i_led = 0; i_led-1 < max_vit ; i_led = i_led +1 ) + { + leds[i_led + 1] = CRGB(0,255,0); } - } else { + } else { // rouge si stop FastLED.clear (); + leds[0] = powerled; + leds[1] = CRGB(255,0,0); // Red } + LEDS.show(); // update LEDS + run_control(); + btn_control --; if (btn_control == 0){ - btn_control =8; + btn_control = 6; speed_control(); } - LEDS.show(); // update LEDS + // Blink the LED - digitalWrite(LED_BUILTIN, (timeNow % 2000) < 1000); + //digitalWrite(LED_BUILTIN, (timeNow % 2000) < 1000); + + ((timeNow % 2000) < 1000)?powerled = CRGB(128,32,0):powerled = CRGB(0,0,0); + } // ########################## END ##########################