Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Motor QEI mbed mbedWSEsbc
Fork of ES309_NerfTurretfinal by
Revision 1:758c16346f28, committed 2016-03-01
- Comitter:
- rixonfletcher
- Date:
- Tue Mar 01 15:00:31 2016 +0000
- Parent:
- 0:e0d517c05233
- Child:
- 2:b8a033375c27
- Commit message:
- firing from mbed
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Feb 18 16:06:13 2016 +0000
+++ b/main.cpp Tue Mar 01 15:00:31 2016 +0000
@@ -1,1 +1,48 @@
-#include mbed.h
+#include "mbed.h"
+
+DigitalOut light[]= {LED1, LED2, LED3, LED4};
+DigitalOut spinner(p20);
+DigitalOut plunger(p21);
+
+int main()
+{
+ int disc=20; //number of discs in magazine
+ float shot_time=0.6; //time per shot. 3.51s for 5 shots
+ int fire=0; //number of bullets to fire (reset to zero after every round of shots)
+ float fwait; //fire time wait
+
+ while(disc>0) {
+ light[0].write(0);
+ light[3].write(0);
+ spinner=0;
+ plunger=0;
+ printf("Ready to fire, %d discs left. Type number of shots. \n \r\r",disc);
+ scanf("%d",&fire);
+
+ if (fire>0) { //fires for desired number of shots
+
+ fwait=fire*shot_time;
+ printf("fire=%d \n\r",fire);
+ printf("fwait=%f \n\r",fwait);
+
+ light[0].write(1);
+ spinner=1; //spinner turns on for 3 seconds
+ wait(1.5);
+
+ light[3].write(1);
+ plunger=1; //plunger turns on for desired number of shots
+ wait(fwait);
+
+ //calculate number of shots left
+ disc=disc-fire;
+ //reset fire sequence
+ fire=0;
+ fwait=0;
+ }
+ }
+ light[0].write(0);
+ light[3].write(0);
+ spinner=0;
+ plunger=0;
+ printf("You ran out of discs. Press the reset button to reload. \n\r\r");
+}
\ No newline at end of file
