Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
00001 #include "mbed.h" 00002 #include "PinDetect.h" 00003 00004 PwmOut red_led(p23); 00005 PwmOut green_led(p22); 00006 PwmOut blue_led(p21); 00007 PinDetect pbdim(p6); 00008 PinDetect pbbright(p7); 00009 float volatile red_brightness = 0.5f; 00010 float volatile blue_brightness = 0.5f; 00011 float volatile green_brightness = 0.5f; 00012 DigitalIn red_switch(p8); 00013 DigitalIn blue_switch(p9); 00014 DigitalIn green_switch(p10); 00015 void pbdim_hit_callback (void) { 00016 if (red_switch && (1.0f > red_brightness || red_brightness >= 0.0f)) { 00017 red_brightness += 0.1f; 00018 } 00019 if (blue_switch && (1.0f > blue_brightness || blue_brightness >= 0.0f)) { 00020 blue_brightness += 0.1f; 00021 } 00022 if (green_switch && (1.0f > green_brightness || green_brightness >= 0.0f)) { 00023 green_brightness += 0.1f; 00024 } 00025 } 00026 void pbbright_hit_callback (void) { 00027 if (red_switch && (0.0f < red_brightness || red_brightness <= 1.0f)) { 00028 red_brightness -= 0.1f; 00029 } 00030 if (blue_switch && (0.0f < blue_brightness || blue_brightness <= 1.0f)) { 00031 blue_brightness -= 0.1f; 00032 } 00033 if (green_switch && (0.0f < green_brightness || green_brightness <= 1.0f)) { 00034 green_brightness -= 0.1f; 00035 } 00036 } 00037 int main(void) { 00038 red_switch.mode(PullUp); 00039 blue_switch.mode(PullUp); 00040 green_switch.mode(PullUp); 00041 pbdim.mode(PullUp); 00042 pbbright.mode(PullUp); 00043 red_switch.mode(PullUp); 00044 blue_switch.mode(PullUp); 00045 green_switch.mode(PullUp); 00046 wait(0.001); 00047 00048 pbdim.attach_deasserted(&pbdim_hit_callback); 00049 pbdim.setSampleFrequency(); 00050 pbbright.attach_deasserted(&pbbright_hit_callback); 00051 pbbright.setSampleFrequency(); 00052 00053 while(1) { 00054 red_led = red_brightness; 00055 green_led = green_brightness; 00056 blue_led = blue_brightness; 00057 wait(.2); 00058 } 00059 }
Generated on Fri Sep 2 2022 21:37:14 by
1.7.2