Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 4 | |||
| × | 1 | ||||
| × | 1 |
In this video I provide few tipes for working with individually addresable leds like ws2812. I would use Arduino with fastled library.I will compare the use of RGB and HSV color models.I hope you would find it useful
If you like this content and you want to support me in creating similar videos go to my Patreon webpage
https://www.patreon.com/MariosIdeas
Or Paypal
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7PD67JWZ9S3EJ&source=url
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <FastLED.h>
int Red;
int Green;
int Blue;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1// Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUM_LEDS 64
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS);
FastLED.setBrightness(5);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(2000);
display.clearDisplay();
display.display();
display.fillRect(0,0,63,16,SSD1306_WHITE);
display.fillRect(65,0,63,16,SSD1306_WHITE);
display.setTextSize(2);
display.setTextColor(SSD1306_BLACK);
display.setCursor(15,1);
display.println("RGB");
display.setCursor(80,1);
display.println("HSV");
display.fillRect(0,15,63,16,SSD1306_WHITE);
display.fillRect(0,32,63,16,SSD1306_WHITE);
display.fillRect(0,49,63,16,SSD1306_WHITE);
display.setCursor(5,17);
display.println("R:");
display.setCursor(5,33);
display.println("G:");
display.setCursor(5,50);
display.println("B:");
display.display();
}
void loop() {
//reading the composite color values from the 3 potentiometers
Red= map(analogRead(A2),0,1023,0,275 );
Green= map(analogRead(A1),0,1023,0,275 );
Blue= map(analogRead(A0),0,1023,0,275 );
//displaying read values on OLED display
display.fillRect(0,15,63,16,SSD1306_WHITE);
display.fillRect(0,32,63,16,SSD1306_WHITE);
display.fillRect(0,49,63,16,SSD1306_WHITE);
display.setCursor(5,17);
display.print("R:");
display.print(Red);
display.setCursor(5,33);
display.print("G:");
display.print(Green);
display.setCursor(5,50);
display.print("B:");
display.print(Blue);
display.display();
// setting all 64 led to the color made of selected R G B values
for (int i=0;i<64;i++) {
leds[i]=CRGB(Red,Green,Blue);
}
// redisplaing all leds
FastLED.show();
}
Setting one half of the matrix to the RGB color and the other half to HSV color
ArduinoRGB color is selected with 3 potentiometers
HSV color is selected with 1 potentiometer
HSV color is selected with 1 potentiometer
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <FastLED.h>
int Red;
int Green;
int Blue;
int C_HSV;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1// Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
uint16_t Colors [27]{0x7FFF00,0x6495ED,0xDC143,0x00008B,0x8B008B,
0xFF8C00,0x00CED1,0x9400D3,0xFF1493,0x228B22,
0xFFD700,0xADFF2F,0x7CFC00,0x87CEFA,0x00FF00,
0xFF00FF,0x0000CD,0xFFA500,0x9ACD32,0xFFE4C4,
0x00FFFF,0x008B8B,0xE9967A,0xFFFACD,0xADD8E6,
0xFAFAD2,0xFFEFD5};
#define NUM_LEDS 64
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
FastLED.setBrightness(5);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(2000);
display.clearDisplay();
display.display();
display.fillRect(0,0,63,16,SSD1306_WHITE);
display.fillRect(65,0,63,16,SSD1306_WHITE);
display.setTextSize(2);
display.setTextColor(SSD1306_BLACK);
display.setCursor(15,1);
display.println("RGB");
display.setCursor(80,1);
display.println("HSV");
display.fillRect(0,15,63,16,SSD1306_WHITE);
display.fillRect(0,32,63,16,SSD1306_WHITE);
display.fillRect(0,49,63,16,SSD1306_WHITE);
display.setCursor(5,17);
display.println("R:");
display.setCursor(5,33);
display.println("G:");
display.setCursor(5,50);
display.println("B:");
display.fillRect(80,15,63,16,SSD1306_WHITE);
display.setCursor(95,17);
display.println("Hue:");
display.display();
}
void loop() {
// reading RGB composite color values from 3 potentiometers
Red= map(analogRead(A2),0,1023,0,260 );
Green= map(analogRead(A1),0,1023,0,260 );
Blue= map(analogRead(A0),0,1023,0,260 );
// reading HSV color value from the potentiometer
C_HSV= map(analogRead(A3),0,1023,0,260 );
// Displaying selected RGB and HSV color values on oled display
display.fillRect(0,15,63,16,SSD1306_WHITE);
display.fillRect(0,32,63,16,SSD1306_WHITE);
display.fillRect(0,49,63,16,SSD1306_WHITE);
display.setCursor(5,17);
display.print("R:");
display.print(Red);
display.setCursor(5,33);
display.print("G:");
display.print(Green);
display.setCursor(5,50);
display.print("B:");
display.print(Blue);
display.fillRect(65,15,63,16,SSD1306_WHITE);
display.setCursor(67,17);
display.print("H:");
display.print(C_HSV);
display.display();
// Setting LEDs in first 4 columns to selected RGB color
// Setting leds in columns 5-8 to selected HSV color
for (int i=0;i<8;i++) {
//leds[i]=CRGB(Red,Green,Blue);
leds[8*i+5]=CRGB(Red,Green,Blue);
leds[8*i+6]=CRGB(Red,Green,Blue);
leds[8*i+7]=CRGB(Red,Green,Blue);
leds[8*i]=CHSV( C_HSV, 255, 255);
leds[8*i+1]=CHSV( C_HSV, 255, 255);
leds[8*i+2]=CHSV( C_HSV, 255, 255);
}
// Redisplaying all leds
FastLED.show();
}
Comments