const int push_green=5; // use pin 5 for green's push button const int push_red=6; // use pin 6 for red's push button const int push_blue=7; // use pin 7 for blue's push button const int led_green=2; // use pin 2 for green LED's cathode const int led_red=3; // use pin 3 for red LED's cathode const int led_blue=4; // use pin 4 for blue LED's cthode int status_green=0; // to store the value of the push button input green int status_red=0; // to store the value of the push button input of red int status_blue=0; // to store the value of the push button input green const int gnd_pin=13; // use pin 13 as extra ground by pulling it LOW (Optional, if not needed can use the common ground) void setup() { // put your setup code here, to run once: pinMode(push_green, INPUT); // Initializing the pinMode(push_red, INPUT); // digital pins as Inputs pinMode(push_blue, INPUT); // as well as outputs so that it pinMode(led_green, OUTPUT); // gets input from PIN 5,6,7 and pinMode(led_red, OUTPUT); // Pulls PIN 2,3,4 to ground accordingly pinMode(led_blue, OUTPUT); // by pulling to ground the cathode completes the circuit and forms pinMode(gnd_pin, OUTPUT); // a closed loop which allows current to flow through it and lights up the LED Serial.begin(9600); // To begin the serial communication protocol } void loop() { clean(); // function call status_green=digitalRead(push_green); // gets input from push button and saves in status_para status_red=digitalRead(push_red); // when push button is not engaged the status_blue=digitalRead(push_blue); // digital pins receives +5 volts but when pushed the +5V drops to 0 digitalWrite(gnd_pin, LOW); // pulling PIN 13 to LOW to make it as an additional ground terminal if(status_green==0) // if then pull particular digital pin to LOW to make it a closed circuit and makes the LED light up { clean(); digitalWrite(led_green, LOW); Serial.print("Green"); Serial.print("\n"); } else if(status_red==0) { clean(); digitalWrite(led_red, LOW); Serial.print("Red"); Serial.print("\n"); } else if(status_blue==0) { clean(); digitalWrite(led_blue, LOW); Serial.print("Blue"); Serial.print("\n"); } if(status_green==0 && status_red==0) { clean(); digitalWrite(led_green, LOW); digitalWrite(led_red, LOW); Serial.print("Orange"); Serial.print("\n"); } if(status_green==0 && status_blue==0) { clean(); digitalWrite(led_green, LOW); digitalWrite(led_blue, LOW); Serial.print("sky blue"); Serial.print("\n"); } if(status_red==0 && status_blue==0) { clean(); digitalWrite(led_red, LOW); digitalWrite(led_blue, LOW); Serial.print("Violet"); Serial.print("\n"); } if(status_red==0 && status_green==0 && status_blue==0) { clean(); digitalWrite(led_red, LOW); digitalWrite(led_green, LOW); digitalWrite(led_blue, LOW); Serial.print("White"); Serial.print("\n"); } delay(100); } void clean(){ // additional function to make the digital pins 2,3,4 to HIGH to turn all the LED off if the push button is not engaged digitalWrite(led_green, HIGH); digitalWrite(led_red, HIGH); digitalWrite(led_blue, HIGH); }