led power control

abrazik
JbLb 4 years ago
parent 275af8599b
commit 549425dbca

@ -88,14 +88,15 @@ int consigne_speed = 10;
int actual_speed = 0; int actual_speed = 0;
int btn_control = 20; 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 rel_marche = true;
bool run_mode = false; // false by default
CRGB powerled;
// ################ Led definition ######################## // ################ Led definition ########################
#define LED_PIN 7 #define LED_PIN 7
#define NUM_LEDS 10 #define NUM_LEDS 9
#define LED_TYPE WS2812B #define LED_TYPE WS2812B
#define COLOR_ORDER GRB #define COLOR_ORDER GRB
@ -120,10 +121,12 @@ void setup()
consigne_speed = MAX_SPEED ; consigne_speed = MAX_SPEED ;
} }
LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS); LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,NUM_LEDS);
LEDS.setBrightness(64); LEDS.setBrightness(32);
FastLED.clear (); memset(leds, 0, NUM_LEDS * 3); // all leds off
// leds[0] = CRGB(255,0,0); // FastLED.clear ();
// LEDS.show(); powerled = CRGB(128,32,0);
leds[0] = powerled;
LEDS.show();
Serial.begin(SERIAL_BAUD); Serial.begin(SERIAL_BAUD);
if (Serial) { if (Serial) {
@ -304,13 +307,14 @@ void loop(void)
// Check for new received data // Check for new received data
Receive(); Receive();
Send(0,actual_speed); // Send(0,actual_speed);
if ( actual_speed != accel_speed){
accel_speed = actual_speed; // if (Serial) Serial.println(actual_speed);
if (Serial) Serial.println(actual_speed);
}
if (iTimeSend > timeNow) return; if (iTimeSend > timeNow) return;
iTimeSend = timeNow + TIME_SEND; iTimeSend = timeNow + TIME_SEND;
Send(0,actual_speed);
if (Serial) { if (Serial) {
if (run_mode != last_run) { if (run_mode != last_run) {
last_run = run_mode; last_run = run_mode;
@ -330,29 +334,40 @@ void loop(void)
actual_speed --; actual_speed --;
} }
} }
// indication vitesse sur barre leds
int max_vit = int(actual_speed / 70); int max_vit = int(actual_speed / 70);
for (int i_led = 1; i_led < max_vit; i_led = i_led +1 ) 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] = CRGB(0,255,0); leds[i_led + 1] = CRGB(0,255,0);
} }
} else { } else { // rouge si stop
FastLED.clear (); FastLED.clear ();
leds[0] = powerled;
leds[1] = CRGB(255,0,0); // Red leds[1] = CRGB(255,0,0); // Red
} }
LEDS.show(); // update LEDS
run_control(); run_control();
btn_control --; btn_control --;
if (btn_control == 0){ if (btn_control == 0){
btn_control =8; btn_control = 6;
speed_control(); speed_control();
} }
LEDS.show(); // update LEDS
// Blink the LED // 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 ########################## // ########################## END ##########################

Loading…
Cancel
Save