Created
September 30, 2013 23:00
-
-
Save jfinstrom/6771543 to your computer and use it in GitHub Desktop.
Set the buzzer on or off by physical button or by serial...
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
int btn = 2; | |
int spkr = 10; | |
int incomingByte = 0; | |
int bybtn = 0; | |
void setup() | |
{ | |
Serial.begin(9600); | |
Serial.println("Arduino Online"); | |
Serial.println(".............."); | |
//setup board | |
pinMode(btn, INPUT); | |
pinMode(spkr,OUTPUT); | |
//initialize the speaker off... may not be needed. | |
digitalWrite(spkr,LOW); | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) { | |
// read the incoming byte: | |
incomingByte = Serial.read(); | |
if ( incomingByte == 49 ){ | |
//received "1" | |
digitalWrite(spkr, HIGH); | |
Serial.print("Buzzer on "); | |
} | |
if ( incomingByte == 48){ | |
//received 0 | |
digitalWrite(spkr,LOW); | |
Serial.print("Buzzer off "); | |
} | |
} | |
//stuff to loop | |
//read if the button is pressed | |
int sensorValue = digitalRead(btn); | |
//if pressed make the buzzer buzz | |
if( sensorValue == 1){ | |
digitalWrite(spkr, HIGH); | |
bybtn = 1; | |
//else buzzzer no buzzzz | |
} else { | |
if(bybtn){ | |
digitalWrite(spkr, LOW); | |
bybtn = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment