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:a0e9db1628f1, 2020-11-16 (annotated)
- Committer:
- yeongsookim
- Date:
- Mon Nov 16 22:37:13 2020 +0000
- Revision:
- 0:a0e9db1628f1
Init commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yeongsookim | 0:a0e9db1628f1 | 1 | #include "mbed.h" |
| yeongsookim | 0:a0e9db1628f1 | 2 | #include "LaneSensor.h" |
| yeongsookim | 0:a0e9db1628f1 | 3 | |
| yeongsookim | 0:a0e9db1628f1 | 4 | //To plot with usb, set as below. |
| yeongsookim | 0:a0e9db1628f1 | 5 | Serial pc(USBTX,USBRX); // Tx, Rx Pin |
| yeongsookim | 0:a0e9db1628f1 | 6 | |
| yeongsookim | 0:a0e9db1628f1 | 7 | //Set each gpio to see the output of the hall sensor as a led |
| yeongsookim | 0:a0e9db1628f1 | 8 | LaneSensor laneSensor(p11,p12,p13,p14,p15,p16,p17); |
| yeongsookim | 0:a0e9db1628f1 | 9 | |
| yeongsookim | 0:a0e9db1628f1 | 10 | //Interrupt is generated every 1ms and count is increased by 1 |
| yeongsookim | 0:a0e9db1628f1 | 11 | unsigned int uiFlag_1ms = 0; |
| yeongsookim | 0:a0e9db1628f1 | 12 | unsigned int uiFlag_50ms = 0; |
| yeongsookim | 0:a0e9db1628f1 | 13 | |
| yeongsookim | 0:a0e9db1628f1 | 14 | void counter_1ms () |
| yeongsookim | 0:a0e9db1628f1 | 15 | { |
| yeongsookim | 0:a0e9db1628f1 | 16 | uiFlag_1ms++; |
| yeongsookim | 0:a0e9db1628f1 | 17 | uiFlag_50ms++; |
| yeongsookim | 0:a0e9db1628f1 | 18 | } |
| yeongsookim | 0:a0e9db1628f1 | 19 | |
| yeongsookim | 0:a0e9db1628f1 | 20 | int main() |
| yeongsookim | 0:a0e9db1628f1 | 21 | { |
| yeongsookim | 0:a0e9db1628f1 | 22 | wait(1); |
| yeongsookim | 0:a0e9db1628f1 | 23 | |
| yeongsookim | 0:a0e9db1628f1 | 24 | ////Set the 1ms thicker. |
| yeongsookim | 0:a0e9db1628f1 | 25 | Ticker ticker_1ms; |
| yeongsookim | 0:a0e9db1628f1 | 26 | ticker_1ms.attach(&counter_1ms, 0.001); |
| yeongsookim | 0:a0e9db1628f1 | 27 | |
| yeongsookim | 0:a0e9db1628f1 | 28 | |
| yeongsookim | 0:a0e9db1628f1 | 29 | while(1) |
| yeongsookim | 0:a0e9db1628f1 | 30 | { |
| yeongsookim | 0:a0e9db1628f1 | 31 | // Every 50 ms, |
| yeongsookim | 0:a0e9db1628f1 | 32 | if(uiFlag_50ms >= 50) { |
| yeongsookim | 0:a0e9db1628f1 | 33 | uiFlag_50ms = 0; |
| yeongsookim | 0:a0e9db1628f1 | 34 | |
| yeongsookim | 0:a0e9db1628f1 | 35 | int data = laneSensor.getData(); |
| yeongsookim | 0:a0e9db1628f1 | 36 | float error = laneSensor.getError(); |
| yeongsookim | 0:a0e9db1628f1 | 37 | pc.printf ("data: %d, error: %f \r\n", data, error); |
| yeongsookim | 0:a0e9db1628f1 | 38 | } |
| yeongsookim | 0:a0e9db1628f1 | 39 | } |
| yeongsookim | 0:a0e9db1628f1 | 40 | } |