Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@8:5ed6685f6edd, 2019-03-31 (annotated)
- Committer:
- mazdo25
- Date:
- Sun Mar 31 20:31:30 2019 +0000
- Revision:
- 8:5ed6685f6edd
- Parent:
- 7:cb07cdb35b6c
- Child:
- 9:cefa177c1353
version used in test demo 3
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mazdo25 | 1:813f4b17ae65 | 1 | #define PI 3.141 |
| mazdo25 | 1:813f4b17ae65 | 2 | |
| mazdo25 | 1:813f4b17ae65 | 3 | #include "math.h" |
| mazdo25 | 0:f45212966fb1 | 4 | #include "mbed.h" |
| mazdo25 | 0:f45212966fb1 | 5 | #include "Encoder.h" |
| mazdo25 | 3:01b5e80d842d | 6 | #include "lineSensor.h" |
| mazdo25 | 5:f1613df66ceb | 7 | #include "PID2.h" |
| mazdo25 | 4:208f5279143a | 8 | #include "PID.h" |
| mazdo25 | 5:f1613df66ceb | 9 | #include "Wheel.h" |
| mazdo25 | 1:813f4b17ae65 | 10 | #include "Robot.h" |
| mazdo25 | 1:813f4b17ae65 | 11 | |
| mazdo25 | 0:f45212966fb1 | 12 | |
| mazdo25 | 0:f45212966fb1 | 13 | //blue D8 |
| mazdo25 | 0:f45212966fb1 | 14 | //Green D9 |
| mazdo25 | 0:f45212966fb1 | 15 | //Red D5 |
| mazdo25 | 3:01b5e80d842d | 16 | int main() { |
| mazdo25 | 7:cb07cdb35b6c | 17 | Serial hm10(PA_11, PA_12); |
| mazdo25 | 7:cb07cdb35b6c | 18 | hm10.baud(9600); |
| mazdo25 | 8:5ed6685f6edd | 19 | char prevC; |
| mazdo25 | 8:5ed6685f6edd | 20 | |
| mazdo25 | 8:5ed6685f6edd | 21 | DigitalIn mybutton(USER_BUTTON); |
| mazdo25 | 1:813f4b17ae65 | 22 | |
| mazdo25 | 3:01b5e80d842d | 23 | DigitalOut enable(PA_13); |
| mazdo25 | 3:01b5e80d842d | 24 | enable.write(1); |
| mazdo25 | 3:01b5e80d842d | 25 | |
| mazdo25 | 1:813f4b17ae65 | 26 | Encoder* RE = new Encoder(PB_3,PB_5); |
| mazdo25 | 3:01b5e80d842d | 27 | Encoder* LE = new Encoder(PB_10,PB_4); |
| mazdo25 | 5:f1613df66ceb | 28 | Wheel* leftWheel = new Wheel(LE,PC_8,PA_9, PA_14); |
| mazdo25 | 5:f1613df66ceb | 29 | Wheel* rightWheel = new Wheel(RE,PC_6,PA_8, PA_7); |
| mazdo25 | 0:f45212966fb1 | 30 | |
| mazdo25 | 4:208f5279143a | 31 | //an array of lineSensor pointers params: lineSensor(PinName emitter Pin, PinName reciever Pin, make sure it is from LEFT TO RIGHT |
| mazdo25 | 4:208f5279143a | 32 | lineSensor* sensorArray[6] = {new lineSensor(PB_9,A0),new lineSensor(PC_11,A1),new lineSensor(PD_2,A2),new lineSensor(PC_10,A3),new lineSensor(PB_8,A4),new lineSensor(PC_12,A5)}; |
| mazdo25 | 8:5ed6685f6edd | 33 | |
| mazdo25 | 8:5ed6685f6edd | 34 | Robot rbt(leftWheel, rightWheel, sensorArray); |
| mazdo25 | 8:5ed6685f6edd | 35 | |
| mazdo25 | 6:477382219bcf | 36 | leftWheel->init2(); |
| mazdo25 | 0:f45212966fb1 | 37 | |
| mazdo25 | 6:477382219bcf | 38 | rightWheel->init2(); |
| mazdo25 | 5:f1613df66ceb | 39 | |
| mazdo25 | 6:477382219bcf | 40 | rbt.rbtInit(); |
| mazdo25 | 8:5ed6685f6edd | 41 | prevC = 'C'; |
| mazdo25 | 8:5ed6685f6edd | 42 | |
| mazdo25 | 3:01b5e80d842d | 43 | while(1) |
| mazdo25 | 3:01b5e80d842d | 44 | { |
| mazdo25 | 7:cb07cdb35b6c | 45 | if(hm10.readable()) |
| mazdo25 | 7:cb07cdb35b6c | 46 | { |
| mazdo25 | 7:cb07cdb35b6c | 47 | rbt.setState(hm10.getc()); |
| mazdo25 | 7:cb07cdb35b6c | 48 | } |
| mazdo25 | 3:01b5e80d842d | 49 | } |
| mazdo25 | 3:01b5e80d842d | 50 | } |
| mazdo25 | 6:477382219bcf | 51 | |
| mazdo25 | 6:477382219bcf | 52 | /* |
| mazdo25 | 7:cb07cdb35b6c | 53 | |
| mazdo25 | 6:477382219bcf | 54 | */ |