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: mbed
Fork of Official by
Revision 1:7cdb9114f511, committed 2016-03-21
- Comitter:
- joankangro
- Date:
- Mon Mar 21 15:54:27 2016 +0000
- Parent:
- 0:60a314903fb0
- Commit message:
- 21.03
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Mar 20 15:33:07 2016 +0000
+++ b/main.cpp Mon Mar 21 15:54:27 2016 +0000
@@ -87,7 +87,7 @@
DigitalOut solenoid(PTA2);
//Ball dispensing
-PwmOut dispenser(PTA4);
+DigitalOut dispenser(PTA4);
//Ball Counter
DigitalOut constant7(PTC16);
@@ -125,7 +125,7 @@
float k = 0;
-bool go_slower=false;
+bool go_slower=true;
bool stop=false;
void sound()
@@ -143,6 +143,22 @@
}
+void debugger()
+{
+ //speaker.period(1.0/500.0); // 500hz period
+ //speaker =0.5; //50% duty cycle - max volume
+
+ for (k=400; k<435; k=k+7) {
+ speaker.period(1.0/float(k));
+ speaker=0.5;
+ wait(.1);
+ }
+
+ speaker=0;
+}
+
+
+
void display()
{
@@ -187,17 +203,33 @@
}
}
+int loops=0;
+
+void generatepwm(){
+ loops=0;
+ while(loops<2000){
+ dispenser=1;
+ wait_us(244);
+ dispenser=0;
+ wait_us(244);
+ loops++;
+ }
+}
+
+bool balldrop=false;
+
void count()
{
- wait_ms(0.55); //this time has to be optimised to stop false positives
- if(ball_trigger==0) {
- ballcount++;
- indicator = 0;
- wait (0.25);
- indicator = 1;
- display();
-
- }
+ if(balldrop==true){
+ wait_ms(0.55); //this time has to be optimised to stop false positives
+ if(ball_trigger==0) {
+ ballcount++;
+ indicator = 0;
+ wait (0.25);
+ indicator = 1;
+ display();
+ }
+ }
}
int balls=0;
@@ -236,9 +268,11 @@
if(midbar==1 and back==1 and front==0){ //or (midbar==1 and front==1)) {
//shoot balls
+ ballcount=5;
+ display();
ENA=0;
ENB=0;
- motors=0.095;
+ motors=0.09;
stop=false;
if (ballcount>0){
while(ballcount>0){
@@ -253,7 +287,7 @@
stop=true;
}
}
-
+ go_slower=false;
motors=0;
ENA=0.35;
ENB=0.35;
@@ -261,15 +295,16 @@
wait(2);
}
return bar==1;
- } else if(front==1 and midbar==0 and back==1) { //test barcode
- ENA=0;
- ENB=0;
+ } else if(front==1 and midbar==0 and back==1) { //test barcode
+ balldrop=true;
ballcount=0;
display();
+ ENA=0;
+ ENB=0;
while(ballcount<5){
- dispenser=0.5;
- wait(1);
+ generatepwm();
dispenser=0;
+ wait(1);
}
ENA=0.35;
ENB=0.35;
@@ -356,10 +391,6 @@
wait(0.3);
indicator=0;// because its a pile of shite
- //define pwn freq for dispenser
- dispenser.period(1/2048);
-
-
dispenser=0;
ENA.period(0.001);
@@ -392,6 +423,7 @@
//sine_interrupt.detach();
bar = 0;
+ balldrop=false;
//counter=counter+1;
//zonecounter=zonecounter+1;
@@ -409,16 +441,16 @@
if(middle>0.4) {
ledmiddle=1;
- ENA=0.45;
+ ENA=0.46;
ENB=0.45;
} else {
ledmiddle=0;
- ENA=0.4;
+ ENA=0.41;
ENB=0.4;
}
if(go_slower==true){
- ENA=0.38;
+ ENA=0.39;
ENB=0.38;
}
@@ -459,12 +491,7 @@
if((left>0.4 or leftmost>0.4)and(right>0.4 or rightmost>0.4)) {
ENB=0.38;
ENA=0;
- wait(2);
- if(go_slower==false){
- go_slower=true;
- }else{
- go_slower=false;
- }
+ wait(2);
}
