![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
454
Dependencies: Motor QEI mbed mbedWSEsbc
Fork of ES309_NerfTurretfinal by
main.cpp@1:758c16346f28, 2016-03-01 (annotated)
- Committer:
- rixonfletcher
- Date:
- Tue Mar 01 15:00:31 2016 +0000
- Revision:
- 1:758c16346f28
- Parent:
- 0:e0d517c05233
- Child:
- 2:b8a033375c27
firing from mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rixonfletcher | 1:758c16346f28 | 1 | #include "mbed.h" |
rixonfletcher | 1:758c16346f28 | 2 | |
rixonfletcher | 1:758c16346f28 | 3 | DigitalOut light[]= {LED1, LED2, LED3, LED4}; |
rixonfletcher | 1:758c16346f28 | 4 | DigitalOut spinner(p20); |
rixonfletcher | 1:758c16346f28 | 5 | DigitalOut plunger(p21); |
rixonfletcher | 1:758c16346f28 | 6 | |
rixonfletcher | 1:758c16346f28 | 7 | int main() |
rixonfletcher | 1:758c16346f28 | 8 | { |
rixonfletcher | 1:758c16346f28 | 9 | int disc=20; //number of discs in magazine |
rixonfletcher | 1:758c16346f28 | 10 | float shot_time=0.6; //time per shot. 3.51s for 5 shots |
rixonfletcher | 1:758c16346f28 | 11 | int fire=0; //number of bullets to fire (reset to zero after every round of shots) |
rixonfletcher | 1:758c16346f28 | 12 | float fwait; //fire time wait |
rixonfletcher | 1:758c16346f28 | 13 | |
rixonfletcher | 1:758c16346f28 | 14 | while(disc>0) { |
rixonfletcher | 1:758c16346f28 | 15 | light[0].write(0); |
rixonfletcher | 1:758c16346f28 | 16 | light[3].write(0); |
rixonfletcher | 1:758c16346f28 | 17 | spinner=0; |
rixonfletcher | 1:758c16346f28 | 18 | plunger=0; |
rixonfletcher | 1:758c16346f28 | 19 | printf("Ready to fire, %d discs left. Type number of shots. \n \r\r",disc); |
rixonfletcher | 1:758c16346f28 | 20 | scanf("%d",&fire); |
rixonfletcher | 1:758c16346f28 | 21 | |
rixonfletcher | 1:758c16346f28 | 22 | if (fire>0) { //fires for desired number of shots |
rixonfletcher | 1:758c16346f28 | 23 | |
rixonfletcher | 1:758c16346f28 | 24 | fwait=fire*shot_time; |
rixonfletcher | 1:758c16346f28 | 25 | printf("fire=%d \n\r",fire); |
rixonfletcher | 1:758c16346f28 | 26 | printf("fwait=%f \n\r",fwait); |
rixonfletcher | 1:758c16346f28 | 27 | |
rixonfletcher | 1:758c16346f28 | 28 | light[0].write(1); |
rixonfletcher | 1:758c16346f28 | 29 | spinner=1; //spinner turns on for 3 seconds |
rixonfletcher | 1:758c16346f28 | 30 | wait(1.5); |
rixonfletcher | 1:758c16346f28 | 31 | |
rixonfletcher | 1:758c16346f28 | 32 | light[3].write(1); |
rixonfletcher | 1:758c16346f28 | 33 | plunger=1; //plunger turns on for desired number of shots |
rixonfletcher | 1:758c16346f28 | 34 | wait(fwait); |
rixonfletcher | 1:758c16346f28 | 35 | |
rixonfletcher | 1:758c16346f28 | 36 | //calculate number of shots left |
rixonfletcher | 1:758c16346f28 | 37 | disc=disc-fire; |
rixonfletcher | 1:758c16346f28 | 38 | //reset fire sequence |
rixonfletcher | 1:758c16346f28 | 39 | fire=0; |
rixonfletcher | 1:758c16346f28 | 40 | fwait=0; |
rixonfletcher | 1:758c16346f28 | 41 | } |
rixonfletcher | 1:758c16346f28 | 42 | } |
rixonfletcher | 1:758c16346f28 | 43 | light[0].write(0); |
rixonfletcher | 1:758c16346f28 | 44 | light[3].write(0); |
rixonfletcher | 1:758c16346f28 | 45 | spinner=0; |
rixonfletcher | 1:758c16346f28 | 46 | plunger=0; |
rixonfletcher | 1:758c16346f28 | 47 | printf("You ran out of discs. Press the reset button to reload. \n\r\r"); |
rixonfletcher | 1:758c16346f28 | 48 | } |