Dependencies: MSCUsbHost mbed Servo SRF08
main.cpp@0:311e864f84b4, 2010-10-06 (annotated)
- Committer:
- dcmk1mr2
- Date:
- Wed Oct 06 01:47:13 2010 +0000
- Revision:
- 0:311e864f84b4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dcmk1mr2 | 0:311e864f84b4 | 1 | #include "mbed.h" |
dcmk1mr2 | 0:311e864f84b4 | 2 | #include "SRF08.h" |
dcmk1mr2 | 0:311e864f84b4 | 3 | #include "Servo.h" |
dcmk1mr2 | 0:311e864f84b4 | 4 | #include "ID12RFID.h" |
dcmk1mr2 | 0:311e864f84b4 | 5 | |
dcmk1mr2 | 0:311e864f84b4 | 6 | DigitalOut led1(LED1); |
dcmk1mr2 | 0:311e864f84b4 | 7 | DigitalOut led2(LED2); |
dcmk1mr2 | 0:311e864f84b4 | 8 | PwmOut led3(LED3); |
dcmk1mr2 | 0:311e864f84b4 | 9 | |
dcmk1mr2 | 0:311e864f84b4 | 10 | SRF08 srf08(p28, p27, 0xE0); // Define SDA, SCL pin and I2C address |
dcmk1mr2 | 0:311e864f84b4 | 11 | PwmOut meter (p22); |
dcmk1mr2 | 0:311e864f84b4 | 12 | Servo servo (p21); |
dcmk1mr2 | 0:311e864f84b4 | 13 | AnalogIn pot (p18); |
dcmk1mr2 | 0:311e864f84b4 | 14 | ID12RFID rfid (p10); |
dcmk1mr2 | 0:311e864f84b4 | 15 | AnalogIn th (p19); |
dcmk1mr2 | 0:311e864f84b4 | 16 | LocalFileSystem fs ("fs"); |
dcmk1mr2 | 0:311e864f84b4 | 17 | |
dcmk1mr2 | 0:311e864f84b4 | 18 | int main() { |
dcmk1mr2 | 0:311e864f84b4 | 19 | |
dcmk1mr2 | 0:311e864f84b4 | 20 | FILE *fp = fopen("/fs/hello.txt","w"); |
dcmk1mr2 | 0:311e864f84b4 | 21 | fprintf(fp,"Hello World!\n"); |
dcmk1mr2 | 0:311e864f84b4 | 22 | fclose(fp); |
dcmk1mr2 | 0:311e864f84b4 | 23 | |
dcmk1mr2 | 0:311e864f84b4 | 24 | while (1) { |
dcmk1mr2 | 0:311e864f84b4 | 25 | |
dcmk1mr2 | 0:311e864f84b4 | 26 | // Check to see if an RFID tag has been presented, if so, display it |
dcmk1mr2 | 0:311e864f84b4 | 27 | if (rfid.readable()) { |
dcmk1mr2 | 0:311e864f84b4 | 28 | printf("ID Tag : %d\n",rfid.read()); |
dcmk1mr2 | 0:311e864f84b4 | 29 | led1 = !led1; |
dcmk1mr2 | 0:311e864f84b4 | 30 | } |
dcmk1mr2 | 0:311e864f84b4 | 31 | |
dcmk1mr2 | 0:311e864f84b4 | 32 | // If the middle pot is more than half way |
dcmk1mr2 | 0:311e864f84b4 | 33 | // read and display from the Ultrasonic range finder |
dcmk1mr2 | 0:311e864f84b4 | 34 | if (th.read() > 0.5) { |
dcmk1mr2 | 0:311e864f84b4 | 35 | float measure = srf08.read(); |
dcmk1mr2 | 0:311e864f84b4 | 36 | printf("Measured range : %.2f cm\n",measure); |
dcmk1mr2 | 0:311e864f84b4 | 37 | meter = 1.0 - (measure/44.0); |
dcmk1mr2 | 0:311e864f84b4 | 38 | led2 = !led2; |
dcmk1mr2 | 0:311e864f84b4 | 39 | } |
dcmk1mr2 | 0:311e864f84b4 | 40 | |
dcmk1mr2 | 0:311e864f84b4 | 41 | // Move the servo to reflect the pot |
dcmk1mr2 | 0:311e864f84b4 | 42 | servo = pot.read(); |
dcmk1mr2 | 0:311e864f84b4 | 43 | led3.write(pot.read()); |
dcmk1mr2 | 0:311e864f84b4 | 44 | wait(0.1); |
dcmk1mr2 | 0:311e864f84b4 | 45 | } |
dcmk1mr2 | 0:311e864f84b4 | 46 | } |