Hi all,
First off i am new and using mostly example code…
But i have a rice paper floor lamp with 3 one meter LED strips in it and a Grove I2C Multitouch and Grove RBG backlight LCD…
The Code with a fire effect is working Great has 4 touch sensors to cycle though and change settings with the LCD…
And the Water looking one works but once i add in the touch and LCD code it just hangs before it even gets the setup done (sometimes makes it to the LCD backlight color) but i don’t get any errors and all the code works on its own
Original:
#include <FastLED.h>
#define LED0_PIN 2
#define LED1_PIN 4
#define LED2_PIN 6
#define CLOCK0_PIN 3
#define CLOCK1_PIN 5
#define CLOCK2_PIN 7
#define CHIPSET WS2801
const bool kMatrixSerpentineLayout = false;
const uint8_t kMatrixWidth = 3;
const uint8_t kMatrixHeight = 32;
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
CRGB leds[kMatrixWidth * kMatrixHeight];
int BRIGHTNESS = 128;
int HUESPEED = .1;
int SPEED = 30;
int SCALE = 4000;
// The 32bit version of our coordinates
static uint16_t x;
static uint16_t y;
static uint16_t z;
// This is the array that we keep our computed noise values in
uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
void setup()
{
delay(3000);
FastLED.addLeds<CHIPSET, LED0_PIN, CLOCK0_PIN>(leds, 0, kMatrixHeight).setCorrection( TypicalLEDStrip );
FastLED.addLeds<CHIPSET, LED1_PIN, CLOCK1_PIN>(leds, kMatrixHeight, kMatrixHeight).setCorrection( TypicalLEDStrip );
FastLED.addLeds<CHIPSET, LED2_PIN, CLOCK2_PIN>(leds, 2 * kMatrixHeight, kMatrixHeight).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
// Initialize our coordinates to some random values
x = random16();
y = random16();
z = random16();
}
void loop()
{
WaterNoise();
FastLED.setBrightness(BRIGHTNESS);
}
void WaterNoise()
{
static float ihue = 0;
for(int i = 0; i < MAX_DIMENSION; i++)
{
int ioffset = SCALE * i;
for(int j = 0; j < MAX_DIMENSION; j++)
{
int joffset = SCALE * j;
noise[i][j] = inoise8(x + ioffset, y + joffset, z);
}
}
z += SPEED;
for(int i = 0; i < kMatrixWidth; i++)
{
for(int j = 0; j < kMatrixHeight; j++)
{
// We use the value at the (i,j) coordinate in the noise
// array for our brightness, and the flipped value from (j,i)
// for our pixel's hue.
//leds[XY(i,j)] = CHSV(noise[j][i],255,noise[i][j]);
//leds[XY(i,j)] = CHSV(ihue + (noise[j][i]>>1),255,noise[i][j]);
leds[XY(i, j)] = CHSV(ihue + noise[j][i], 255, noise[i][j]);
}
}
ihue += HUESPEED;
LEDS.show();
}
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false)
{
i = (y * kMatrixWidth) + x;
}
if( kMatrixSerpentineLayout == true)
{
if( y & 0x01)
{
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
}
else
{
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
return i;
}
Code in Question with the touch-n-LCD from the fire code:
#include <FastLED.h>
#include <Wire.h>
#include <GroveMultiTouch.h>
#include <rgb_lcd.h>
#define LED0_PIN 2
#define LED1_PIN 4
#define LED2_PIN 6
#define CLOCK0_PIN 3
#define CLOCK1_PIN 5
#define CLOCK2_PIN 7
#define CHIPSET WS2801
const bool kMatrixSerpentineLayout = false;
const uint8_t kMatrixWidth = 3;
const uint8_t kMatrixHeight = 32;
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
CRGB leds[kMatrixWidth * kMatrixHeight];
int BRIGHTNESS = 128;
int HUESPEED = .1;
int SPEED = 30;
int SCALE = 4000;
// The 32bit version of our coordinates
static uint16_t x;
static uint16_t y;
static uint16_t z;
// This is the array that we keep our computed noise values in
uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
int menumode = 0;
int COLPAL = 0;
#define MAXMENUMODE 4
#define MAXCOLPAL 3
String COLPALNAME = "Hello ";
rgb_lcd lcd;
const int colorR = 0;
const int colorG = 0;
const int colorB = 250;
GroveMultiTouch feelers(8);
boolean padTouched[4];
boolean wastouched = true;
static unsigned long last_touched_time = 0;
long previousMillis = 0;
void setup()
{
delay(3000);
FastLED.addLeds<CHIPSET, LED0_PIN, CLOCK0_PIN>(leds, 0, kMatrixHeight).setCorrection( TypicalLEDStrip );
FastLED.addLeds<CHIPSET, LED1_PIN, CLOCK1_PIN>(leds, kMatrixHeight, kMatrixHeight).setCorrection( TypicalLEDStrip );
FastLED.addLeds<CHIPSET, LED2_PIN, CLOCK2_PIN>(leds, 2 * kMatrixHeight, kMatrixHeight).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
// Initialize our coordinates to some random values
x = random16();
y = random16();
z = random16();
Wire.begin(); // needed by the GroveMultiTouch lib
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
feelers.initialize(); // initialize the feelers
for(int i = 0; i <= 3; i++)
{
padTouched[i] = false;
}
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - last_touched_time > 5000UL)
{
if(wastouched)
{
lcd.setCursor(0, 0);
lcd.print("Run Time ");
lcd.setCursor(0, 1);
lcd.print(" ");
wastouched = false;
}
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}
feelers.readTouchInputs(); // test read the touch sensors
for(int i = 0; i <= 3; i++)
{
if(feelers.getTouchState(i))
{
if(!padTouched[i])
{
//Serial.print(i);
//Serial.println(" +");
}
padTouched[i] = true;
touched(i);
}
else
{
if(padTouched[i])
{
//Serial.print(i);
//Serial.println(" -");
}
padTouched[i] = false;
}
}
WaterNoise();
FastLED.setBrightness(BRIGHTNESS);
}
void touched(int pad)
{
unsigned long touched_time = millis();
if (touched_time - last_touched_time > 200)
{
last_touched_time = touched_time;
wastouched = true;
lcd.setCursor(0, 1);
lcd.print(" ");
if(pad == 0)
{
menumode ++;
if(menumode == MAXMENUMODE)
{
menumode = 0;
}
}
if(pad == 1)
{
menumode --;
if(menumode == -1)
{
menumode = MAXMENUMODE - 1;
}
}
switch(menumode)
{
case 0:
if(pad == 2 && SCALE <= 3999)
{
SCALE += 10;
}
if(pad == 3 && SCALE >= 2)
{
SCALE -= 10;
}
lcd.setCursor(0, 0);
lcd.print("Scale ");
lcd.setCursor(0, 1);
lcd.print(SCALE);
break;
case 1:
if(pad == 2 && SPEED <= 99)
{
SPEED ++;
}
if(pad == 3 && SPEED >= 2)
{
SPEED --;
}
lcd.setCursor(0, 0);
lcd.print("Speed ");
lcd.setCursor(0, 1);
lcd.print(SPEED);
break;
case 2:
if(pad == 2 && BRIGHTNESS <= 254)
{
BRIGHTNESS ++;
}
if(pad == 3 && BRIGHTNESS >= 1)
{
BRIGHTNESS --;
}
lcd.setCursor(0, 0);
lcd.print("Brighness ");
lcd.setCursor(0, 1);
lcd.print(BRIGHTNESS);
break;
case 3:
if(pad == 2 && HUESPEED <= 1.0)
{
HUESPEED += .01;
}
if(pad == 3 && HUESPEED >= .01)
{
HUESPEED -= .01;
}
lcd.setCursor(0, 0);
lcd.print("HueSpeed ");
lcd.setCursor(0, 1);
lcd.print(HUESPEED);
break;
case 4:
if(pad == 2)
{
COLPAL ++;
if(COLPAL == MAXCOLPAL)
{
COLPAL = 0;
}
}
if(pad == 3)
{
COLPAL --;
if(COLPAL == -1)
{
COLPAL = MAXCOLPAL - 1;
}
}
switch(COLPAL)
{
case 0:
COLPALNAME = "a ";
break;
case 1:
COLPALNAME = "b ";
break;
case 2:
COLPALNAME = "c ";
break;
}
lcd.setCursor(0, 0);
lcd.print("Palate ");
lcd.setCursor(0, 1);
lcd.print(COLPALNAME);
break;
}
}
}
void WaterNoise()
{
static float ihue = 0;
for(int i = 0; i < MAX_DIMENSION; i++)
{
int ioffset = SCALE * i;
for(int j = 0; j < MAX_DIMENSION; j++)
{
int joffset = SCALE * j;
noise[i][j] = inoise8(x + ioffset, y + joffset, z);
}
}
z += SPEED;
for(int i = 0; i < kMatrixWidth; i++)
{
for(int j = 0; j < kMatrixHeight; j++)
{
switch(COLPAL)
{
case 0:
leds[XY(i, j)] = CHSV(ihue + noise[j][i], 255, noise[i][j]);
break;
case 1:
leds[XY(i, j)] = CHSV(ihue + (noise[j][i] >> 1), 255, noise[i][j]);
break;
case 2:
leds[XY(i, j)] = CHSV(noise[j][i], 255, noise[i][j]);
break;
}
}
}
ihue += HUESPEED;
LEDS.show();
}
uint16_t XY( uint8_t x, uint8_t y)
{
uint16_t i;
if( kMatrixSerpentineLayout == false)
{
i = (y * kMatrixWidth) + x;
}
if( kMatrixSerpentineLayout == true)
{
if( y & 0x01)
{
// Odd rows run backwards
uint8_t reverseX = (kMatrixWidth - 1) - x;
i = (y * kMatrixWidth) + reverseX;
}
else
{
// Even rows run forwards
i = (y * kMatrixWidth) + x;
}
}
return i;
}
…Thanx in advance for any help