Lab1
Dependencies: mbed Joystick MPR121_Demo
main.cpp@1:a8881b932dd3, 2016-09-02 (annotated)
- Committer:
- rmaran6
- Date:
- Fri Sep 02 17:20:11 2016 +0000
- Revision:
- 1:a8881b932dd3
- Parent:
- 0:b6b25be5f240
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rmaran6 | 0:b6b25be5f240 | 1 | #include "mbed.h" |
rmaran6 | 0:b6b25be5f240 | 2 | |
rmaran6 | 1:a8881b932dd3 | 3 | DigitalIn dip(p13); |
rmaran6 | 1:a8881b932dd3 | 4 | DigitalIn PB1(p11); |
rmaran6 | 1:a8881b932dd3 | 5 | DigitalIn PB2(p12); |
rmaran6 | 1:a8881b932dd3 | 6 | PwmOut red_light(p21); |
rmaran6 | 1:a8881b932dd3 | 7 | //PwmOut green_light(p22); |
rmaran6 | 1:a8881b932dd3 | 8 | //PwmOut blue_light(p23); |
rmaran6 | 0:b6b25be5f240 | 9 | |
rmaran6 | 1:a8881b932dd3 | 10 | //void RGB_light(int r, int g, int b) { |
rmaran6 | 1:a8881b932dd3 | 11 | // red_light = r; |
rmaran6 | 1:a8881b932dd3 | 12 | // green_light = g; |
rmaran6 | 1:a8881b932dd3 | 13 | // blue_light = b; |
rmaran6 | 1:a8881b932dd3 | 14 | //} |
rmaran6 | 0:b6b25be5f240 | 15 | int main() { |
rmaran6 | 1:a8881b932dd3 | 16 | float brightness = 0.5; |
rmaran6 | 0:b6b25be5f240 | 17 | while(1) { |
rmaran6 | 1:a8881b932dd3 | 18 | if(dip){ |
rmaran6 | 1:a8881b932dd3 | 19 | red_light = 0.0; |
rmaran6 | 1:a8881b932dd3 | 20 | } |
rmaran6 | 1:a8881b932dd3 | 21 | else { |
rmaran6 | 1:a8881b932dd3 | 22 | red_light = brightness; |
rmaran6 | 1:a8881b932dd3 | 23 | } |
rmaran6 | 1:a8881b932dd3 | 24 | if(!PB1 && brightness < 1) { |
rmaran6 | 1:a8881b932dd3 | 25 | brightness = brightness + .1; |
rmaran6 | 1:a8881b932dd3 | 26 | wait(.5); |
rmaran6 | 1:a8881b932dd3 | 27 | } |
rmaran6 | 1:a8881b932dd3 | 28 | if(!PB2 && brightness > 0) { |
rmaran6 | 1:a8881b932dd3 | 29 | brightness = brightness - .1; |
rmaran6 | 1:a8881b932dd3 | 30 | wait(.5); |
rmaran6 | 1:a8881b932dd3 | 31 | } |
rmaran6 | 0:b6b25be5f240 | 32 | } |
rmaran6 | 1:a8881b932dd3 | 33 | } |