Somewhere in Arizona
Offline
God Member
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
|
 |
« on: March 09, 2010, 09:45:06 pm » |
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
|
|
|
|
|
|
|
Somewhere in Arizona
Offline
God Member
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
|
 |
« Reply #2 on: March 11, 2010, 11:45:29 pm » |
anybody there?
|
|
|
|
|
Logged
|
|
|
|
|
North Carolina, USA
Offline
Full Member
Karma: 1
Posts: 137
:O Arduino!
|
 |
« Reply #3 on: March 11, 2010, 11:54:58 pm » |
in the siren loop, put in a "if btn == HIGH, then..." and pop the second loop there.
Does that help?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #4 on: March 12, 2010, 02:25:21 am » |
i want have 2 void loops Sorry, no can do. Could you maybe rewrite the question?
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
Somewhere in Arizona
Offline
God Member
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
|
 |
« Reply #5 on: March 12, 2010, 10:00:50 am » |
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
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #6 on: March 12, 2010, 10:04:07 am » |
If you want to use HIGH and LOW, don't connect it to an analogue pin.
|
|
|
|
|
Logged
|
Per Arduino ad Astra
|
|
|
|
Somewhere in Arizona
Offline
God Member
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
|
 |
« Reply #7 on: March 12, 2010, 10:19:03 am » |
so how do i connect it?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Faraday Member
Karma: 15
Posts: 2852
Gorm deficient
|
 |
« Reply #8 on: March 12, 2010, 10:41:11 am » |
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
|
|
|
|
Somewhere in Arizona
Offline
God Member
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
|
 |
« Reply #9 on: March 12, 2010, 06:00:56 pm » |
any schematics / code? im confused
|
|
|
|
|
Logged
|
|
|
|
|
Somewhere in Arizona
Offline
God Member
Karma: 0
Posts: 725
Arduino must be a drug, because I'm addicted!
|
 |
« Reply #10 on: March 14, 2010, 01:41:35 pm » |
hello? i need help... im at the point of the switch...
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #11 on: March 14, 2010, 03:13:32 pm » |
Read reply #9 // 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.
|
|
|
|
|