0

Why does my code not works? (Arduino language)

This is my code #define BUTL 13 #define BUTR 12 #define BUTC 11 #define LEDL 3 #define LEDR 2 bool R = false; bool L = false; void setup() { // put your setup code here, to run once: pinMode(BUTL, INPUT_PULLUP); pinMode(BUTR, INPUT_PULLUP); pinMode(LEDL, OUTPUT); pinMode(LEDR, OUTPUT); digitalWrite(LEDL, LOW); digitalWrite(LEDR, LOW); } void loop() { // put your main code here, to run repeatedly: if (digitalRead(BUTR)){ R = !R; } if (digitalRead(BUTL)){ L = !L; } if (digitalRead(BUTC)){ if (L == R){ L = !L; R = !R; } else { L = R = false; } } if (millis() % 1000 >= 0){ if (L){ digitalWrite(LEDL, HIGH); } if (R){ digitalWrite(LEDR, HIGH); } } if (millis() % 1000 >= 500){ if (L){ digitalWrite(LEDL, LOW); } if (R){ digitalWrite(LEDR, LOW); } } } If you press BUTR the LEDR has to blink. If you press BUTL the LEDL has to blink. If you press BUTC the LEDR and the LEDL have to blink. I don't use delay, but I think, that I have problems with asynchrony.

3rd Jul 2021, 9:14 AM
Kind_Cat
Kind_Cat - avatar
2 Respuestas
0
Thanks, Martin Taylor. I have warning, that millis() > 0 is always true. But I write millis() % 1000 == 0
3rd Jul 2021, 10:21 AM
Kind_Cat
Kind_Cat - avatar