////////////////////////////////////////////////////////////////////////////////////////////
// DEFINES AND MACROS AND CONSTANTS
////////////////////////////////////////////////////////////////////////////////////////////
//pins for buttons
const int BLUE_BUTTON_PIN = 7;
const int GREEN_BUTTON_PIN = 6;
const int RED_BUTTON_PIN = 5;
const int YELLOW_BUTTON_PIN = 4;
//pins for LEDS
const int BLUE_LED_PIN = 13;
const int GREEN_LED_PIN = 12;
const int RED_LED_PIN = 11;
const int YELLOW_LED_PIN = 10;
//pins for buzzer
const int BUZZER_PIN = 2;
//tones for colors
const unsigned short BLUE_TONE = 415;
const unsigned short GREEN_TONE = 310;
const unsigned short RED_TONE = 252;
const unsigned short YELLOW_TONE = 209;
////////////////////////////////////////////////////////////////////////////////////////////
// GLOBALS
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// put your setup code here, to run once:
//initialize LEDs pins
pinMode(BLUE_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(YELLOW_LED_PIN, OUTPUT);
//initialize button pins
pinMode(BLUE_BUTTON_PIN, INPUT);
pinMode(GREEN_BUTTON_PIN, INPUT);
pinMode(RED_BUTTON_PIN, INPUT);
pinMode(YELLOW_BUTTON_PIN, INPUT);
//initialize buzzer pin
pinMode(BUZZER_PIN, OUTPUT);
//init serial port
Serial.begin(115200);
Serial.write("\n\rPINs initialized");
}
void loop() {
// put your main code here, to run repeatedly:
//read blue button input
if (!digitalRead(BLUE_BUTTON_PIN)) {
digitalWrite(BLUE_LED_PIN, HIGH);
Serial.write("\n\rBlue button pressed");
//play tone
tone(BUZZER_PIN, BLUE_TONE, 500);
} else {
digitalWrite(BLUE_LED_PIN, LOW);
}
//read green button input
if (!digitalRead(GREEN_BUTTON_PIN)) {
digitalWrite(GREEN_LED_PIN, HIGH);
Serial.write("\n\rGreen button pressed");
//play tone
tone(BUZZER_PIN, GREEN_TONE, 500);
} else {
digitalWrite(GREEN_LED_PIN, LOW);
}
//read red button input
if (!digitalRead(RED_BUTTON_PIN)) {
digitalWrite(RED_LED_PIN, HIGH);
Serial.write("\n\rRed button pressed");
//play tone
tone(BUZZER_PIN, RED_TONE, 500);
} else {
digitalWrite(RED_LED_PIN, LOW);
}
//read yellow button input
if (!digitalRead(YELLOW_BUTTON_PIN)) {
digitalWrite(YELLOW_LED_PIN, HIGH);
Serial.write("\n\rYellow button pressed");
//play tone
tone(BUZZER_PIN, YELLOW_TONE, 500);
} else {
digitalWrite(YELLOW_LED_PIN, LOW);
}
}