Last active
June 4, 2019 10:59
-
-
Save MindstormFan/b85a569cd23a2e6b435bf51c59062005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the library code: | |
#include "pitches.h" | |
//------------------------------------------ | |
int adc_id = 6; | |
int buzzer = 13;//the pin of the passive buzzer | |
int melody[] = {NOTE_B0, NOTE_DS8}; | |
int duration = 1500; // 1500 miliseconds | |
//------------------------------------------ | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
pinMode(7,OUTPUT); //Green LED is connected to pin 7 | |
pinMode(4,OUTPUT); //Red LED is connected to pin 4 | |
} | |
//------------------------------------------- | |
void loop() { | |
// put your main code here, to run repeatedly: | |
int value = analogRead(adc_id); // get adc value | |
Serial.println(value); | |
if(value >= 250) { | |
digitalWrite(7, HIGH); | |
digitalWrite(4, LOW); | |
tone(buzzer, melody[0], duration); | |
} else { | |
digitalWrite(7, LOW); | |
digitalWrite(4, HIGH); | |
tone(buzzer, melody[1], duration); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment