Last active
December 20, 2015 21:59
-
-
Save ramalho/6202074 to your computer and use it in GitHub Desktop.
SemaforoPot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| SemaforoPot | |
| Controla tres leds com um potenciometro | |
| */ | |
| int led_vermelho = 11; | |
| int led_amarelo = 12; | |
| int led_verde = 13; | |
| int led_aceso = led_amarelo; | |
| void setup() { | |
| pinMode(led_vermelho, OUTPUT); | |
| pinMode(led_amarelo, OUTPUT); | |
| pinMode(led_verde, OUTPUT); | |
| } | |
| void loop() { | |
| int valor = analogRead(A0); // ler o valor do pot: 0...1023 | |
| digitalWrite(led_aceso, LOW); | |
| if (valor > 930) { | |
| led_aceso = led_vermelho; | |
| } else if (valor < 700) { | |
| led_aceso = led_verde; | |
| } else { | |
| led_aceso = led_amarelo; | |
| } | |
| digitalWrite(led_aceso, HIGH); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment