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.
main.cpp@0:8c408630d916, 2022-04-21 (annotated)
- Committer:
- oslejste
- Date:
- Thu Apr 21 18:58:08 2022 +0000
- Revision:
- 0:8c408630d916
Init commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| oslejste | 0:8c408630d916 | 1 | #include "mbed.h" |
| oslejste | 0:8c408630d916 | 2 | |
| oslejste | 0:8c408630d916 | 3 | Serial pc(PA_2, PA_3); |
| oslejste | 0:8c408630d916 | 4 | BusOut motorCoils(PB_1, PA_7, PA_6, PA_5); |
| oslejste | 0:8c408630d916 | 5 | |
| oslejste | 0:8c408630d916 | 6 | void delayV(uint8_t count){ |
| oslejste | 0:8c408630d916 | 7 | for(unsigned char i=0; i<count; i++){ |
| oslejste | 0:8c408630d916 | 8 | wait(0.005); |
| oslejste | 0:8c408630d916 | 9 | } |
| oslejste | 0:8c408630d916 | 10 | } |
| oslejste | 0:8c408630d916 | 11 | void step_left(int pause){ |
| oslejste | 0:8c408630d916 | 12 | motorCoils = 0x09; |
| oslejste | 0:8c408630d916 | 13 | delayV(pause); |
| oslejste | 0:8c408630d916 | 14 | motorCoils = 0x08; |
| oslejste | 0:8c408630d916 | 15 | delayV(pause); |
| oslejste | 0:8c408630d916 | 16 | motorCoils = 0x0C; |
| oslejste | 0:8c408630d916 | 17 | delayV(pause); |
| oslejste | 0:8c408630d916 | 18 | motorCoils = 0x04; |
| oslejste | 0:8c408630d916 | 19 | delayV(pause); |
| oslejste | 0:8c408630d916 | 20 | motorCoils = 0x06; |
| oslejste | 0:8c408630d916 | 21 | delayV(pause); |
| oslejste | 0:8c408630d916 | 22 | motorCoils = 0x02; |
| oslejste | 0:8c408630d916 | 23 | delayV(pause); |
| oslejste | 0:8c408630d916 | 24 | motorCoils = 0x03; |
| oslejste | 0:8c408630d916 | 25 | delayV(pause); |
| oslejste | 0:8c408630d916 | 26 | motorCoils = 0x01; |
| oslejste | 0:8c408630d916 | 27 | delayV(pause); |
| oslejste | 0:8c408630d916 | 28 | } |
| oslejste | 0:8c408630d916 | 29 | |
| oslejste | 0:8c408630d916 | 30 | void step_right(int pause){ |
| oslejste | 0:8c408630d916 | 31 | motorCoils = 0x01; //0001 |
| oslejste | 0:8c408630d916 | 32 | delayV(pause); |
| oslejste | 0:8c408630d916 | 33 | motorCoils = 0x03; //0011 |
| oslejste | 0:8c408630d916 | 34 | delayV(pause); |
| oslejste | 0:8c408630d916 | 35 | motorCoils = 0x02; //0010 |
| oslejste | 0:8c408630d916 | 36 | delayV(pause); |
| oslejste | 0:8c408630d916 | 37 | motorCoils = 0x06; //0110 |
| oslejste | 0:8c408630d916 | 38 | delayV(pause); |
| oslejste | 0:8c408630d916 | 39 | motorCoils = 0x04; //0100 |
| oslejste | 0:8c408630d916 | 40 | delayV(pause); |
| oslejste | 0:8c408630d916 | 41 | motorCoils = 0x0C; //1100 |
| oslejste | 0:8c408630d916 | 42 | delayV(pause); |
| oslejste | 0:8c408630d916 | 43 | motorCoils = 0x08; //1000 |
| oslejste | 0:8c408630d916 | 44 | delayV(pause); |
| oslejste | 0:8c408630d916 | 45 | motorCoils = 0x09; //1001 |
| oslejste | 0:8c408630d916 | 46 | delayV(pause); |
| oslejste | 0:8c408630d916 | 47 | } |
| oslejste | 0:8c408630d916 | 48 | |
| oslejste | 0:8c408630d916 | 49 | uint8_t pause = 15; |
| oslejste | 0:8c408630d916 | 50 | int main(){ |
| oslejste | 0:8c408630d916 | 51 | while(1) { |
| oslejste | 0:8c408630d916 | 52 | if(pc.readable()){ |
| oslejste | 0:8c408630d916 | 53 | char cmd = pc.getc(); |
| oslejste | 0:8c408630d916 | 54 | switch(cmd){ |
| oslejste | 0:8c408630d916 | 55 | case 's': |
| oslejste | 0:8c408630d916 | 56 | step_right(pause); |
| oslejste | 0:8c408630d916 | 57 | pc.printf("Stepped right\n"); |
| oslejste | 0:8c408630d916 | 58 | break; |
| oslejste | 0:8c408630d916 | 59 | |
| oslejste | 0:8c408630d916 | 60 | case 'r': |
| oslejste | 0:8c408630d916 | 61 | step_right(pause); |
| oslejste | 0:8c408630d916 | 62 | pc.printf("Rotating right\n"); |
| oslejste | 0:8c408630d916 | 63 | break; |
| oslejste | 0:8c408630d916 | 64 | |
| oslejste | 0:8c408630d916 | 65 | case 'l': |
| oslejste | 0:8c408630d916 | 66 | step_left(pause); |
| oslejste | 0:8c408630d916 | 67 | pc.printf("Rotating left\n"); |
| oslejste | 0:8c408630d916 | 68 | break; |
| oslejste | 0:8c408630d916 | 69 | } |
| oslejste | 0:8c408630d916 | 70 | } |
| oslejste | 0:8c408630d916 | 71 | |
| oslejste | 0:8c408630d916 | 72 | } |
| oslejste | 0:8c408630d916 | 73 | } |