Skip to content

Instantly share code, notes, and snippets.

@donly
Created December 25, 2020 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donly/6364ef50184d5aed558c355ecea01e8d to your computer and use it in GitHub Desktop.
Save donly/6364ef50184d5aed558c355ecea01e8d to your computer and use it in GitHub Desktop.
Photoresistor and buzzer usage demo
#define BUZZER D6
#define LIGHTD D11
void setup() {
Serial.begin(115200);
Serial.println("setup");
pinMode(BUZZER, OUTPUT);
digitalWrite(BUZZER, HIGH);
pinMode(LIGHTD, INPUT);
}
void loop() {
if (digitalRead(LIGHTD)) {
buzzer_Di();
}
else {
buzzer_off();
}
}
void buzzer_Di() {
Serial.println("Bi..ON");
digitalWrite(BUZZER, LOW);
delay(300);
}
void buzzer_off() {
Serial.println("Bi..OFF");
digitalWrite(BUZZER, HIGH);
delay(300);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment