Components and supplies
18
Jumper wires (generic)
1
Arduino UNO
1
Analog joystick (Generic)
1
Buttons (Optional)
1
Custom PCB
1
128x32 pixel OLED
1
Adafruit Neopixel RGB
1
Solderless Breadboard Full Size
1
Wire (Optional)
Tools and machines
1
Soldering iron (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
LEDstrip
arduino
1#include <Adafruit_NeoPixel.h> 2#define LED_PIN 6 3#define LED_COUNT 30 4Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); 5#define joyX A2 6#define joyY A1 7#include "U8glib.h" 8 9U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); //Initialize OLED display 10 11 12int r = 0; 13 14int g = 0; 15 16int b = 0;//These three variables determine RGB values 17 18int num = 1; //This variable helps switch between colors. 19 20const int swpin = 5; //Defining switch button pin 21 22int SW = 0; 23 24void draw() 25{ 26//READINGS------------------------------------------------------------------- 27 int X; 28 int Y; 29 int Xval; 30 int Yval; 31 32 33 34 X = analogRead(joyX); //Reading off of VRx 35 Y = analogRead(joyY); //Reading off of VRy 36 37 Xval = map(X, 0, 1023, 10, 0); 38 Yval = map(Y, 0, 1023, 255, 0); //mapping values 39 40//COLOR SWITCHING------------------------------------------------------------- 41 if(Xval < 9){ //This bit of code helps us switch between R, G and B. 42 num = num + 1; 43 } 44 if(Xval > 1){ 45 num = num - 1; 46 } 47 48//LIMITS------------------------------------------------------------------- 49 if(num > 3){ //This bit creates a cycle between colors 50 num = 1; 51 } 52 if(num < 1){ 53 num = 3; 54 } 55 56 57//Red-value------------------------------------------------------------------------------------------------------- 58char buf[8]; //Define buffer 59 60if(r < 0){ 61 r = 255; 62} 63 //Cycles red value 64 if(r > 255){ 65 r = 0; 66 } 67 68//Write text. (x, y, text) 69u8g.drawStr(1, 16, "R-"); 70u8g.drawStr(20, 16, itoa(r, buf, 10)); //itoa(int1, buffer, int2) converts int1(base int2) to ASCII format. Buffer stores this data. 71 72//Green-value----------------------------------------------------------------------------------------------------- 73 74 75if(g < 0){ 76 g = 255; 77} 78 //Cycles green value 79 if(g > 255){ 80 g = 0; 81 } 82 83 84u8g.drawStr(64, 16, "G-"); 85u8g.drawStr(84, 16, itoa(g, buf, 10)); 86 87//Blue-value------------------------------------------------------------------------------------------------------ 88 89 90if(b < 0){ 91 b = 255; 92} 93 //Cycles blue value 94if (b > 255){ 95 b = 0; 96} 97 98u8g.drawStr(1, 32, "B-"); 99u8g.drawStr(20, 32, itoa(b, buf, 10)); 100 101//LINE (x1, y1, x2, y2)------------------------------------------------------------------------------------------- 102u8g.drawLine(1, 17, 128, 17); 103//draw a line (x1, y1, x2, y2) 104 105//SET COLOR------------------------------------------------------------------------------------------------------------ 106u8g.drawStr(64, 32, "Color-"); 107 108 switch(num) { 109 /*This function only converts the num values to R, G and B strings according to the current color being edited. 110 This code makes sure that when editing value intensity, the 'Color' field actually switches to the correct color(R, G or B).*/ 111 112 case 1 : 113 u8g.drawStr(115, 32, "R"); 114 if(Yval > 230){ 115 r = r+1; 116 } 117 118 if(Yval < 20){ 119 r = r-1; 120 } 121 break; 122 123 case 2 : 124 u8g.drawStr(115, 32, "G"); 125 if(Yval > 230){ 126 g = g+1; 127 } 128 129 if(Yval < 20){ 130 g = g-1; 131 } 132 break; 133 134 case 3 : 135 u8g.drawStr(115, 32, "B"); 136 if(Yval > 230){ 137 b = b+1; 138 } 139 140 if(Yval < 20){ 141 b = b-1; 142 } 143 break; 144 } 145} 146 147void setup() { 148 u8g.setFont(u8g_font_unifont); //Set text font 149 pinMode(swpin, INPUT_PULLUP); //Define the pin mode for the switch button 150 strip.begin(); //Initiate LED strip 151 strip.show(); //Update Strip 152 strip.setBrightness(50); //Set the brightness of each NeoPixel 153} 154 155 156void loop() { 157 u8g.firstPage(); 158 do {draw(); 159 } while (u8g.nextPage()); //Draw loop (OLED) 160 delay(10); //Delay before each loop begins 161 if(SW < 1){ //Ensures that the strip stays on at all times; you can use the int SW and link it to input swpin to assign to it a different function. 162 colorWipe(strip.Color(r, g, b), 5);//The variables r g and b are linked to the values you will see on the OLED. The number '5' defines the number of seconds it takes to fill up the entire strip (Neopixels turn on one at a time in this function). 163 } 164 165} 166void colorWipe(uint32_t color, int wait) { //Defining a new function to display the color. 167 for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip: 168 strip.setPixelColor(i, color); // Set pixel's color 169 strip.show(); // Update strip to match 170 delay(wait); // Pause for a moment 171 } 172 } 173 174
Downloadable files
Schematic Diagram
Schematic Diagram

Schematic Diagram
Schematic Diagram

Comments
Only logged in users can leave comments