BlinkTicker123

Dependencies:   mbed

main.cpp

Committer:
redona
Date:
2018-11-15
Revision:
1:253ac8e04eba
Parent:
0:d9ec23dd131e

File content as of revision 1:253ac8e04eba:

#include "mbed.h"

Ticker toggle_led_ticker;

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);

int counter = 0; 

void toggle_led() {
    // We give the bits value of 1 and shifting the bits to the left based on the right number.
     (counter & (1 << (0))) ? led1 =1 : led1 = 0;
     
     (counter & (1 << (1))) ?  led2 = 1 : led2 = 0;
   
     counter & (1 << (2)) ? led3 = 1 : led3 = 0;

}

int main() {
    // Init the ticker with the address of the function (toggle_led) to be attached and the interval (2000 ms)
    toggle_led_ticker.attach(&toggle_led, 2);
    while (true) {
    // increment the counter
        wait(2);
        counter ++;
    }
}