brightness of the led controlled by two buttons
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 PwmOut led(D3); 00004 00005 InterruptIn but1(D5); 00006 InterruptIn but2(D4); 00007 00008 volatile float brightness = 0.0f; 00009 00010 void increaseBrightness() { 00011 brightness = brightness + 0.1f > 1.0f ? 1.0f : brightness + 0.1f; 00012 led.write(brightness); 00013 } 00014 00015 void decreaseBrightness() { 00016 brightness = brightness - 0.1f < 0.0f ? 0.0f : brightness - 0.1f; 00017 led.write(brightness); 00018 } 00019 00020 int main() 00021 { 00022 but1.fall(increaseBrightness); 00023 but2.fall(decreaseBrightness); 00024 while (true); 00025 }
Generated on Fri Aug 12 2022 22:25:46 by
1.7.2