Craig Raslawski
/
switchlight
4180Lab1Part1&2
main.cpp@2:51a94a489f09, 2017-02-27 (annotated)
- Committer:
- CRaslawski
- Date:
- Mon Feb 27 22:30:08 2017 +0000
- Revision:
- 2:51a94a489f09
- Parent:
- 1:dcefd568845d
initial upload
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CRaslawski | 0:3c5cdcee59dd | 1 | #include "mbed.h" |
CRaslawski | 0:3c5cdcee59dd | 2 | |
CRaslawski | 0:3c5cdcee59dd | 3 | DigitalOut myled2(p25); |
CRaslawski | 0:3c5cdcee59dd | 4 | PwmOut myled3(p21); |
CRaslawski | 0:3c5cdcee59dd | 5 | DigitalIn pb(p24); |
CRaslawski | 0:3c5cdcee59dd | 6 | DigitalIn pwmup(p22); |
CRaslawski | 0:3c5cdcee59dd | 7 | DigitalIn pwmdown(p23); |
CRaslawski | 0:3c5cdcee59dd | 8 | |
CRaslawski | 0:3c5cdcee59dd | 9 | int main() { |
CRaslawski | 0:3c5cdcee59dd | 10 | // Part 1 |
CRaslawski | 0:3c5cdcee59dd | 11 | pb.mode(PullUp); // The variable left_pb will be zero when the pushbutton for moving the player left is pressed |
CRaslawski | 0:3c5cdcee59dd | 12 | pwmup.mode(PullUp); |
CRaslawski | 0:3c5cdcee59dd | 13 | pwmdown.mode(PullUp); |
CRaslawski | 0:3c5cdcee59dd | 14 | |
CRaslawski | 0:3c5cdcee59dd | 15 | // Part 2 |
CRaslawski | 2:51a94a489f09 | 16 | myled3.period(0.01f); |
CRaslawski | 0:3c5cdcee59dd | 17 | volatile float duty = 0.50f; |
CRaslawski | 0:3c5cdcee59dd | 18 | myled3.write(duty); |
CRaslawski | 2:51a94a489f09 | 19 | |
CRaslawski | 0:3c5cdcee59dd | 20 | while(1) { |
CRaslawski | 0:3c5cdcee59dd | 21 | // Part 1 |
CRaslawski | 0:3c5cdcee59dd | 22 | while(pb == 0) { |
CRaslawski | 0:3c5cdcee59dd | 23 | myled2 = 0; |
CRaslawski | 0:3c5cdcee59dd | 24 | } |
CRaslawski | 0:3c5cdcee59dd | 25 | myled2 = 1; |
CRaslawski | 0:3c5cdcee59dd | 26 | |
CRaslawski | 0:3c5cdcee59dd | 27 | // Part 2 |
CRaslawski | 0:3c5cdcee59dd | 28 | if(pwmup == 0 && duty < 1.00f) { |
CRaslawski | 2:51a94a489f09 | 29 | //duty = duty + 0.001f; |
CRaslawski | 2:51a94a489f09 | 30 | duty += 0.05f; |
CRaslawski | 0:3c5cdcee59dd | 31 | //duty = 1.0f; |
CRaslawski | 0:3c5cdcee59dd | 32 | myled3.write(duty); |
CRaslawski | 2:51a94a489f09 | 33 | while(pwmup == 0) {} |
CRaslawski | 0:3c5cdcee59dd | 34 | } |
CRaslawski | 0:3c5cdcee59dd | 35 | if(pwmdown == 0 && duty > 0.00f) { |
CRaslawski | 2:51a94a489f09 | 36 | //duty = duty - 0.001f; |
CRaslawski | 2:51a94a489f09 | 37 | duty -= 0.05f; |
CRaslawski | 0:3c5cdcee59dd | 38 | //duty = 0.0f; |
CRaslawski | 0:3c5cdcee59dd | 39 | myled3.write(duty); |
CRaslawski | 2:51a94a489f09 | 40 | while(pwmdown == 0) {} |
CRaslawski | 0:3c5cdcee59dd | 41 | } |
CRaslawski | 0:3c5cdcee59dd | 42 | } |
CRaslawski | 0:3c5cdcee59dd | 43 | } |