Cameron Causer
/
4180_L1_P3_RGBLedDimmer
Dimmer code for RGB LED
Revision 0:17f02642d413, committed 2018-10-16
- Comitter:
- kzar
- Date:
- Tue Oct 16 18:52:58 2018 +0000
- Commit message:
- Dimmer code for RGB LED
Changed in this revision
diff -r 000000000000 -r 17f02642d413 PinDetect.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PinDetect.lib Tue Oct 16 18:52:58 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 000000000000 -r 17f02642d413 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 16 18:52:58 2018 +0000 @@ -0,0 +1,51 @@ +#include "mbed.h" +#include "PinDetect.h" + +//Init leds using PwmOut +PwmOut red(p26); +PwmOut green(p25); +PwmOut blue(p24); +//Init pushbuttons using PinDetect +PinDetect pb1(p21); +PinDetect pb2(p22); +//Init dip switches using DigitalIn +DigitalIn dip1(p15); +DigitalIn dip2(p16); +DigitalIn dip3(p17); + + +//Increment or decrement the led depending on which button was pressed +void pb1_pressed(void) { + if (dip1 == 1 && red < 1) { red = red + .1; } + if (dip2 == 1 && green < 1) { green = green + .1; } + if (dip3 == 1 && blue < 1) { blue = blue + .1; } +} +void pb2_pressed(void) { + if (dip1 == 1 && red > 0) { red = red - .1; } + if (dip2 == 1 && green > 0) { green = green - .1; } + if (dip3 == 1 && blue > 0) { blue = blue - .1; } +} + +int main() { + //Set buttons internal pullup + pb1.mode(PullUp); + pb2.mode(PullUp); + //set for the pressed functions to be called when the button is pressed + pb1.attach_asserted(&pb1_pressed); + pb2.attach_asserted(&pb2_pressed); + //Default the sample freq + pb1.setSampleFrequency(); + pb2.setSampleFrequency(); + //Set switches internal pullup + dip1.mode(PullUp); + dip2.mode(PullUp); + dip3.mode(PullUp); + + //Loop forever + while(1) { + if (dip1 == 0) { red = 0; } + if (dip2 == 0) { green = 0; } + if (dip3 == 0) { blue = 0; } + } +} +
diff -r 000000000000 -r 17f02642d413 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Oct 16 18:52:58 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539 \ No newline at end of file