TimerLed

Dependencies:   mbed

main.cpp

Committer:
happy_alien
Date:
2019-12-16
Revision:
1:4f4f8acfae13
Parent:
0:28ab61836d38

File content as of revision 1:4f4f8acfae13:

#include "mbed.h"
#define BUTTON1 p14     // push joystick pin
//#define BUTTON1 A1    // NUCLEO Taster A1
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);  // NUCLEO D2
DigitalOut led3(LED3);  // NUCLEO D3
DigitalOut led4(LED4);
 
Ticker t1,t3;
Timeout t2;
InterruptIn btn(BUTTON1);
 
void blink_led1() {
    printf("Ticker fired\n");
    led1 = !led1;
}
void blink_led4() 
{
    led4=!led4;
    
    
    
}
void toggle_led2() {
    printf("BUTTON1 fall invoked\n");
    led2 = !led2;
}
 
void turn_led3_on() {
    printf("Timeout fired\n");
    led3 = 1;
}
 
int main() {
    printf("Hello world!\n");
    printf("LED1 will blink every second, LED3 will toggle after 2.5 seconds, LED2 can be toggled through BUTTON1.\n");
    printf("-----------------------------------\n\n");
 
    t1.attach(callback(&blink_led1), 1.0f);
    t2.attach(callback(&turn_led3_on), 2.5f);
    t3.attach(callback(&blink_led4),5.0f);
    btn.fall(callback(&toggle_led2));
 
    while(1) {}
    // wait_ms(osWaitForever);
}