![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test of Ticker interface
Ticker interface: https://developer.mbed.org/handbook/Ticker
main.cpp@0:be44cd8797f6, 2015-05-05 (annotated)
- Committer:
- 66keg
- Date:
- Tue May 05 10:42:22 2015 +0000
- Revision:
- 0:be44cd8797f6
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
66keg | 0:be44cd8797f6 | 1 | #include "mbed.h" |
66keg | 0:be44cd8797f6 | 2 | |
66keg | 0:be44cd8797f6 | 3 | Serial pc(USBTX, USBRX); |
66keg | 0:be44cd8797f6 | 4 | Ticker ticker1, ticker2; |
66keg | 0:be44cd8797f6 | 5 | |
66keg | 0:be44cd8797f6 | 6 | void myFunc1() |
66keg | 0:be44cd8797f6 | 7 | { |
66keg | 0:be44cd8797f6 | 8 | pc.printf("ticker1\n"); |
66keg | 0:be44cd8797f6 | 9 | } |
66keg | 0:be44cd8797f6 | 10 | |
66keg | 0:be44cd8797f6 | 11 | void myFunc2() |
66keg | 0:be44cd8797f6 | 12 | { |
66keg | 0:be44cd8797f6 | 13 | pc.printf("ticker2\n"); |
66keg | 0:be44cd8797f6 | 14 | } |
66keg | 0:be44cd8797f6 | 15 | |
66keg | 0:be44cd8797f6 | 16 | int main() { |
66keg | 0:be44cd8797f6 | 17 | ticker1.attach(&myFunc1, 1.0); // call myFunc1 every 1.0 seconds |
66keg | 0:be44cd8797f6 | 18 | ticker2.attach(&myFunc2, 2.0); // call myFunc2 every 2.0 seconds |
66keg | 0:be44cd8797f6 | 19 | |
66keg | 0:be44cd8797f6 | 20 | // main loop |
66keg | 0:be44cd8797f6 | 21 | while(1) { |
66keg | 0:be44cd8797f6 | 22 | pc.printf("main loop\n"); |
66keg | 0:be44cd8797f6 | 23 | wait(5.0); |
66keg | 0:be44cd8797f6 | 24 | } |
66keg | 0:be44cd8797f6 | 25 | } |