Created
July 21, 2014 16:07
-
-
Save esdrasdutra/f93b5c122d2d0eed6665 to your computer and use it in GitHub Desktop.
código para testes do sensor óptico reflexivo
This file contains 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
/* Criado por Ronilson Santos em 06/07/2014 | |
* Testes realizados com sucesso. | |
*/ | |
int ledPin = 13; // Led interno do Arduino (da porta 13) | |
int sigPin = 10; // Pino do Sensor | |
int valor = 0; // Variável para guardar guardar o valor retornado | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(ledPin, OUTPUT); // Led do arduino como saida | |
pinMode(sigPin, INPUT); // Pino do sinal do sensor setado como entrada | |
} | |
void loop(){ | |
valor = digitalRead(sigPin); // Ler o sensor | |
if (valor == HIGH) { // Se o sensor detectar superfície escura (a linha), o led ACENDE | |
digitalWrite(ledPin, HIGH); // Acender o led | |
Serial.println("Preto"); // Retorna a palavra "Preto" | |
} | |
else { // Senão, superficie branca | |
digitalWrite(ledPin, LOW); // Se o sensor NÃO detectar superfície escura (a linha), o led APAGA | |
Serial.println("Branco"); // Retorna a palavra "Branco" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment