Traffic Light Doorbell by Alvaro, Bree, and Victor

code for the doorbell buzzer and doorbell bell

Code for the bell

#define VERSION “1.00a0”
int BELL = 5;
void setup(){

pinMode(BELL, OUTPUT);

Serial.begin(9600);

}
void loop(){
if (Serial.available() > 0){

switch(Serial.read())    {

case ‘G’:

Serial.print(“N”);

ring();

break;

case ‘Y’:

Serial.print(“W”);

ring();

break;
case ‘R’:

Serial.print(“D”);

ring();

break;
case ‘X’:

Serial.print(“O”);

break;

}

}

}

void ring(){
tone(BELL, 400);

delay(10);

tone(BELL, 700);

delay(10);

noTone(BELL);}

Code for the Buzzer

#define VERSION “1.00a0”

 

int pressCounter;

//int resetCounter;

int BUZZER   = 7;

int BUTTON   = 2;

int GREEN    = 8;

int YELLOW   = 10;

int RED      = 12;

 

 

void setup(){

//  resetCounter = 0;

pressCounter = 0;

pinMode (BUTTON, INPUT);

pinMode (BUZZER, OUTPUT);

pinMode (GREEN,  OUTPUT);

pinMode (YELLOW, OUTPUT);

pinMode (RED,    OUTPUT);

Serial.begin(9600);

}

 

void loop(){

if (digitalRead(BUTTON)==HIGH){

if( pressCounter == 0){

Serial.println(‘G’);

delay(300);

pressCounter = 1;

}

 

if( pressCounter == 1){

Serial.println(‘Y’);

delay(300);

pressCounter = 2;

}

if( pressCounter == 2){

Serial.println(‘R’);

delay(300);

pressCounter = 3;

}

if( pressCounter ==3){

Serial.println(‘X’);

pressCounter = 0;

}

 

 

if (Serial.available() > 0){

 

switch(Serial.read()){

case ‘N’:

digitalWrite(GREEN,HIGH);

digitalWrite(RED,LOW);

tone(BUZZER,900);

delay(10);

tone(BUZZER, 800);

delay(10);

noTone(BUZZER);

break;

 

case ‘W’:

digitalWrite(YELLOW,HIGH);

digitalWrite(GREEN,LOW);

tone(BUZZER,400);

delay(10);

tone(BUZZER, 600);

delay(10);

noTone(BUZZER);

break;

//

case ‘D’:

digitalWrite(RED,HIGH);

digitalWrite(YELLOW,LOW);

tone(BUZZER,300);

delay(400);

noTone(BUZZER);

break;

}

}

 

}

 

}