Eleanor Hulm
/
EMB_LAB3
Controlling onboard RGB LED with Pulse-Width Modulation
Diff: EMB_Lab3_RGB.cpp
- Revision:
- 1:31823a0dc268
diff -r f86c572491c3 -r 31823a0dc268 EMB_Lab3_RGB.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EMB_Lab3_RGB.cpp Sat Aug 17 09:43:21 2019 +0000 @@ -0,0 +1,27 @@ +// IT Tralee Mechatronics: Embedded Systems LAB#3 +// Controlling RGB using PWM + +#include "mbed.h" +#include "C12832_lcd.h" + +C12832_LCD lcd; +PwmOut r (p23); +PwmOut g (p24); +PwmOut b (p25); +AnalogIn pot1(p19); // pot 1 = red +AnalogIn pot2(p20); // pot 2 = green +DigitalIn center(p14); // joystick cent = blue + +int main() { + while(1) { + r = 1 - pot1; // range=0-1 / 1=max red / levels varied by changing pot + g = 1 - pot2; + b = 1 - center; + lcd.cls(); // clear LCD + lcd.locate(0,0); // location + lcd.printf("Fun RGB Rainbow Show :) \n \r"); + lcd.locate(0,8); + lcd.printf("Pot 1 = %.2f", (float)pot1); // print pot value + lcd.locate(0,16); + lcd.printf("Pot 2 = %.2f", (float)pot2); } +}