Kazuhiro Ouchi
/
m3pi_ledpsd
A program that connects a distance sensor to the m3pi and avoids obstacles.
main.cpp
- Committer:
- kanpapa
- Date:
- 2011-11-23
- Revision:
- 1:97befd99f2b7
- Parent:
- 0:1c32a3ae67e1
File content as of revision 1:97befd99f2b7:
#include "mbed.h" #include "m3pi.h" m3pi m3pi; AnalogIn ain(p20); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); int main() { m3pi.locate(0,1); m3pi.printf("LO World"); wait(2.0); for (int i = 0; i < 30; i++) { m3pi.forward(0.1); wait(0.5); // led1 = (ain > 0.2) ? 1 : 0; led2 = (ain > 0.4) ? 1 : 0; led3 = (ain > 0.6) ? 1 : 0; led4 = (ain > 0.8) ? 1 : 0; if (ain > 0.8) { m3pi.backward(0.1); wait(0.5); m3pi.left(0.1); wait(0.5); } } m3pi.stop(); }