ajout du control bouton dans dual color

reformatage de code
master
JbLb 4 years ago
parent e4e8049eda
commit ae82931203

@ -57,7 +57,8 @@ void dual_color(struct CRGB color1, struct CRGB color2, uint8_t wait)
} }
} }
void xmas(uint8_t wait){ void xmas(uint8_t wait)
{
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
for (int i = 0; i < NUM_LEDS; i++) { for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ((i % 2) == j) ? CRGB::Red : CRGB::Green; leds[i] = ((i % 2) == j) ? CRGB::Red : CRGB::Green;
@ -66,8 +67,10 @@ void xmas(uint8_t wait){
delay(wait); delay(wait);
} }
} }
// change run_mod return true si appuis cour // change run_mod return true si appuis cour
boolean check_button(){ boolean check_button()
{
if (button1.checkPress() == 1) { if (button1.checkPress() == 1) {
// SHORT PRESS! // SHORT PRESS!
if (!run_mod) { if (!run_mod) {
@ -105,8 +108,10 @@ if (run_mod){
break; break;
} }
} }
if (breaked) break; if (breaked || check_button()) {
if (check_button()) break; memset(leds, 0, NUM_LEDS * 3); // all leds off
break;
}
delay(tempo_anim); delay(tempo_anim);
for (int i = 0; i < NUM_LEDS; i++) { for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Green; leds[i] = CRGB::Green;
@ -119,26 +124,39 @@ if (run_mod){
} }
delay(tempo_anim); delay(tempo_anim);
if (breaked) break; if (breaked)
if (check_button()) break; break;
if (check_button())
break;
} }
} }
breaked = false;
// dual color // dual color
if (run_mod) { if (run_mod) {
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
dual_color(CRGB::Red, CRGB::Green, tempo_anim); for (int i = 0; i < NUM_LEDS; i++) {
if (check_button()) break; memset(leds, 0, NUM_LEDS * 3); // all leds off
leds[i] = CRGB::Red;
leds[NUM_LEDS - (i + 1)] = CRGB::Green;
FastSPI_LED.show();
delay(tempo_anim);
if (check_button()) {
breaked = true;
break;
}
}
if (breaked)
break;
} }
} }
// Xmas // Xmas
if (run_mod) { if (run_mod) {
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
xmas(tempo_anim); xmas(tempo_anim);
if (check_button()) break; if (check_button())
break;
} }
} }
// aller-retour // aller-retour
if (run_mod) { if (run_mod) {
int i = 1; int i = 1;
@ -150,9 +168,11 @@ if (run_mod){
delay(tempo_anim / 2); delay(tempo_anim / 2);
leds[j] = CRGB::Black; leds[j] = CRGB::Black;
j = j + i; j = j + i;
if(j==NUM_LEDS- 1|| j==0) i= -i; if (j == NUM_LEDS - 1 || j == 0)
i = -i;
if (check_button()) break; if (check_button())
break;
} }
} }
check_button(); check_button();

Loading…
Cancel
Save