Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // define pinos. Usei os pinos 4 e 5
- #define irLedPin 4 // Ir Led neste pino
- #define irSensorPin 5 // Sensor IR neste pino
- int irRead(int readPin, int triggerPin); // protótipo de função
- void setup()
- {
- pinMode(irSensorPin, INPUT);
- pinMode(irLedPin, OUTPUT);
- Serial.begin(9600);
- // imprime o título com intervalo de linha final
- Serial.println("Program Starting");
- // aguarde que a string longa seja enviada
- delay(100);
- }
- void loop()
- {
- Serial.println(irRead(irSensorPin, irLedPin)); // exibe os resultados
- delay(10); //wait for the string to be sent
- }
- /******************************************************************************
- * Esta função pode ser usada com um sensor panasonic pna4602m ir
- * Retorna um zero se algo for detectado pelo sensor, e um 1 caso contrário
- * A função bit bangs uma forma de onda de 38.5khZ para um led IR conectado ao
- * TriggerPin durante 1 milissegundo e, em seguida, lê o pino do sensor IR para ver se
- * O IR refletido foi detectado
- ******************************************************************************/
- int irRead(int readPin, int triggerPin)
- {
- int halfPeriod = 13; // um período de 38.5khZ é de aproximadamente 26 microssegundos
- int cycles = 38; // 26 microseconds * 38 é mais ou menos 1 milissegundo
- int i;
- for (i=0; i <=cycles; i++)
- {
- digitalWrite(triggerPin, HIGH);
- delayMicroseconds(halfPeriod);
- digitalWrite(triggerPin, LOW);
- delayMicroseconds(halfPeriod - 1); // - 1 para compensar DigitaWrite sobrecarga
- }
- return digitalRead(readPin);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement