Macchina con bluetooth
Dependencies: MotorMR001-004 mbed
main.cpp@0:9cefbd1e13a1, 2016-11-12 (annotated)
- Committer:
- Mattinico
- Date:
- Sat Nov 12 18:29:24 2016 +0000
- Revision:
- 0:9cefbd1e13a1
k
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mattinico | 0:9cefbd1e13a1 | 1 | #include "mbed.h" |
Mattinico | 0:9cefbd1e13a1 | 2 | #include "Motor.h" |
Mattinico | 0:9cefbd1e13a1 | 3 | Serial pc (SERIAL_TX, SERIAL_RX); |
Mattinico | 0:9cefbd1e13a1 | 4 | Motor m1(D10, D8, D9); //pwm (E1), fwd (1A), rev (1B) |
Mattinico | 0:9cefbd1e13a1 | 5 | Motor m2(D5, D6, D7); //pwm (E2), fwd (2A), rev (2B) |
Mattinico | 0:9cefbd1e13a1 | 6 | RawSerial hc05(D8, D2); |
Mattinico | 0:9cefbd1e13a1 | 7 | |
Mattinico | 0:9cefbd1e13a1 | 8 | int main() { |
Mattinico | 0:9cefbd1e13a1 | 9 | char a; |
Mattinico | 0:9cefbd1e13a1 | 10 | pc.baud(9600); // setto il baud rate della porta seriale pc |
Mattinico | 0:9cefbd1e13a1 | 11 | hc05.baud(9600); // setto il baud rate della porta rawserial hc05 |
Mattinico | 0:9cefbd1e13a1 | 12 | while(1) { |
Mattinico | 0:9cefbd1e13a1 | 13 | if(hc05.readable()) { // se e’¨ stato ricevuto un carattere |
Mattinico | 0:9cefbd1e13a1 | 14 | a=hc05.getc(); // assegna il carattere ricevuto alla var a |
Mattinico | 0:9cefbd1e13a1 | 15 | if (a=='v') { |
Mattinico | 0:9cefbd1e13a1 | 16 | m1.speed(1); |
Mattinico | 0:9cefbd1e13a1 | 17 | m2.speed(1); |
Mattinico | 0:9cefbd1e13a1 | 18 | wait(1.5); |
Mattinico | 0:9cefbd1e13a1 | 19 | } |
Mattinico | 0:9cefbd1e13a1 | 20 | else if(a=='d'){ |
Mattinico | 0:9cefbd1e13a1 | 21 | m1.speed(0.6); |
Mattinico | 0:9cefbd1e13a1 | 22 | m2.speed(-0.6); |
Mattinico | 0:9cefbd1e13a1 | 23 | wait(1); |
Mattinico | 0:9cefbd1e13a1 | 24 | } |
Mattinico | 0:9cefbd1e13a1 | 25 | else if(a=='s'){ |
Mattinico | 0:9cefbd1e13a1 | 26 | m1.speed(-0.6); |
Mattinico | 0:9cefbd1e13a1 | 27 | m2.speed(0.6); |
Mattinico | 0:9cefbd1e13a1 | 28 | wait(1); |
Mattinico | 0:9cefbd1e13a1 | 29 | } |
Mattinico | 0:9cefbd1e13a1 | 30 | /*else if(a=='p'{ |
Mattinico | 0:9cefbd1e13a1 | 31 | m1.speed(0); |
Mattinico | 0:9cefbd1e13a1 | 32 | m2.speed(0); |
Mattinico | 0:9cefbd1e13a1 | 33 | } */ |
Mattinico | 0:9cefbd1e13a1 | 34 | } |
Mattinico | 0:9cefbd1e13a1 | 35 | } |
Mattinico | 0:9cefbd1e13a1 | 36 | } |