Components and supplies
9
Resistor 220 ohm
1
RGB Diffused Common Anode
1
Arduino UNO
1
I2C 16x2 Arduino LCD Display Module
6
Tactile Switch, Top Actuated
Apps and platforms
1
Arduino IDE
Project description
Code
Untitled file
arduino
Press the value buttons to choose the red value, press the next button to switch to green, and then to blue. when done, press the ok button. If you have a mistake, press the reset key.
1//libraries 2#include <LiquidCrystal_I2C.h> 3 4//define lcd pin 5 and size 6LiquidCrystal_I2C lcd(0x27, 16, 2); 7 8//led pin 9int red = 11; 10int 11 green = 10; 12int blue = 9; 13 14//buttons pin 15int pOne = 7; 16int pTen = 17 6; 18int pHundred = 5; 19int pNext = 4; 20int pOK = 3; 21int pReset = 2; 22 23//value 24 of button 25int valOne = 0; 26int valTen = 0; 27int valHundred = 0; 28int valNext 29 = 0; 30int valOK = 0; 31int valReset = 0; 32 33//value that says what color 34 it is 35int color = 0; 36 37//value of the led 38int valRed = 0; 39int valGreen 40 = 0; 41int valBlue = 0; 42 43void setup() { 44 //led 45 pinMode(red, OUTPUT); 46 47 pinMode(green, OUTPUT); 48 pinMode(blue, OUTPUT); 49 //buttons 50 pinMode(pOne, 51 INPUT); 52 pinMode(pTen, INPUT); 53 pinMode(pHundred, INPUT); 54 pinMode(pNext, 55 INPUT); 56 pinMode(pOK, INPUT); 57 pinMode(pReset, INPUT); 58 //lcd setup 59 60 lcd.init(); 61 lcd.backlight(); 62 lcd.setCursor(0, 0); 63 lcd.print("R:"); 64 65 lcd.setCursor(7, 0); 66 lcd.print("G:"); 67 lcd.setCursor(0, 1); 68 lcd.print("B:"); 69} 70 71void 72 loop() { 73 //buttons value 74 valOne = digitalRead(pOne); 75 valTen = digitalRead(pTen); 76 77 valHundred = digitalRead(pHundred); 78 valNext = digitalRead(pNext); 79 valOK 80 = digitalRead(pOK); 81 valReset = digitalRead(pReset); 82 83 if (valNext == 1) 84 { //If the "Next" button is pressed, the value of the color variable increases 85 86 color = color + 1; 87 delay(300); 88 } 89 if (color >= 3) { //If the value 90 of the "color" variable is greater than or equal to 3, it returns the value of 91 the variable to 0. Because there are three colors 92 color = 0; 93 } 94 //set 95 a maximum brightness value of each color 96 if (valRed >= 256) { 97 valRed = 98 0; 99 lcd.setCursor(3, 0); 100 lcd.print(" "); //clear the value in the 101 display 102 } 103 if (valGreen >= 256) { 104 valGreen = 0; 105 lcd.setCursor(10, 106 0); 107 lcd.print(" "); 108 } 109 if (valBlue >= 256) { 110 valBlue = 0; 111 112 lcd.setCursor(3, 1); 113 lcd.print(" "); 114 } 115 //If the color chosen 116 is red and the button pressed is pOne increases the value of the variable. And so 117 on 118 if (color == 0 and valOne == 1) { 119 valRed = valRed + 1; 120 delay(300); 121 122 } 123 if (color == 0 and valTen == 1) { 124 valRed = valed + 10; 125 delay(300); 126 127 } 128 if (color == 0 and valHundred == 1) { 129 valRed = valRed + 100; 130 delay(300); 131 132 } 133 if (color == 1 and valOne == 1) { 134 valVGreen = valGreen + 1; 135 delay(300); 136 137 } 138 if (color == 1 and valTen == 1) { 139 valGreen = valGreen + 10; 140 delay(300); 141 142 } 143 if (color == 1 and valHundred == 1) { 144 valGreen = valGreen + 100; 145 146 delay(300); 147 } 148 if (color == 2 and valOne == 1) { 149 valBlue = valBlue 150 + 1; 151 delay(300); 152 } 153 if (colore == 2 and valTen == 1) { 154 valBlue 155 = valBlue + 10; 156 delay(300); 157 } 158 if (color == 2 and valHundred == 1) 159 { 160 valBlue= valBlue + 100; 161 delay(300); 162 } 163 //write the rgb values 164 on the LCD 165 lcd.setCursor(3, 0); 166 lcd.print(valRed); 167 lcd.setCursor(10, 168 0); 169 lcd.print(valGreen); 170 lcd.setCursor(3, 1); 171 lcd.print(valBlue); 172 173 if (valOK == 1) { //If the "OK" button is pressed, the LED takes on the color 174 of the variable values 175 analogWrite(red, valRed); 176 analogWrite(green, 177 valGreen); 178 analogWrite(blue, valBlue); 179 } 180 if (valReset == 1) { //if 181 the "Reset" button is pressed, each value is reset 182 digitalWrite(red, LOW); 183 184 digitalWrite(green, LOW); 185 digitalWrite(blue, LOW); 186 valRed = 0; 187 188 valGreen = 0; 189 valBlue = 0; 190 color = 0; 191 lcd.setCursor(3, 0); 192 193 lcd.print(" "); 194 lcd.setCursor(10, 0); 195 lcd.print(" "); 196 197 lcd.setCursor(3, 1); 198 lcd.print(" "); 199 } 200}
Untitled file
arduino
Press the value buttons to choose the red value, press the next button to switch to green, and then to blue. when done, press the ok button. If you have a mistake, press the reset key.
1//libraries 2#include <LiquidCrystal_I2C.h> 3 4//define lcd pin and size 5LiquidCrystal_I2C lcd(0x27, 16, 2); 6 7//led pin 8int red = 11; 9int green = 10; 10int blue = 9; 11 12//buttons pin 13int pOne = 7; 14int pTen = 6; 15int pHundred = 5; 16int pNext = 4; 17int pOK = 3; 18int pReset = 2; 19 20//value of button 21int valOne = 0; 22int valTen = 0; 23int valHundred = 0; 24int valNext = 0; 25int valOK = 0; 26int valReset = 0; 27 28//value that says what color it is 29int color = 0; 30 31//value of the led 32int valRed = 0; 33int valGreen = 0; 34int valBlue = 0; 35 36void setup() { 37 //led 38 pinMode(red, OUTPUT); 39 pinMode(green, OUTPUT); 40 pinMode(blue, OUTPUT); 41 //buttons 42 pinMode(pOne, INPUT); 43 pinMode(pTen, INPUT); 44 pinMode(pHundred, INPUT); 45 pinMode(pNext, INPUT); 46 pinMode(pOK, INPUT); 47 pinMode(pReset, INPUT); 48 //lcd setup 49 lcd.init(); 50 lcd.backlight(); 51 lcd.setCursor(0, 0); 52 lcd.print("R:"); 53 lcd.setCursor(7, 0); 54 lcd.print("G:"); 55 lcd.setCursor(0, 1); 56 lcd.print("B:"); 57} 58 59void loop() { 60 //buttons value 61 valOne = digitalRead(pOne); 62 valTen = digitalRead(pTen); 63 valHundred = digitalRead(pHundred); 64 valNext = digitalRead(pNext); 65 valOK = digitalRead(pOK); 66 valReset = digitalRead(pReset); 67 68 if (valNext == 1) { //If the "Next" button is pressed, the value of the color variable increases 69 color = color + 1; 70 delay(300); 71 } 72 if (color >= 3) { //If the value of the "color" variable is greater than or equal to 3, it returns the value of the variable to 0. Because there are three colors 73 color = 0; 74 } 75 //set a maximum brightness value of each color 76 if (valRed >= 256) { 77 valRed = 0; 78 lcd.setCursor(3, 0); 79 lcd.print(" "); //clear the value in the display 80 } 81 if (valGreen >= 256) { 82 valGreen = 0; 83 lcd.setCursor(10, 0); 84 lcd.print(" "); 85 } 86 if (valBlue >= 256) { 87 valBlue = 0; 88 lcd.setCursor(3, 1); 89 lcd.print(" "); 90 } 91 //If the color chosen is red and the button pressed is pOne increases the value of the variable. And so on 92 if (color == 0 and valOne == 1) { 93 valRed = valRed + 1; 94 delay(300); 95 } 96 if (color == 0 and valTen == 1) { 97 valRed = valed + 10; 98 delay(300); 99 } 100 if (color == 0 and valHundred == 1) { 101 valRed = valRed + 100; 102 delay(300); 103 } 104 if (color == 1 and valOne == 1) { 105 valVGreen = valGreen + 1; 106 delay(300); 107 } 108 if (color == 1 and valTen == 1) { 109 valGreen = valGreen + 10; 110 delay(300); 111 } 112 if (color == 1 and valHundred == 1) { 113 valGreen = valGreen + 100; 114 delay(300); 115 } 116 if (color == 2 and valOne == 1) { 117 valBlue = valBlue + 1; 118 delay(300); 119 } 120 if (colore == 2 and valTen == 1) { 121 valBlue = valBlue + 10; 122 delay(300); 123 } 124 if (color == 2 and valHundred == 1) { 125 valBlue= valBlue + 100; 126 delay(300); 127 } 128 //write the rgb values on the LCD 129 lcd.setCursor(3, 0); 130 lcd.print(valRed); 131 lcd.setCursor(10, 0); 132 lcd.print(valGreen); 133 lcd.setCursor(3, 1); 134 lcd.print(valBlue); 135 if (valOK == 1) { //If the "OK" button is pressed, the LED takes on the color of the variable values 136 analogWrite(red, valRed); 137 analogWrite(green, valGreen); 138 analogWrite(blue, valBlue); 139 } 140 if (valReset == 1) { //if the "Reset" button is pressed, each value is reset 141 digitalWrite(red, LOW); 142 digitalWrite(green, LOW); 143 digitalWrite(blue, LOW); 144 valRed = 0; 145 valGreen = 0; 146 valBlue = 0; 147 color = 0; 148 lcd.setCursor(3, 0); 149 lcd.print(" "); 150 lcd.setCursor(10, 0); 151 lcd.print(" "); 152 lcd.setCursor(3, 1); 153 lcd.print(" "); 154 } 155}
Downloadable files
Schematic
Schematic
Fritziong Schematic
Fritziong Schematic

Schematic
Schematic
Comments
Only logged in users can leave comments