Hello,
I have one quite annoying problem which I am trying to fix last couple days.
I would like to have a system which is indicating the status of the machine by colour.
For example machine is running - green light.
Machine stop - red light, etc.
Bacause regular lights are boring I am trying to add some effects by FastLED & WS2812 led strip, but seems that I am getting some loop problem.
The idea is to click '1' on the keypad and then the green light with glowing effects done by FastLED would come up.
Then when '2' would be pressed the red light (also with some effects).
Now the keypad is working, because when '1' would be pressed the green light is coming, then when '2' is pressed the red light is coming - but the main problem is that the effects are not there.
Below it the code which I am using right now.
Keypad_and_WS2812.ino (2.1 KB)
#include <Keypad.h>
#include <FastLED.h>
byte myLEDis = 255;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] =
{
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
boolean keyStateChanged();
Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define NUM_LEDS 10
CRGB leds[NUM_LEDS];
#define PIN 9
uint8_t colorIndex[NUM_LEDS];
DEFINE_GRADIENT_PALETTE( greenblue_gp ) {
0, 5, 130, 5,
125, 0, 200, 10,
255, 5, 130, 5,
};
CRGBPalette16 greenblue = greenblue_gp;
DEFINE_GRADIENT_PALETTE( red_gp ) {
0, 155, 0, 5,
125, 200, 200, 10,
255, 155, 0, 5,
};
CRGBPalette16 red = red_gp;
//******************************************************************************
void setup()
{
Serial.begin(9600);
pinMode(PIN, OUTPUT);
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(50);
for (int i = 0; i < NUM_LEDS; i++) {
colorIndex[i] = random8();
}
} //END of setup()
//******************************************************************************
void loop()
{
char key = myKeypad.getKey();
FastLED.clear();
if (key == '1') {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(greenblue, colorIndex[i]);
}
EVERY_N_MILLISECONDS(5) {
for (int i = 0; i < NUM_LEDS; i++) {
colorIndex[i]++;
}
}
FastLED.show();
}
else if (key == '2') {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(red, colorIndex[i]);
}
EVERY_N_MILLISECONDS(5) {
for (int i = 0; i < NUM_LEDS; i++) {
colorIndex[i]++;
}
}
FastLED.show();
}
}