whipplashes
Published © GPL3+

RGB LED with 3 function dipswitch

This is an RGB LED that allows any input from 0-255 and is controlled with a dipswitch.

BeginnerShowcase (no instructions)336
RGB LED with 3 function dipswitch

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
Resistor 221 ohm
Resistor 221 ohm
×6
Jumper wires (generic)
Jumper wires (generic)
×1
3 position dip switch
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

screenshot_(193)_4COkQXiRyo.png

Code

4 prong LED with dip swtich

Arduino
//Whipplashes
//Code orginally taken from inventr.io and modified to fit the needs of this project
//4-21-22
 
int red = 11;  //output
int green = 10;
int blue = 9;

int Switch1 = 2;  //Input 
int Switch2 = 3;
int Switch3 = 4;
 
void setup() {
// Setup pins 
 
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(Switch1, INPUT);
  pinMode(Switch2, INPUT);
  pinMode(Switch3, INPUT);
}
 
void RGB_color(int red_value, int green_value, int blue_value)
{
// RBG function to pass on color values 
 
  analogWrite(red, red_value);
  analogWrite(green, green_value);
  analogWrite(blue, blue_value);
}
 
 
 
void loop() { //Various if and if else statments designed to trigger once only when the corresponding values on the breadboard are selected. 

  if (digitalRead(Switch1) == HIGH && digitalRead(Switch2) != HIGH && digitalRead(Switch3) != HIGH) 
  
  {
  RGB_color(125, 0, 0); // Red
  delay(800);
  RGB_color(0, 125, 0); // Green
  delay(800);
   
  }
  else if (digitalRead(Switch2) == HIGH && digitalRead(Switch1) != HIGH && digitalRead(Switch3) != HIGH) 
  {
  RGB_color(0, 0, 125); // Blue
  delay(800);
  RGB_color(64, 32, 0); // yellow
  delay(800);
  }
  else if (digitalRead(Switch3) == HIGH && digitalRead(Switch2) != HIGH && digitalRead(Switch1) != HIGH) 
  {
  RGB_color(125, 0, 125); // purple
  delay(800);
  RGB_color(125, 125, 125); // white
  delay(800);
  }
  else if (digitalRead(Switch1) == HIGH && digitalRead(Switch2) == HIGH  && digitalRead(Switch3) != HIGH)
  {
   RGB_color(125, 0, 0); // Red
  delay(800);
  RGB_color(0, 125, 0); // Green
  delay(800);
  RGB_color(0, 0, 125); // Blue
  delay(800);
  RGB_color(64, 32, 0); // yellow
  delay(800);
  
  }
  else if (digitalRead(Switch1) == HIGH && digitalRead(Switch3) == HIGH  && digitalRead(Switch2) != HIGH)
  {
     RGB_color(125, 0, 0); // Red
  delay(800);
  RGB_color(0, 125, 0); // Green
  delay(800); 
  RGB_color(125, 0, 125); // purple
  delay(800);
  RGB_color(125, 125, 125); // white
  delay(800);
  }
  else if  (digitalRead(Switch2) == HIGH && digitalRead(Switch3) == HIGH  && digitalRead(Switch1) != HIGH)
  {
     RGB_color(0, 0, 125); // Blue
  delay(800);
  RGB_color(64, 32, 0); // yellow
  delay(800);
   RGB_color(125, 0, 125); // purple
  delay(800);
  RGB_color(125, 125, 125); // white
  delay(800);
  
  }
  else if  (digitalRead(Switch2) == HIGH && digitalRead(Switch3) == HIGH  && digitalRead(Switch1) == HIGH)
  {
    RGB_color(125, 0, 0); // Red
  delay(800);
  RGB_color(0, 125, 0); // Green
  delay(800);
  RGB_color(0, 0, 125); // Blue
  delay(800);
  RGB_color(64, 32, 0); // yellow
  delay(800);
  RGB_color(125, 0, 125); // purple
  delay(800);
  RGB_color(125, 125, 125); // white
  delay(800);
  }
 else if (digitalRead(Switch2) != HIGH && digitalRead(Switch3) != HIGH  && digitalRead(Switch1) != HIGH)
 {
  RGB_color(0,0,0); 
  delay(500);
 }
  
}

Credits

whipplashes
0 projects • 0 followers

Comments