Components and supplies
I2C OLED display
Rotary potentiometer (generic)
Arduino Nano R3
8x8 WS2812 LED matrix
Project description
Code
Setting all 64 led of the matrix to a color selected using RGB color model
arduino
1#include <Wire.h> 2#include <Adafruit_GFX.h> 3#include <Adafruit_SSD1306.h> 4#include <FastLED.h> 5 6int Red; 7int Green; 8int Blue; 9 10#define SCREEN_WIDTH 128 // OLED display width, in pixels 11#define SCREEN_HEIGHT 64 // OLED display height, in pixels 12 13#define OLED_RESET -1// Reset pin # (or -1 if sharing Arduino reset pin) 14Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 15 16 17#define NUM_LEDS 64 18#define DATA_PIN 13 19CRGB leds[NUM_LEDS]; 20 21 22void setup() { 23 24 FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS); 25 FastLED.setBrightness(5); 26 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 27 Serial.println(F("SSD1306 allocation failed")); 28 for(;;); // Don't proceed, loop forever 29 } 30 31 display.display(); 32 delay(2000); 33 display.clearDisplay(); 34 display.display(); 35 36 display.fillRect(0,0,63,16,SSD1306_WHITE); 37 display.fillRect(65,0,63,16,SSD1306_WHITE); 38 display.setTextSize(2); 39 display.setTextColor(SSD1306_BLACK); 40 display.setCursor(15,1); 41 display.println("RGB"); 42 display.setCursor(80,1); 43 display.println("HSV"); 44 display.fillRect(0,15,63,16,SSD1306_WHITE); 45 display.fillRect(0,32,63,16,SSD1306_WHITE); 46 display.fillRect(0,49,63,16,SSD1306_WHITE); 47 display.setCursor(5,17); 48 display.println("R:"); 49 display.setCursor(5,33); 50 display.println("G:"); 51 display.setCursor(5,50); 52 display.println("B:"); 53 54 55 display.display(); 56 57} 58 59void loop() { 60 //reading the composite color values from the 3 potentiometers 61 Red= map(analogRead(A2),0,1023,0,275 ); 62 Green= map(analogRead(A1),0,1023,0,275 ); 63 Blue= map(analogRead(A0),0,1023,0,275 ); 64 //displaying read values on OLED display 65 display.fillRect(0,15,63,16,SSD1306_WHITE); 66 display.fillRect(0,32,63,16,SSD1306_WHITE); 67 display.fillRect(0,49,63,16,SSD1306_WHITE); 68 display.setCursor(5,17); 69 display.print("R:"); 70 display.print(Red); 71 display.setCursor(5,33); 72 display.print("G:"); 73 display.print(Green); 74 display.setCursor(5,50); 75 display.print("B:"); 76 display.print(Blue); 77 display.display(); 78 // setting all 64 led to the color made of selected R G B values 79 for (int i=0;i<64;i++) { 80 leds[i]=CRGB(Red,Green,Blue); 81 } 82 // redisplaing all leds 83 FastLED.show(); 84}
Setting one half of the matrix to the RGB color and the other half to HSV color
arduino
RGB color is selected with 3 potentiometers HSV color is selected with 1 potentiometer
1#include <Wire.h> 2#include <Adafruit_GFX.h> 3#include <Adafruit_SSD1306.h> 4#include <FastLED.h> 5 6int Red; 7int Green; 8int Blue; 9int C_HSV; 10 11#define SCREEN_WIDTH 128 // OLED display width, in pixels 12#define SCREEN_HEIGHT 64 // OLED display height, in pixels 13 14#define OLED_RESET -1// Reset pin # (or -1 if sharing Arduino reset pin) 15Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 16 17 18uint16_t Colors [27]{0x7FFF00,0x6495ED,0xDC143,0x00008B,0x8B008B, 19 0xFF8C00,0x00CED1,0x9400D3,0xFF1493,0x228B22, 20 0xFFD700,0xADFF2F,0x7CFC00,0x87CEFA,0x00FF00, 21 0xFF00FF,0x0000CD,0xFFA500,0x9ACD32,0xFFE4C4, 22 0x00FFFF,0x008B8B,0xE9967A,0xFFFACD,0xADD8E6, 23 0xFAFAD2,0xFFEFD5}; 24 25 26#define NUM_LEDS 64 27#define DATA_PIN 13 28CRGB leds[NUM_LEDS]; 29 30 31void setup() { 32 33 FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS); 34 FastLED.setBrightness(5); 35 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 36 Serial.println(F("SSD1306 allocation failed")); 37 for(;;); // Don't proceed, loop forever 38 } 39 40 display.display(); 41 delay(2000); 42 display.clearDisplay(); 43 display.display(); 44 45 display.fillRect(0,0,63,16,SSD1306_WHITE); 46 display.fillRect(65,0,63,16,SSD1306_WHITE); 47 display.setTextSize(2); 48 display.setTextColor(SSD1306_BLACK); 49 display.setCursor(15,1); 50 display.println("RGB"); 51 display.setCursor(80,1); 52 display.println("HSV"); 53 display.fillRect(0,15,63,16,SSD1306_WHITE); 54 display.fillRect(0,32,63,16,SSD1306_WHITE); 55 display.fillRect(0,49,63,16,SSD1306_WHITE); 56 display.setCursor(5,17); 57 display.println("R:"); 58 display.setCursor(5,33); 59 display.println("G:"); 60 display.setCursor(5,50); 61 display.println("B:"); 62 display.fillRect(80,15,63,16,SSD1306_WHITE); 63 display.setCursor(95,17); 64 display.println("Hue:"); 65 66 67 display.display(); 68 69} 70 71void loop() { 72// reading RGB composite color values from 3 potentiometers 73 Red= map(analogRead(A2),0,1023,0,260 ); 74 Green= map(analogRead(A1),0,1023,0,260 ); 75 Blue= map(analogRead(A0),0,1023,0,260 ); 76// reading HSV color value from the potentiometer 77 C_HSV= map(analogRead(A3),0,1023,0,260 ); 78// Displaying selected RGB and HSV color values on oled display 79 display.fillRect(0,15,63,16,SSD1306_WHITE); 80 display.fillRect(0,32,63,16,SSD1306_WHITE); 81 display.fillRect(0,49,63,16,SSD1306_WHITE); 82 display.setCursor(5,17); 83 display.print("R:"); 84 display.print(Red); 85 display.setCursor(5,33); 86 display.print("G:"); 87 display.print(Green); 88 display.setCursor(5,50); 89 display.print("B:"); 90 display.print(Blue); 91 display.fillRect(65,15,63,16,SSD1306_WHITE); 92 display.setCursor(67,17); 93 display.print("H:"); 94 display.print(C_HSV); 95 display.display(); 96 // Setting LEDs in first 4 columns to selected RGB color 97 // Setting leds in columns 5-8 to selected HSV color 98 for (int i=0;i<8;i++) { 99 //leds[i]=CRGB(Red,Green,Blue); 100 leds[8*i+5]=CRGB(Red,Green,Blue); 101 leds[8*i+6]=CRGB(Red,Green,Blue); 102 leds[8*i+7]=CRGB(Red,Green,Blue); 103 leds[8*i]=CHSV( C_HSV, 255, 255); 104 leds[8*i+1]=CHSV( C_HSV, 255, 255); 105 leds[8*i+2]=CHSV( C_HSV, 255, 255); 106 } 107// Redisplaying all leds 108 FastLED.show(); 109 110 111}
Setting one half of the matrix to the RGB color and the other half to HSV color
arduino
RGB color is selected with 3 potentiometers HSV color is selected with 1 potentiometer
1#include <Wire.h> 2#include <Adafruit_GFX.h> 3#include <Adafruit_SSD1306.h> 4#include <FastLED.h> 5 6int Red; 7int Green; 8int Blue; 9int C_HSV; 10 11#define SCREEN_WIDTH 128 // OLED display width, in pixels 12#define SCREEN_HEIGHT 64 // OLED display height, in pixels 13 14#define OLED_RESET -1// Reset pin # (or -1 if sharing Arduino reset pin) 15Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 16 17 18uint16_t Colors [27]{0x7FFF00,0x6495ED,0xDC143,0x00008B,0x8B008B, 19 0xFF8C00,0x00CED1,0x9400D3,0xFF1493,0x228B22, 20 0xFFD700,0xADFF2F,0x7CFC00,0x87CEFA,0x00FF00, 21 0xFF00FF,0x0000CD,0xFFA500,0x9ACD32,0xFFE4C4, 22 0x00FFFF,0x008B8B,0xE9967A,0xFFFACD,0xADD8E6, 23 0xFAFAD2,0xFFEFD5}; 24 25 26#define NUM_LEDS 64 27#define DATA_PIN 13 28CRGB leds[NUM_LEDS]; 29 30 31void setup() { 32 33 FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS); 34 FastLED.setBrightness(5); 35 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 36 Serial.println(F("SSD1306 allocation failed")); 37 for(;;); // Don't proceed, loop forever 38 } 39 40 display.display(); 41 delay(2000); 42 display.clearDisplay(); 43 display.display(); 44 45 display.fillRect(0,0,63,16,SSD1306_WHITE); 46 display.fillRect(65,0,63,16,SSD1306_WHITE); 47 display.setTextSize(2); 48 display.setTextColor(SSD1306_BLACK); 49 display.setCursor(15,1); 50 display.println("RGB"); 51 display.setCursor(80,1); 52 display.println("HSV"); 53 display.fillRect(0,15,63,16,SSD1306_WHITE); 54 display.fillRect(0,32,63,16,SSD1306_WHITE); 55 display.fillRect(0,49,63,16,SSD1306_WHITE); 56 display.setCursor(5,17); 57 display.println("R:"); 58 display.setCursor(5,33); 59 display.println("G:"); 60 display.setCursor(5,50); 61 display.println("B:"); 62 display.fillRect(80,15,63,16,SSD1306_WHITE); 63 display.setCursor(95,17); 64 display.println("Hue:"); 65 66 67 display.display(); 68 69} 70 71void loop() { 72// reading RGB composite color values from 3 potentiometers 73 Red= map(analogRead(A2),0,1023,0,260 ); 74 Green= map(analogRead(A1),0,1023,0,260 ); 75 Blue= map(analogRead(A0),0,1023,0,260 ); 76// reading HSV color value from the potentiometer 77 C_HSV= map(analogRead(A3),0,1023,0,260 ); 78// Displaying selected RGB and HSV color values on oled display 79 display.fillRect(0,15,63,16,SSD1306_WHITE); 80 display.fillRect(0,32,63,16,SSD1306_WHITE); 81 display.fillRect(0,49,63,16,SSD1306_WHITE); 82 display.setCursor(5,17); 83 display.print("R:"); 84 display.print(Red); 85 display.setCursor(5,33); 86 display.print("G:"); 87 display.print(Green); 88 display.setCursor(5,50); 89 display.print("B:"); 90 display.print(Blue); 91 display.fillRect(65,15,63,16,SSD1306_WHITE); 92 display.setCursor(67,17); 93 display.print("H:"); 94 display.print(C_HSV); 95 display.display(); 96 // Setting LEDs in first 4 columns to selected RGB color 97 // Setting leds in columns 5-8 to selected HSV color 98 for (int i=0;i<8;i++) { 99 //leds[i]=CRGB(Red,Green,Blue); 100 leds[8*i+5]=CRGB(Red,Green,Blue); 101 leds[8*i+6]=CRGB(Red,Green,Blue); 102 leds[8*i+7]=CRGB(Red,Green,Blue); 103 leds[8*i]=CHSV( C_HSV, 255, 255); 104 leds[8*i+1]=CHSV( C_HSV, 255, 255); 105 leds[8*i+2]=CHSV( C_HSV, 255, 255); 106 } 107// Redisplaying all leds 108 FastLED.show(); 109 110 111}
Setting all 64 led of the matrix to a color selected using RGB color model
arduino
1#include <Wire.h> 2#include <Adafruit_GFX.h> 3#include <Adafruit_SSD1306.h> 4#include 5 <FastLED.h> 6 7int Red; 8int Green; 9int Blue; 10 11#define SCREEN_WIDTH 12 128 // OLED display width, in pixels 13#define SCREEN_HEIGHT 64 // OLED display 14 height, in pixels 15 16#define OLED_RESET -1// Reset pin # (or -1 if sharing 17 Arduino reset pin) 18Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, 19 OLED_RESET); 20 21 22#define NUM_LEDS 64 23#define DATA_PIN 13 24CRGB leds[NUM_LEDS]; 25 26 27void 28 setup() { 29 30 FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS); 31 FastLED.setBrightness(5); 32 33 if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 34 35 Serial.println(F("SSD1306 allocation failed")); 36 for(;;); // Don't proceed, 37 loop forever 38 } 39 40 display.display(); 41 delay(2000); 42 display.clearDisplay(); 43 44 display.display(); 45 46 display.fillRect(0,0,63,16,SSD1306_WHITE); 47 display.fillRect(65,0,63,16,SSD1306_WHITE); 48 49 display.setTextSize(2); 50 display.setTextColor(SSD1306_BLACK); 51 display.setCursor(15,1); 52 53 display.println("RGB"); 54 display.setCursor(80,1); 55 display.println("HSV"); 56 57 display.fillRect(0,15,63,16,SSD1306_WHITE); 58 display.fillRect(0,32,63,16,SSD1306_WHITE); 59 60 display.fillRect(0,49,63,16,SSD1306_WHITE); 61 display.setCursor(5,17); 62 63 display.println("R:"); 64 display.setCursor(5,33); 65 display.println("G:"); 66 67 display.setCursor(5,50); 68 display.println("B:"); 69 70 71 display.display(); 72 73 74} 75 76void loop() { 77 //reading the composite color values from the 78 3 potentiometers 79 Red= map(analogRead(A2),0,1023,0,275 ); 80 Green= map(analogRead(A1),0,1023,0,275 81 ); 82 Blue= map(analogRead(A0),0,1023,0,275 ); 83 //displaying read values 84 on OLED display 85 display.fillRect(0,15,63,16,SSD1306_WHITE); 86 display.fillRect(0,32,63,16,SSD1306_WHITE); 87 88 display.fillRect(0,49,63,16,SSD1306_WHITE); 89 display.setCursor(5,17); 90 91 display.print("R:"); 92 display.print(Red); 93 display.setCursor(5,33); 94 95 display.print("G:"); 96 display.print(Green); 97 display.setCursor(5,50); 98 99 display.print("B:"); 100 display.print(Blue); 101 display.display(); 102 // 103 setting all 64 led to the color made of selected R G B values 104 for (int i=0;i<64;i++) 105 { 106 leds[i]=CRGB(Red,Green,Blue); 107 } 108 // redisplaing all leds 109 110 FastLED.show(); 111}
Downloadable files
Conenctivity for LED coror selection device
Conenctivity for LED coror selection device

Comments
Only logged in users can leave comments