So this is the program now.
Which is much better.
Now it runs the whole program when the switch is activated. Which is what i want (yay)
But then it just runs the first part for some reason by it self with no switch input??
(this bit) (turns on a LED and Vibe Motor)
digitalWrite(vibeMotor, HIGH);
Start = millis();
while((millis()-Start)<50){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
digitalWrite(LED, HIGH);
beep(piezo,tonec,500);
Start = millis();
while((millis()-Start)<2000){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
HEre is the whole program with "!" added and then removed from the other digitalReads\
//set correct pin numbers as required
#define reedswitch 11
#define vibeMotor 5
#define piezo 9
#define LED 13
long Start = 0;
// this section is Piezo Pitch
#define tonec 2500
#define toned 3900
#define tonee 3950
#define tonep 0
void setup() {
// put your setup code here, to run once:
pinMode(reedswitch, INPUT_PULLUP);
pinMode(vibeMotor, OUTPUT);
pinMode(piezo, OUTPUT);
pinMode(LED, OUTPUT);
digitalWrite(piezo, LOW);
digitalWrite(vibeMotor, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
begin_:
if(!digitalRead(reedswitch)){//If reed switch active
Start = millis();
//digitalWrite(LED2, HIGH); This would be for BALL in Hand LED
while((millis()-Start)<6000){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
digitalWrite(vibeMotor, HIGH);
Start = millis();
while((millis()-Start)<50){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
digitalWrite(LED, HIGH);
beep(piezo,tonec,500);
Start = millis();
while((millis()-Start)<2000){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
beep(piezo,toned,500);
Start = millis();
while((millis()-Start)<1000){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
beep(piezo,tonee,500);
Start = millis();
while((millis()-Start)<1000){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
beep(piezo,tonee,3000);
Start = millis();
while((millis()-Start)<1000){
if(digitalRead(reedswitch)){
goto begin_;
break;
}
}
//digitalWrite(vibeMotor, LOW);//turn off ibe motor, if you don't need this just comment out
}
digitalWrite(vibeMotor, LOW);
digitalWrite(piezo, LOW);
digitalWrite(LED, LOW);
}
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)
{
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x<loopTime;x++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayAmount);
}
}