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:3ead6014ad51, 2019-11-03 (annotated)
- Committer:
- yeongsookim
- Date:
- Sun Nov 03 23:28:27 2019 +0000
- Revision:
- 0:3ead6014ad51
- Child:
- 1:d43df9a7cef2
plot unable
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yeongsookim | 0:3ead6014ad51 | 1 | #include "mbed.h" |
| yeongsookim | 0:3ead6014ad51 | 2 | #include "Motor.h" |
| yeongsookim | 0:3ead6014ad51 | 3 | #include "Plotting.h" |
| yeongsookim | 0:3ead6014ad51 | 4 | #include "HallSensor.h" |
| yeongsookim | 0:3ead6014ad51 | 5 | |
| yeongsookim | 0:3ead6014ad51 | 6 | |
| yeongsookim | 0:3ead6014ad51 | 7 | //To plot with usb, set as below. |
| yeongsookim | 0:3ead6014ad51 | 8 | Serial pc(USBTX,USBRX); // Tx, Rx Pin |
| yeongsookim | 0:3ead6014ad51 | 9 | Plotting plot; |
| yeongsookim | 0:3ead6014ad51 | 10 | |
| yeongsookim | 0:3ead6014ad51 | 11 | //Set each gpio to see the output of the hall sensor as a led |
| yeongsookim | 0:3ead6014ad51 | 12 | DigitalOut myled1(LED1); |
| yeongsookim | 0:3ead6014ad51 | 13 | |
| yeongsookim | 0:3ead6014ad51 | 14 | HallSensor hall (p29); |
| yeongsookim | 0:3ead6014ad51 | 15 | Motor motor (p23, p24, p25, p26); |
| yeongsookim | 0:3ead6014ad51 | 16 | |
| yeongsookim | 0:3ead6014ad51 | 17 | //Interrupt is generated every 1ms and count is increased by 1 |
| yeongsookim | 0:3ead6014ad51 | 18 | unsigned int uiFlag_1ms = 0; |
| yeongsookim | 0:3ead6014ad51 | 19 | unsigned int uiFlag_50ms = 0; |
| yeongsookim | 0:3ead6014ad51 | 20 | |
| yeongsookim | 0:3ead6014ad51 | 21 | void counter_1ms () |
| yeongsookim | 0:3ead6014ad51 | 22 | { |
| yeongsookim | 0:3ead6014ad51 | 23 | uiFlag_1ms++; |
| yeongsookim | 0:3ead6014ad51 | 24 | uiFlag_50ms++; |
| yeongsookim | 0:3ead6014ad51 | 25 | } |
| yeongsookim | 0:3ead6014ad51 | 26 | |
| yeongsookim | 0:3ead6014ad51 | 27 | int main() |
| yeongsookim | 0:3ead6014ad51 | 28 | { |
| yeongsookim | 0:3ead6014ad51 | 29 | wait(1); |
| yeongsookim | 0:3ead6014ad51 | 30 | |
| yeongsookim | 0:3ead6014ad51 | 31 | //Set the 1ms thicker. |
| yeongsookim | 0:3ead6014ad51 | 32 | Ticker ticker_1ms; |
| yeongsookim | 0:3ead6014ad51 | 33 | ticker_1ms.attach (&counter_1ms, 0.001); |
| yeongsookim | 0:3ead6014ad51 | 34 | |
| yeongsookim | 0:3ead6014ad51 | 35 | while(1) { |
| yeongsookim | 0:3ead6014ad51 | 36 | // Every 1 ms, |
| yeongsookim | 0:3ead6014ad51 | 37 | if(uiFlag_1ms >= 1) { |
| yeongsookim | 0:3ead6014ad51 | 38 | uiFlag_1ms = 0; |
| yeongsookim | 0:3ead6014ad51 | 39 | |
| yeongsookim | 0:3ead6014ad51 | 40 | //Set the motor to 10%. |
| yeongsookim | 0:3ead6014ad51 | 41 | motor.setSpeed_percent(10.0, FORWARD); |
| yeongsookim | 0:3ead6014ad51 | 42 | |
| yeongsookim | 0:3ead6014ad51 | 43 | //If A is 0, turn on the LED. |
| yeongsookim | 0:3ead6014ad51 | 44 | myled1 = hall.getPinState(); |
| yeongsookim | 0:3ead6014ad51 | 45 | } |
| yeongsookim | 0:3ead6014ad51 | 46 | |
| yeongsookim | 0:3ead6014ad51 | 47 | // Every 50 ms, |
| yeongsookim | 0:3ead6014ad51 | 48 | if(uiFlag_50ms >= 50) { |
| yeongsookim | 0:3ead6014ad51 | 49 | uiFlag_50ms = 0; |
| yeongsookim | 0:3ead6014ad51 | 50 | |
| yeongsookim | 0:3ead6014ad51 | 51 | // clear plotting buffer |
| yeongsookim | 0:3ead6014ad51 | 52 | plot.reset (); |
| yeongsookim | 0:3ead6014ad51 | 53 | |
| yeongsookim | 0:3ead6014ad51 | 54 | // put data to buffer |
| yeongsookim | 0:3ead6014ad51 | 55 | plot.put (hall.getSpeed_rps(), 0); |
| yeongsookim | 0:3ead6014ad51 | 56 | |
| yeongsookim | 0:3ead6014ad51 | 57 | // send buffer |
| yeongsookim | 0:3ead6014ad51 | 58 | plot.send (&pc); |
| yeongsookim | 0:3ead6014ad51 | 59 | } |
| yeongsookim | 0:3ead6014ad51 | 60 | } |
| yeongsookim | 0:3ead6014ad51 | 61 | } |