![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
stuff
Dependencies: mbed Servo Motor
confetti.cpp@4:439279a72ef4, 2019-10-15 (annotated)
- Committer:
- m226072
- Date:
- Tue Oct 15 18:07:33 2019 +0000
- Revision:
- 4:439279a72ef4
- Parent:
- 3:e3b0e591e976
LED's added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m226072 | 3:e3b0e591e976 | 1 | #include "mbed.h" |
m226072 | 3:e3b0e591e976 | 2 | #include "Motor.h" |
m226072 | 3:e3b0e591e976 | 3 | #include "Servo.h" |
m226072 | 2:5b599e8e7e8c | 4 | |
m226072 | 2:5b599e8e7e8c | 5 | |
m226072 | 3:e3b0e591e976 | 6 | DigitalIn switches [5] = {p15, p16, p17, p18, p19}; |
m226072 | 4:439279a72ef4 | 7 | DigitalOut lights [5] = {p10, p11, p12, p13, p14}; |
m226072 | 3:e3b0e591e976 | 8 | Servo gun (p24); |
m226072 | 3:e3b0e591e976 | 9 | Servo spin (p23); |
m226072 | 3:e3b0e591e976 | 10 | Motor jeff (p26, p29, p30); |
m226072 | 3:e3b0e591e976 | 11 | int h [5]; |
m226072 | 3:e3b0e591e976 | 12 | float i; |
m226072 | 3:e3b0e591e976 | 13 | |
m226072 | 3:e3b0e591e976 | 14 | int main () |
m226072 | 3:e3b0e591e976 | 15 | { |
m226072 | 3:e3b0e591e976 | 16 | i=0.5; |
m226072 | 3:e3b0e591e976 | 17 | while (1) { |
m226072 | 3:e3b0e591e976 | 18 | h [0] = switches [0]; |
m226072 | 3:e3b0e591e976 | 19 | h [1] = switches [1]; |
m226072 | 3:e3b0e591e976 | 20 | h [2] = switches [2]; |
m226072 | 3:e3b0e591e976 | 21 | h [3] = switches [3]; |
m226072 | 3:e3b0e591e976 | 22 | h [4] = switches [4]; |
m226072 | 2:5b599e8e7e8c | 23 | |
m226072 | 3:e3b0e591e976 | 24 | // switch 1 on and 2 off |
m226072 | 3:e3b0e591e976 | 25 | if ((h [0] == 1) && (h [1] ==0)) { |
m226072 | 3:e3b0e591e976 | 26 | jeff.speed (0.5); |
m226072 | 4:439279a72ef4 | 27 | lights[0] = 1; |
m226072 | 3:e3b0e591e976 | 28 | } |
m226072 | 3:e3b0e591e976 | 29 | // switch 1 off and 2 on |
m226072 | 3:e3b0e591e976 | 30 | if ((h [0] == 0) && (h [1] == 1)) { |
m226072 | 3:e3b0e591e976 | 31 | jeff.speed (-0.5); |
m226072 | 4:439279a72ef4 | 32 | lights[1] = 1; |
m226072 | 3:e3b0e591e976 | 33 | } |
m226072 | 3:e3b0e591e976 | 34 | // switch 1 off and 2 off |
m226072 | 4:439279a72ef4 | 35 | if (((h [0] == 0) && (h [1] == 0)) || ((h [0] == 1) && (h [1] == 1)) ) { |
m226072 | 3:e3b0e591e976 | 36 | jeff.speed (0); |
m226072 | 4:439279a72ef4 | 37 | lights[2] = 1; |
m226072 | 3:e3b0e591e976 | 38 | } |
m226072 | 3:e3b0e591e976 | 39 | // switch 3 on and 4 off |
m226072 | 3:e3b0e591e976 | 40 | if ((h [2] == 1) && (h [3] ==0)) { |
m226072 | 3:e3b0e591e976 | 41 | if (i>1.0) { |
m226072 | 3:e3b0e591e976 | 42 | i=1.0; |
m226072 | 3:e3b0e591e976 | 43 | } |
m226072 | 3:e3b0e591e976 | 44 | spin = i; |
m226072 | 3:e3b0e591e976 | 45 | wait (0.1); |
m226072 | 3:e3b0e591e976 | 46 | i = i + 0.02; |
m226072 | 4:439279a72ef4 | 47 | lights[3] = 1; |
m221770 | 0:54b247669e8c | 48 | |
m226072 | 3:e3b0e591e976 | 49 | } |
m226072 | 3:e3b0e591e976 | 50 | // switch 3 off and 4 on |
m226072 | 3:e3b0e591e976 | 51 | if ((h [2] == 0) && (h [3] ==1)) { |
m226072 | 3:e3b0e591e976 | 52 | if (i<0.0) { |
m226072 | 3:e3b0e591e976 | 53 | i=0.0; |
m226072 | 3:e3b0e591e976 | 54 | } |
m226072 | 3:e3b0e591e976 | 55 | spin = i; |
m226072 | 3:e3b0e591e976 | 56 | wait (0.1); |
m226072 | 3:e3b0e591e976 | 57 | i = i - 0.02; |
m226072 | 4:439279a72ef4 | 58 | lights[4] = 1; |
m226072 | 3:e3b0e591e976 | 59 | } |
m226072 | 3:e3b0e591e976 | 60 | // switch 3 off and 4 off |
m226072 | 3:e3b0e591e976 | 61 | if (((h [2] == 0) && (h [3] ==0))|| ((h [2] == 1) && (h [3] ==1))) { |
m226072 | 3:e3b0e591e976 | 62 | spin = i ; |
m226072 | 3:e3b0e591e976 | 63 | } |
m226072 | 3:e3b0e591e976 | 64 | // switch 5 on |
m226072 | 3:e3b0e591e976 | 65 | if (h [4] == 1) { |
m226072 | 3:e3b0e591e976 | 66 | gun = 1.0; |
m226072 | 3:e3b0e591e976 | 67 | wait (1.0); |
m226072 | 3:e3b0e591e976 | 68 | gun = 0.0; |
m226072 | 3:e3b0e591e976 | 69 | wait (1.0); |
m226072 | 3:e3b0e591e976 | 70 | } |
m226072 | 3:e3b0e591e976 | 71 | |
m226072 | 3:e3b0e591e976 | 72 | |
m226072 | 3:e3b0e591e976 | 73 | |
m226072 | 3:e3b0e591e976 | 74 | } |
m226072 | 3:e3b0e591e976 | 75 | } |