![](/media/cache/profiles/26657d5ff9020d2abefe558796b99584.50x50_q85.jpg)
"wait_us" example
main.cpp@1:09163b143242, 2013-03-21 (annotated)
- Committer:
- emilmont
- Date:
- Thu Mar 21 13:00:28 2013 +0000
- Revision:
- 1:09163b143242
- Parent:
- 0:453461456608
More explicit message
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 0:453461456608 | 1 | #include "mbed.h" |
emilmont | 0:453461456608 | 2 | |
emilmont | 0:453461456608 | 3 | int main() { |
emilmont | 0:453461456608 | 4 | volatile int us = 100; |
emilmont | 0:453461456608 | 5 | volatile uint32_t start = 0xFFFFFFF0; |
emilmont | 0:453461456608 | 6 | volatile uint32_t us_ticker = 100; |
emilmont | 0:453461456608 | 7 | |
emilmont | 0:453461456608 | 8 | // void wait_us(int us) { |
emilmont | 0:453461456608 | 9 | // uint32_t start = us_ticker_read(); |
emilmont | 0:453461456608 | 10 | // while ((us_ticker_read() - start) < us); |
emilmont | 0:453461456608 | 11 | // } |
emilmont | 0:453461456608 | 12 | if ((us_ticker - start) < us) { |
emilmont | 0:453461456608 | 13 | printf("while(True): Failed to detect that the interval is expired, still in the loop \n"); |
emilmont | 0:453461456608 | 14 | } else { |
emilmont | 0:453461456608 | 15 | printf("while(False): Got out of the wait loop\n"); |
emilmont | 0:453461456608 | 16 | } |
emilmont | 1:09163b143242 | 17 | printf("%d\n", (us_ticker - start)); |
emilmont | 0:453461456608 | 18 | |
emilmont | 0:453461456608 | 19 | DigitalOut led(LED1); |
emilmont | 0:453461456608 | 20 | while (1) { |
emilmont | 0:453461456608 | 21 | led = !led; |
emilmont | 0:453461456608 | 22 | wait(0.5); |
emilmont | 0:453461456608 | 23 | } |
emilmont | 0:453461456608 | 24 | } |