Eleanor Hulm
/
EMB_LAB3
Controlling onboard RGB LED with Pulse-Width Modulation
EMB_Lab3_RGB.cpp@1:31823a0dc268, 2019-08-17 (annotated)
- Committer:
- hulmpants
- Date:
- Sat Aug 17 09:43:21 2019 +0000
- Revision:
- 1:31823a0dc268
Embedded Systems Laboratory 3; Controlling RGB LED with Pulse-Width Modulation;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hulmpants | 1:31823a0dc268 | 1 | // IT Tralee Mechatronics: Embedded Systems LAB#3 |
hulmpants | 1:31823a0dc268 | 2 | // Controlling RGB using PWM |
hulmpants | 1:31823a0dc268 | 3 | |
hulmpants | 1:31823a0dc268 | 4 | #include "mbed.h" |
hulmpants | 1:31823a0dc268 | 5 | #include "C12832_lcd.h" |
hulmpants | 1:31823a0dc268 | 6 | |
hulmpants | 1:31823a0dc268 | 7 | C12832_LCD lcd; |
hulmpants | 1:31823a0dc268 | 8 | PwmOut r (p23); |
hulmpants | 1:31823a0dc268 | 9 | PwmOut g (p24); |
hulmpants | 1:31823a0dc268 | 10 | PwmOut b (p25); |
hulmpants | 1:31823a0dc268 | 11 | AnalogIn pot1(p19); // pot 1 = red |
hulmpants | 1:31823a0dc268 | 12 | AnalogIn pot2(p20); // pot 2 = green |
hulmpants | 1:31823a0dc268 | 13 | DigitalIn center(p14); // joystick cent = blue |
hulmpants | 1:31823a0dc268 | 14 | |
hulmpants | 1:31823a0dc268 | 15 | int main() { |
hulmpants | 1:31823a0dc268 | 16 | while(1) { |
hulmpants | 1:31823a0dc268 | 17 | r = 1 - pot1; // range=0-1 / 1=max red / levels varied by changing pot |
hulmpants | 1:31823a0dc268 | 18 | g = 1 - pot2; |
hulmpants | 1:31823a0dc268 | 19 | b = 1 - center; |
hulmpants | 1:31823a0dc268 | 20 | lcd.cls(); // clear LCD |
hulmpants | 1:31823a0dc268 | 21 | lcd.locate(0,0); // location |
hulmpants | 1:31823a0dc268 | 22 | lcd.printf("Fun RGB Rainbow Show :) \n \r"); |
hulmpants | 1:31823a0dc268 | 23 | lcd.locate(0,8); |
hulmpants | 1:31823a0dc268 | 24 | lcd.printf("Pot 1 = %.2f", (float)pot1); // print pot value |
hulmpants | 1:31823a0dc268 | 25 | lcd.locate(0,16); |
hulmpants | 1:31823a0dc268 | 26 | lcd.printf("Pot 2 = %.2f", (float)pot2); } |
hulmpants | 1:31823a0dc268 | 27 | } |