Hello, I have spent days on this. Some description within the code attached. In short I have a FastLED programs changing patterns with push button. I want to display the pattern on a OLED. I can get each to work independently but not together. Sure would like some suggestions. I have used OLED with multiple temperature, time, date etc. successfully but this has me stumped.
Any help, as always, greatly appreciated.
Thanks,
//_________________________________________________________________________
#include <FastLED.h>
#include <OneButton.h>
//#include <SPI.h)>
#include <Wire.h>;
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUM_LEDS 50
#define LED_PIN 3
#define BTN_PIN 7
#define leds_i
CRGB leds[NUM_LEDS];
uint8_t patternCounter = 0;
uint8_t data[ NUM_LEDS];
// Push button connected between pin 7 and GND (no resistor required)
OneButton btn = OneButton(BTN_PIN, true, true);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
FastLED.addLeds<WS2812B, LED_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness(200);
Serial.begin(9600);
/*
* #define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
0b00000001, 0b11000000,
0b00000001, 0b11000000,
0b00000011, 0b11100000,
0b11110011, 0b11100000,
0b11111110, 0b11111000,
0b01111110, 0b11111111,
0b00110011, 0b10011111,
0b00011111, 0b11111100,
0b00001101, 0b01110000,
0b00011011, 0b10100000,
0b00111111, 0b11100000,
0b00111111, 0b11110000,
0b01111100, 0b11110000,
0b01110000, 0b01110000,
0b00000000, 0b00110000 };
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
I CAN GET THE PROGRAM OR THE OLED BUT NOT BOTH TOGETHER???
*/
/* HELP!! I have been working on this for days, almost non stop. Trying to output the color selected via push button to OLED.
* It seems that if I have this anywhere in the program, it prevents the program from working. I can display on the OLED
* without the program running? I have used these OLEDs in other projects but can't seem to get this to work.
// display.clearDisplay();
// display.setTextSize(2);
// display.setTextColor(WHITE);
// display.setCursor(5, 15);
// display.println("HELP!! "); // WANT COLOR OF PATTERN TO SHOW ON OLED
// display.display(); //delay(2000);
*/
btn.attachClick(nextPattern);
}
//___________________________________________________________________
void loop() {
switch (patternCounter) {
case 0:
redSolid();
break;
case 1:
greenSolid();
break;
case 2:
blueSolid();
break;
case 3:
purpleSolid();
break;
case 4:
blueWhiteSolid();
break;
case 5:
blueGlitter();
break;
}
FastLED.show();
btn.tick();
}
void nextPattern() {
patternCounter = (patternCounter + 1) % 6;
// Change the number after the % to the number of patterns you have
}
//------- Put your patterns below -------//
void redSolid() {
// _________________________________________________________________________________________RED
Serial.print(patternCounter);
Serial.println("RED");
for (int x = 0; x < NUM_LEDS; x += 2) {
leds[x] = CRGB:: Red; // RED
}
for (int x = 1; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Red; // RED
}
FastLED.show();
}
//______________________________________________________________________//GREEN____________
void greenSolid() {
Serial.print(patternCounter);
Serial.println("GREEN");
for (int x = 0; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Green; // GREEN
}
for (int x = 1; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Green; // GREEN
}
FastLED.show();
}
//_______________________________________________________________________ BLUE_______________
void blueSolid() {
Serial.print(patternCounter);
Serial.println("BLUE");
for (int x = 0; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Blue; // BLUE
for (int x = 1; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Blue; // BLUE
}
FastLED.show();
}
}
//___________________________________________________________________________________
void purpleSolid() {
Serial.print(patternCounter);
Serial.println("PURPLE");
for (int x = 0; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Purple; // PURPLE
for (int x = 1; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Purple; // PURPLE
}
FastLED.show();
}
}
//__________________________________________________________________________________________________
void blueWhiteSolid() {
Serial.print(patternCounter);
Serial.println("BLUE/WHITE");
for (int x = 0; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::Blue; // BLUE/WHITE
for (int x = 1; x < NUM_LEDS; x += 2) {
leds[x] = CRGB::White; // BLUE/WHITE
}
FastLED.show();
}
}
//___________________________________________________________________________________________________
void blueGlitter() {
fill_data_array();
render_data_with_palette();
add_glitter();
Serial.print(patternCounter);
Serial.println("BLUE/GLITTER");
FastLED.show();
FastLED.delay(20);
}
void fill_data_array()
{
static uint8_t startValue = 0;
startValue = startValue + 2;
uint8_t value = startValue;
for ( int i = 0; i < NUM_LEDS; i++) {
data[i] = triwave8( value); // convert value to an up-and-down wave
value += 7;
}
}
CRGBPalette16 gPalette (
CRGB::Blue, CRGB::Blue, //BLACK CHANGE THESE FOR FOURTH OF JULY RED,WHITE,BLUE
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue, //RED
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,// WHITE
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,//BLUE
CRGB::Blue, CRGB::Blue //BLACK
);
void render_data_with_palette()
{
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( gPalette, data[i], 128, 1);
}
}
void add_glitter()
{
int chance_of_glitter = 10; // percent of the time that we add glitter
int number_of_glitters = 1; // number of glitter sparkles to add
int r = random8(100);
if ( r < chance_of_glitter ) {
for ( int j = 0; j < number_of_glitters; j++) {
int pos = random16( NUM_LEDS);
leds[pos] = CRGB::White; // very bright glitter
}
}
}