stuff
Dependencies: mbed Servo Motor
confetti.cpp@3:e3b0e591e976, 2019-10-15 (annotated)
- Committer:
- m226072
- Date:
- Tue Oct 15 17:52:08 2019 +0000
- Revision:
- 3:e3b0e591e976
- Parent:
- 2:5b599e8e7e8c
- Child:
- 4:439279a72ef4
Code still needs LED's;
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 | 3:e3b0e591e976 | 7 | |
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 | 3:e3b0e591e976 | 27 | } |
m226072 | 3:e3b0e591e976 | 28 | // switch 1 off and 2 on |
m226072 | 3:e3b0e591e976 | 29 | if ((h [0] == 0) && (h [1] == 1)) { |
m226072 | 3:e3b0e591e976 | 30 | jeff.speed (-0.5); |
m226072 | 3:e3b0e591e976 | 31 | } |
m226072 | 3:e3b0e591e976 | 32 | // switch 1 off and 2 off |
m226072 | 3:e3b0e591e976 | 33 | if (((h [0] == 0) && (h [1] == 0)) || ((h [0] == 1) && (h [1] == 1)) ){ |
m226072 | 3:e3b0e591e976 | 34 | |
m226072 | 3:e3b0e591e976 | 35 | jeff.speed (0); |
m226072 | 3:e3b0e591e976 | 36 | } |
m226072 | 3:e3b0e591e976 | 37 | // switch 3 on and 4 off |
m226072 | 3:e3b0e591e976 | 38 | if ((h [2] == 1) && (h [3] ==0)) { |
m226072 | 3:e3b0e591e976 | 39 | if (i>1.0) { |
m226072 | 3:e3b0e591e976 | 40 | i=1.0; |
m226072 | 3:e3b0e591e976 | 41 | } |
m226072 | 3:e3b0e591e976 | 42 | spin = i; |
m226072 | 3:e3b0e591e976 | 43 | wait (0.1); |
m226072 | 3:e3b0e591e976 | 44 | i = i + 0.02; |
m226072 | 3:e3b0e591e976 | 45 | |
m221770 | 0:54b247669e8c | 46 | |
m226072 | 3:e3b0e591e976 | 47 | } |
m226072 | 3:e3b0e591e976 | 48 | // switch 3 off and 4 on |
m226072 | 3:e3b0e591e976 | 49 | if ((h [2] == 0) && (h [3] ==1)) { |
m226072 | 3:e3b0e591e976 | 50 | if (i<0.0) { |
m226072 | 3:e3b0e591e976 | 51 | i=0.0; |
m226072 | 3:e3b0e591e976 | 52 | } |
m226072 | 3:e3b0e591e976 | 53 | spin = i; |
m226072 | 3:e3b0e591e976 | 54 | wait (0.1); |
m226072 | 3:e3b0e591e976 | 55 | i = i - 0.02; |
m226072 | 3:e3b0e591e976 | 56 | } |
m226072 | 3:e3b0e591e976 | 57 | // switch 3 off and 4 off |
m226072 | 3:e3b0e591e976 | 58 | if (((h [2] == 0) && (h [3] ==0))|| ((h [2] == 1) && (h [3] ==1))) { |
m226072 | 3:e3b0e591e976 | 59 | spin = i ; |
m226072 | 3:e3b0e591e976 | 60 | } |
m226072 | 3:e3b0e591e976 | 61 | // switch 5 on |
m226072 | 3:e3b0e591e976 | 62 | if (h [4] == 1) { |
m226072 | 3:e3b0e591e976 | 63 | gun = 1.0; |
m226072 | 3:e3b0e591e976 | 64 | wait (1.0); |
m226072 | 3:e3b0e591e976 | 65 | gun = 0.0; |
m226072 | 3:e3b0e591e976 | 66 | wait (1.0); |
m226072 | 3:e3b0e591e976 | 67 | } |
m226072 | 3:e3b0e591e976 | 68 | |
m226072 | 3:e3b0e591e976 | 69 | |
m226072 | 3:e3b0e591e976 | 70 | |
m226072 | 3:e3b0e591e976 | 71 | } |
m226072 | 3:e3b0e591e976 | 72 | } |