![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
stuff
Dependencies: mbed Servo Motor
confetti.cpp
- Committer:
- m226072
- Date:
- 2019-10-15
- Revision:
- 4:439279a72ef4
- Parent:
- 3:e3b0e591e976
File content as of revision 4:439279a72ef4:
#include "mbed.h" #include "Motor.h" #include "Servo.h" DigitalIn switches [5] = {p15, p16, p17, p18, p19}; DigitalOut lights [5] = {p10, p11, p12, p13, p14}; Servo gun (p24); Servo spin (p23); Motor jeff (p26, p29, p30); int h [5]; float i; int main () { i=0.5; while (1) { h [0] = switches [0]; h [1] = switches [1]; h [2] = switches [2]; h [3] = switches [3]; h [4] = switches [4]; // switch 1 on and 2 off if ((h [0] == 1) && (h [1] ==0)) { jeff.speed (0.5); lights[0] = 1; } // switch 1 off and 2 on if ((h [0] == 0) && (h [1] == 1)) { jeff.speed (-0.5); lights[1] = 1; } // switch 1 off and 2 off if (((h [0] == 0) && (h [1] == 0)) || ((h [0] == 1) && (h [1] == 1)) ) { jeff.speed (0); lights[2] = 1; } // switch 3 on and 4 off if ((h [2] == 1) && (h [3] ==0)) { if (i>1.0) { i=1.0; } spin = i; wait (0.1); i = i + 0.02; lights[3] = 1; } // switch 3 off and 4 on if ((h [2] == 0) && (h [3] ==1)) { if (i<0.0) { i=0.0; } spin = i; wait (0.1); i = i - 0.02; lights[4] = 1; } // switch 3 off and 4 off if (((h [2] == 0) && (h [3] ==0))|| ((h [2] == 1) && (h [3] ==1))) { spin = i ; } // switch 5 on if (h [4] == 1) { gun = 1.0; wait (1.0); gun = 0.0; wait (1.0); } } }