Pages: [1]   Go Down
Author Topic: Police Lights and Siren  (Read 3227 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 10, 2010, 10:11:35 am by Jeremy1998 » Logged

Norway
Offline Offline
Sr. Member
****
Karma: 0
Posts: 344
Just dip it in mercury and power it up
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

anybody there?
Logged

North Carolina, USA
Offline Offline
Full Member
***
Karma: 1
Posts: 137
:O Arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Does that help?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i want have 2 void loops

Sorry, no can do.

Could you maybe rewrite the question?
Logged

Per Arduino ad Astra

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want to use HIGH and LOW, don't connect it to an analogue pin.
Logged

Per Arduino ad Astra

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so how do i connect it?
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Per Arduino ad Astra

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

any schematics / code? im confused
Logged

Offline Offline
God Member
*****
Karma: 1
Posts: 733
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26536
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read reply #9
Code:
// 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");
  }
}
Logged

"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.

Pages: [1]   Go Up
Jump to: