Go Down

Topic: Police Lights and Siren (Read 3525 times) previous topic - next topic

Jeremy1998

Mar 10, 2010, 03:45 am Last Edit: Mar 10, 2010, 04:11 pm by Jeremy1998 Reason: 1
i am making some police lights, and need two things;

sound players
"horn"

lets start with the "horn"
i need to use a pushbutton as a "horn" to change the void loop that runs... basically i want have 2 void loops, one for normal police lights, and one for when the "horn" is on. how do i write two void loops, and make them play by the pushbutton?

ex:
void loop 1
hsadf ajsdv das
dsvasvdsa

void loop 2
fvadsvasdvaASv
dsvasdddvd

if the pishbutton is off, void loop one plays, and if it is on, void loop two plays

ArduinoM

Try out Tone library for the arduino
http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation
I have not tested it yet, but there is a tutorial there.

David


kevinsa5

in the siren loop, put in a "if btn == HIGH, then..." and pop the second loop there.

Does that help?

Groove

Quote
i want have 2 void loops


Sorry, no can do.

Could you maybe rewrite the question?
Per Arduino ad Astra

Jeremy1998

Quote
if btn == HIGH, then...


so, i use a pushbutton, and hook it to an analog pin... then i define it as "btn", and put "if btn == LOW, (code1) and then "if btn == HIGH, (code2)"

an i correct? also, how do i connect the pishbutton?

Groove

If you want to use HIGH and LOW, don't connect it to an analogue pin.
Per Arduino ad Astra

Jeremy1998


Groove

Between GND and a digital pin, with the pin configured as INPUT, and with the internal pull-up enabled.
It will read HIGH when the switch is open.
Per Arduino ad Astra

Jeremy1998

any schematics / code? im confused

Jeremy1998

hello? i need help... im at the point of the switch...

AWOL

Read reply #9
Code: [Select]

// connect switch between digital pin 2 and GND
const int BUTTON_PIN = 2;

void setup ()
{
 Serial.begin (9600);
 pinMode(BUTTON_PIN, INPUT);
 digitalWrite (BUTTON_PIN, HIGH); // apply pull-up
}

void loop ()
{
 if (digitalRead (BUTTON_PIN)  == LOW)) {
   Serial.println ("Switch closed");
 } else {
   Serial.println ("Switch open");
 }
}
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up