
Lab3 Part
main.cpp@1:ff9797f5be2c, 2018-01-30 (annotated)
- Committer:
- Nydrel
- Date:
- Tue Jan 30 22:42:11 2018 +0000
- Revision:
- 1:ff9797f5be2c
- Parent:
- 0:02946956d93e
Changed main while loop -- inverted redOn, blueOn, greenOn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bjs9 | 0:02946956d93e | 1 | #include "mbed.h" |
bjs9 | 0:02946956d93e | 2 | #include "PinDetect.h" |
bjs9 | 0:02946956d93e | 3 | #include "RGB_LED.h" |
bjs9 | 0:02946956d93e | 4 | |
bjs9 | 0:02946956d93e | 5 | RGBLed myRGBled(p22,p23,p24); |
bjs9 | 0:02946956d93e | 6 | PinDetect pb1(p16); |
bjs9 | 0:02946956d93e | 7 | PinDetect pb2(p17); |
bjs9 | 0:02946956d93e | 8 | DigitalIn switchInputRed(p13); |
bjs9 | 0:02946956d93e | 9 | DigitalIn switchInputBlue(p14); |
bjs9 | 0:02946956d93e | 10 | DigitalIn switchInputGreen(p15); |
bjs9 | 0:02946956d93e | 11 | |
bjs9 | 0:02946956d93e | 12 | |
bjs9 | 0:02946956d93e | 13 | float illuminateRed = 0.0f; |
bjs9 | 0:02946956d93e | 14 | float illuminateBlue = 0.0f; |
bjs9 | 0:02946956d93e | 15 | float illuminateGreen = 0.0f; |
bjs9 | 0:02946956d93e | 16 | bool greenOn =false; |
bjs9 | 0:02946956d93e | 17 | bool blueOn = false; |
bjs9 | 0:02946956d93e | 18 | bool redOn = false; |
bjs9 | 0:02946956d93e | 19 | |
bjs9 | 0:02946956d93e | 20 | |
bjs9 | 0:02946956d93e | 21 | void pb1_dim_callback (void) { |
bjs9 | 0:02946956d93e | 22 | if(redOn && illuminateRed > 0.0f){ |
bjs9 | 0:02946956d93e | 23 | illuminateRed -= 0.1f; |
bjs9 | 0:02946956d93e | 24 | } |
bjs9 | 0:02946956d93e | 25 | if(greenOn && illuminateGreen > 0.0f){ |
bjs9 | 0:02946956d93e | 26 | illuminateGreen -= 0.1f; |
bjs9 | 0:02946956d93e | 27 | } |
bjs9 | 0:02946956d93e | 28 | if(blueOn && illuminateBlue > 0.0f) { |
bjs9 | 0:02946956d93e | 29 | illuminateBlue -= 0.1f; |
bjs9 | 0:02946956d93e | 30 | } |
bjs9 | 0:02946956d93e | 31 | } |
bjs9 | 0:02946956d93e | 32 | void pb2_bright_callback (void) { |
bjs9 | 0:02946956d93e | 33 | if(redOn && illuminateRed <= 1.0f){ |
bjs9 | 0:02946956d93e | 34 | illuminateRed += 0.1f; |
bjs9 | 0:02946956d93e | 35 | } |
bjs9 | 0:02946956d93e | 36 | if(greenOn && illuminateGreen <= 1.0f){ |
bjs9 | 0:02946956d93e | 37 | illuminateGreen += 0.1f; |
bjs9 | 0:02946956d93e | 38 | } |
bjs9 | 0:02946956d93e | 39 | if(blueOn && illuminateBlue <= 1.0f) { |
bjs9 | 0:02946956d93e | 40 | illuminateBlue += 0.1f; |
bjs9 | 0:02946956d93e | 41 | } |
bjs9 | 0:02946956d93e | 42 | } |
bjs9 | 0:02946956d93e | 43 | int main() { |
bjs9 | 0:02946956d93e | 44 | switchInputRed.mode(PullUp); |
bjs9 | 0:02946956d93e | 45 | switchInputGreen.mode(PullUp); |
bjs9 | 0:02946956d93e | 46 | switchInputBlue.mode(PullUp); |
bjs9 | 0:02946956d93e | 47 | pb1.mode(PullUp); |
bjs9 | 0:02946956d93e | 48 | pb2.mode(PullUp); |
bjs9 | 0:02946956d93e | 49 | wait(.01); |
bjs9 | 0:02946956d93e | 50 | |
bjs9 | 0:02946956d93e | 51 | pb1.attach_deasserted(&pb1_dim_callback); |
bjs9 | 0:02946956d93e | 52 | pb2.attach_deasserted(&pb2_bright_callback); |
bjs9 | 0:02946956d93e | 53 | |
bjs9 | 0:02946956d93e | 54 | pb1.setSampleFrequency(); |
bjs9 | 0:02946956d93e | 55 | pb2.setSampleFrequency(); |
bjs9 | 0:02946956d93e | 56 | |
bjs9 | 0:02946956d93e | 57 | while(1) { |
Nydrel | 1:ff9797f5be2c | 58 | redOn = !switchInputRed; |
Nydrel | 1:ff9797f5be2c | 59 | blueOn = !switchInputBlue; |
Nydrel | 1:ff9797f5be2c | 60 | greenOn = !switchInputGreen; |
bjs9 | 0:02946956d93e | 61 | myRGBled.write(illuminateRed,illuminateGreen,illuminateBlue); |
bjs9 | 0:02946956d93e | 62 | wait(.1); |
bjs9 | 0:02946956d93e | 63 | } |
bjs9 | 0:02946956d93e | 64 | } |