I was wondering how would I get the LED to turn on when the buzzer is on, I am doing this for a wire buzzer game and wanted the led to activate when the wire is touched with the the buzzer. How would I do this?
I am a beginner thanks!
I was wondering how would I get the LED to turn on when the buzzer is on, I am doing this for a wire buzzer game and wanted the led to activate when the wire is touched with the the buzzer. How would I do this?
I am a beginner thanks!
what does the buzzer command?
Heres the code
int ledPin = 13;
int redPin = 12;
const int buzzer = 9;
int state = 0;
int buzzerState = 0;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(redPin, OUTPUT);
}
void loop() {
tone(buzzer, 1000);
digitalWrite(ledPin, HIGH);
delay(45000);
digitalWrite(ledPin, LOW);
delay(1);
digitalWrite(redPin, HIGH);
delay(10000);
digitalWrite(redPin, LOW);
delay(1);
}
it only has a green led to stay on for some time until it turns off the red led goes on
for information, the code must be written differently ... I can't modify it, but use![]()
Git rid of delay() calls and use millis(). The following tutorials should help:
Hello, thanks for the information, I'm a bit new to Arduino can you clarify what millis() would help with in the code I would really appreciate it.
Thanks
I assume you will add a digital input to detect when the wire is touched. However, if you just need to activate the buzzer and an LED when a wire is touched why do you need an Arduino at all? All you need is a power supply, buzzer, LED and a resistor.
I guess I'm missing something...
millis is the time expressed in milliseconds, which you can call whenever you want ... function: millis ()
int time=0;
void setup() {
}
void loop() {
if(millis()>time){
time=millis()+1000;
}
}