veja o primeiro vídeo - como piscar led sem delay:
http://youtu.be/R3mn7Vw9g2Y
Inscreva-se no meu canal do youtube para mais vídeos como esse!
Código:
const int PINO_LED_1 = 3; const int PINO_LED_2 = 5; const int PINO_LED_3 = 6; const int PINO_LED_4 = 9; void setup() { pinMode(PINO_LED_1, OUTPUT); pinMode(PINO_LED_2, OUTPUT); pinMode(PINO_LED_3, OUTPUT); pinMode(PINO_LED_4, OUTPUT); } void loop() { piscaLedFade(PINO_LED_1, 2000, 1500, 000, 1000, 1000); piscaLedFade(PINO_LED_2, 2000, 1500, 200, 1000, 1000); piscaLedFade(PINO_LED_3, 4000, 1500, 400, 1000, 1000); piscaLedFade(PINO_LED_4, 4000, 1500, 600, 1000, 1000); } void piscaLedFade(int pin, int timeOn, int timeOff, int atraso, int timeFadeOn, int timeFadeOff){ long resto = (millis()-atraso) % (timeOn + timeOff); long fade = (resto < timeOn ? 255 : 0); if (fade > 0){ if ( timeFadeOn > resto ) { fade = resto * 255 / timeFadeOn; } if ( (timeOn-timeFadeOff) < resto ) { fade = (timeOn-resto) * 255 / timeFadeOff; } } analogWrite(pin, fade); }
Nenhum comentário:
Postar um comentário