mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 #include "mbed.h"
elessair 0:f269e3021894 2 #include "test_env.h"
elessair 0:f269e3021894 3
elessair 0:f269e3021894 4 void print_char(char c = '*')
elessair 0:f269e3021894 5 {
elessair 0:f269e3021894 6 printf("%c", c);
elessair 0:f269e3021894 7 fflush(stdout);
elessair 0:f269e3021894 8 }
elessair 0:f269e3021894 9
elessair 0:f269e3021894 10 Ticker flipper_1;
elessair 0:f269e3021894 11 DigitalOut led1(LED1);
elessair 0:f269e3021894 12
elessair 0:f269e3021894 13 void flip_1() {
elessair 0:f269e3021894 14 static int led1_state = 0;
elessair 0:f269e3021894 15 if (led1_state) {
elessair 0:f269e3021894 16 led1 = 0; led1_state = 0;
elessair 0:f269e3021894 17 } else {
elessair 0:f269e3021894 18 led1 = 1; led1_state = 1;
elessair 0:f269e3021894 19 }
elessair 0:f269e3021894 20 print_char();
elessair 0:f269e3021894 21 }
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 Ticker flipper_2;
elessair 0:f269e3021894 24 DigitalOut led2(LED2);
elessair 0:f269e3021894 25
elessair 0:f269e3021894 26 void flip_2() {
elessair 0:f269e3021894 27 static int led2_state = 0;
elessair 0:f269e3021894 28 if (led2_state) {
elessair 0:f269e3021894 29 led2 = 0; led2_state = 0;
elessair 0:f269e3021894 30 } else {
elessair 0:f269e3021894 31 led2 = 1; led2_state = 1;
elessair 0:f269e3021894 32 }
elessair 0:f269e3021894 33 }
elessair 0:f269e3021894 34
elessair 0:f269e3021894 35 int main() {
elessair 0:f269e3021894 36 MBED_HOSTTEST_TIMEOUT(15);
elessair 0:f269e3021894 37 MBED_HOSTTEST_SELECT(wait_us_auto);
elessair 0:f269e3021894 38 MBED_HOSTTEST_DESCRIPTION(Ticker Int);
elessair 0:f269e3021894 39 MBED_HOSTTEST_START("MBED_11");
elessair 0:f269e3021894 40
elessair 0:f269e3021894 41 led1 = 0;
elessair 0:f269e3021894 42 led2 = 0;
elessair 0:f269e3021894 43 flipper_1.attach(&flip_1, 1.0); // the address of the function to be attached (flip) and the interval (1 second)
elessair 0:f269e3021894 44 flipper_2.attach(&flip_2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
elessair 0:f269e3021894 45
elessair 0:f269e3021894 46 while (true) {
elessair 0:f269e3021894 47 wait(1.0);
elessair 0:f269e3021894 48 }
elessair 0:f269e3021894 49 }