Modify the BlinkTicker example to use LED1, LED2, and LED3 for showing the three least significant bits of an 8 bit counter
main.cpp
00001 #include "mbed.h" 00002 00003 Ticker toggle_led_ticker; 00004 00005 DigitalOut led1(LED1); 00006 DigitalOut led2(LED2); 00007 DigitalOut led3(LED3); 00008 00009 int8_t counter = 0; 00010 00011 void toggle_leds_by_least_significant_bytes() { 00012 00013 if(counter & (1 << (0))){ 00014 led1 = 1; 00015 } else { 00016 led1 = 0; 00017 } 00018 00019 if(counter & (1 << (1))){ 00020 led2 = 1; 00021 } else { 00022 led2 = 0; 00023 } 00024 00025 if(counter & (1 << (2))){ 00026 led3 = 1; 00027 } else { 00028 led3 = 0; 00029 } 00030 00031 counter++; 00032 } 00033 00034 int main() { 00035 toggle_led_ticker.attach(&toggle_leds_by_least_significant_bytes, 1); 00036 }
Generated on Wed Sep 14 2022 11:54:23 by
1.7.2