esempio IR
Dependencies: mbed
main.cpp@3:5844462d5785, 2017-02-19 (annotated)
- Committer:
- vidica94
- Date:
- Sun Feb 19 18:27:13 2017 +0000
- Revision:
- 3:5844462d5785
- Parent:
- 2:d288340a708d
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vidica94 | 0:1a9d324dc172 | 1 | #include "mbed.h" |
vidica94 | 0:1a9d324dc172 | 2 | |
vidica94 | 0:1a9d324dc172 | 3 | /* |
vidica94 | 0:1a9d324dc172 | 4 | This basic example just shows how to read the output value of a infrared sensor. In this case we used the sensor avaiable on amazon link |
vidica94 | 2:d288340a708d | 5 | we read the output value as a digital signal , so we can use the InterruptIn to better control the bot. |
vidica94 | 3:5844462d5785 | 6 | WARNING: to catch the target at the right distance it's necessary to calibrate the ir sensor, using the little potentiometer on the pcb whith the sensors. |
vidica94 | 0:1a9d324dc172 | 7 | To calibrate the sensors run the other program |
vidica94 | 0:1a9d324dc172 | 8 | */ |
vidica94 | 0:1a9d324dc172 | 9 | |
vidica94 | 0:1a9d324dc172 | 10 | DigitalIn ir(D4);// definition of the pin D4 as digital input |
vidica94 | 0:1a9d324dc172 | 11 | |
vidica94 | 0:1a9d324dc172 | 12 | |
vidica94 | 0:1a9d324dc172 | 13 | DigitalOut led(LED1);//definition of the green led on the board as digital output |
vidica94 | 0:1a9d324dc172 | 14 | |
vidica94 | 0:1a9d324dc172 | 15 | int main() |
vidica94 | 0:1a9d324dc172 | 16 | { |
vidica94 | 0:1a9d324dc172 | 17 | |
vidica94 | 0:1a9d324dc172 | 18 | while(1) { |
vidica94 | 0:1a9d324dc172 | 19 | |
vidica94 | 0:1a9d324dc172 | 20 | |
vidica94 | 0:1a9d324dc172 | 21 | printf("lettura = %d\n",ir.read() ); |
vidica94 | 0:1a9d324dc172 | 22 | |
vidica94 | 0:1a9d324dc172 | 23 | if(ir.read()==1) |
vidica94 | 0:1a9d324dc172 | 24 | led = 1; |
vidica94 | 0:1a9d324dc172 | 25 | else |
vidica94 | 0:1a9d324dc172 | 26 | led=0; |
vidica94 | 0:1a9d324dc172 | 27 | wait(1.0); |
vidica94 | 0:1a9d324dc172 | 28 | } |
vidica94 | 0:1a9d324dc172 | 29 | } |