I am programming an alarm clock, using a grove board, a light sensor, a buzzer and a button.
I want it to work this way:
If it is dark, then no sound
If it is light, then buzzer sounds.
If buzzer sounds, then the buzzer stops, if I press button.
By pressing the button 1 time, the buzzer stops until it has been dark 1 more time in the room.
I dont know how to code the last thing: By pressing the button 1 time, the buzzer stops until it has been dark 1 more time in the room.
I have put my code below:
int lightSensorPin = A0;
int analogValue = 0;
int Buzzer = 3;
int Button = 5;
bool Pressed;
void setup()
{
pinMode(Buzzer, OUTPUT);
pinMode(Button, INPUT);
Serial.begin(9600);
}
void loop()
{
Pressed = digitalRead(Button);
analogValue = analogRead(lightSensorPin);
Serial.println(" ");
Serial.println(Pressed);
Serial.println(analogValue);
delay (1000);
if(analogValue < 100)
{
digitalWrite(Buzzer, LOW);
Serial.println("Det er mørkt"); // if buzzer is low, monitor writes that it is dark
}
if(analogValue > 100)
{
digitalWrite(Buzzer, HIGH);
Serial.println("Det er lyst"); // if buzzer is high, monitor writes that it is light
}
if (Pressed)
{
digitalWrite(Buzzer, LOW);
Serial.println("Der er trykket sluk"); // if button is pressed, monitor writes that button has been pressed.
}
}