Arduino Code for a better Ring bell
We will go through this process in class just make sure your breakout board is ready to go!
CODE FOR THE BUTTON (Ring the Bell)
/* doorbell basic BUTTON!! by Rob Faludi faluudi.com */ #define VERSION "1.00a0" int BUTTON = 2; void setup(){ pinMode(BUTTON, INPUT); Serial.begin(9600); } void loop(){ //send a capital D over the serial port if the button is pressed if (digitalRead(BUTTON) == HIGH){ Serial.print('D'); delay(10); //prevents overwhelming the serial port } }
CODE FOR THE BELL (Ring my bell)
* doorbell basic DINGY!! by Rob Faludi faluudi.com */ #define VERSION "1.00a0" int BELL = 4; void setup(){ pinMode(BELL, OUTPUT); Serial.begin(9600); } void loop(){ //look for a capital D over the serial port and ring the bell if found if (Serial.available() > 0){ if (Serial.read() == 'D') { //ring bell briefly digitalWrite(BELL, HIGH); delay(10); digitalWrite(BELL, LOW); } } }
CODE TO CONFIRM FEEDBACK (BELLS)
/* doorbell feedback dingy!! by Rob Faludi faluudi.com */ #define VERSION "1.00a0" int BELL = 4; void setup(){ pinMode(BELL, OUTPUT); Serial.begin(9600); } void loop(){ //look for a capital D over the serial port and ring the bell if found if (Serial.available() > 0){ if (Serial.read() == 'D') { //send feedback that the message was received Serial.print('K'); //ring bell briefly digitalWrite(BELL, HIGH); delay(10); digitalWrite(BELL, LOW); } } }
CODE TO CONFIRM FEEDBACK (BUTTONS)
/* doorbell feedback BUTTON!! by Rob Faludi faluudi.com */ #define VERSION "1.00a0" int BUTTON = 2; int LED = 11; void setup(){ pinMode (BUTTON, INPUT); pinMode (LED, OUTPUT); Serial.begin(9600); } void loop(){ //send a capital D over the serial port if the button is pressed if (digitalRead(BUTTON) == HIGH){ Serial.print('D'); delay(10); //prevents overwhelming the serial port } // if a capital K is received back, light the feedback LED if (Serial.available() > 0){ if (Serial.read() == 'K'){ digitalWrite(LED, HIGH); } } // when the button is released, turn off the if ( digitalRead(BUTTON) == LOW){ digitalWrite(LED, LOW); } }
Reply