Hi,
I'm getting close to finishing my air raid siren ( see attached photo's ) I've written some code to alter the siren speed depending the position of a rotary switch, this took me a while using the arduino cook book, Jeremy Blum vids on youtube and here searching the forums.
My setup is RC motor and controller with BEC, 7.2v 3700mah battery, arduino uno, 6 position rotary switch with voltage divider circuit to sense position, main power on / off switch, on order two led push buttons.
I've got the siren running on this set up but would like to add 2 NO push buttons in series to start the siren. this is a safety feature to ensure both hands are on the buttons when running. ( and not in the chopper )
The first three positions on the rotary switch will be low speed cycles for indoor use for me and my kid to use. the remaining three postion will be full speed simulating WWII air raid, and fire trucks but I don't want the little guy hurting his ears so I was thinking of creating a pushing pattern to enable the high speed cycles. something like 5 short presses on the push buttons.
This is where i need some help in formating the right code into my program. my thoughts are sense the button being pressed add 1 to variable each time it's pressed then i need to add this to my else if statements but I not sure of the correct formatting.
Any help would gratefully recieved, please go gently on my code as this is the 1st arduino program I've written, I'm sure it could be more efficient, but the only other thing I've programmed is a 1970's Casio calculator for trigonometry.
Regards
Dale
#include <Servo.h>
Servo myservo1; // create servo object to control a servo
// a maximum of eight servo objects can be created
float pos = 0; // variable to store the rotary switch input
void setup() {
myservo1.attach(9); // attaches the servo on pin 9 to the servo object
myservo1.write(pos);// arm speed controller
delay(3000);
}
// the loop routine runs over and over again forever:
void loop() {
start:
int sensorValue = analogRead(A0); // read the input on analog pin 0:
if (sensorValue > 100 && sensorValue < 200) { goto servo1;} // create jump to values
else if (sensorValue > 300 && sensorValue < 400) { goto servo2;}
else if (sensorValue > 500 && sensorValue < 599) { goto servo3;}
else if (sensorValue > 600 && sensorValue < 699) { goto servo4;}
else if (sensorValue > 800 && sensorValue < 899) { goto servo5;}
else if (sensorValue > 900) { goto servo6;}
servo1:
{ // MAX SPEED 120
myservo1.write(pos = 10); // tell servo to go to position in variable 'pos'
}
{ goto start;}
servo2:
{
myservo1.write(pos = 13);
}
{ goto start;}
servo3:
{
myservo1.write(pos = 20); // tell servo to go to position in variable 'pos'
}
{ goto start;}
servo4:
{
myservo1.write(pos = 25); // tell servo to go to position in variable 'pos'
}
{ goto start;}
servo5:
{
myservo1.write(pos = 30); // tell servo to go to position in variable 'pos'
}
{ goto start;}
servo6:
{
myservo1.write(pos = 120); // tell servo to go to position in variable 'pos'
//delay(700);
}
{ goto start;}
}