I would make for a project, a program code that controls a LED strip using a 4x4 keypad. The problem is what I have I want to create different states e.g. when the A key is held that meanwhile you can switch the LEDs 1-8 with the keys 1-8, then release the A key and this state remains. I need 8 states in total and would have used the keys ( A, B, C, D, 9, 0, *, # ). The other states should do exactly the same as with A only other LEDs address.
I would have made there something already but I know unfortunately no more further and/or how I should formulate generally that.
#include <FastLED_NeoPixel.h>
#define DATA_PIN 10
#define NUM_LEDS 128
#define BRIGHTNESS 250
FastLED_NeoPixel<NUM_LEDS, DATA_PIN, NEO_GRB> strip;
#include <Keypad.h>
enum State_enum {A, B, C, D, NUMBER_NINE, NUMBER_ZERO, STAR, HASH_TAG};
void a();
void b();
void c();
void d();
void number_nine();
void number_zero();
void star();
void hash_tag();
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{ 'D', '#', '0', '*' },
{ 'C', '9', '8', '7' },
{ 'B', '6', '5', '4' },
{ 'A', '3', '2', '1' }
};
byte rowPins[ROWS] = { 6, 7, 8, 9 };
byte colPins[COLS] = { 2, 3, 4, 5 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
uint32_t red = strip.Color(255, 0, 0);
uint32_t off = strip.Color(0, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
void setup() {
strip.begin();
strip.setBrightness(BRIGHTNESS);
Serial.begin(9600);
Serial.println("test");
colorWipe(off, 0);
}
void loop() {
}
void colorWipe(uint32_t color, unsigned long wait) {
Serial.println(color);
for (unsigned int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}
void a(uint32_t color){
char key = keypad.getKey();
if(kpd.getKeys)){
for (int i=0; i<LIST_MAX; i++){
switch (kpd.key[i].kstate){
if (key == 'A') {
switch(kpd.key[i].stateChanged){
case PRESSED:
{ for (uint16_t i = 0; i < 16; i+2)
Serial.println(key);
if (isDigit(key)) {
int keyAsNumber = key - '0';
strip.setPixelColor(keyAsNumber - 1, red);
}
}
strip.show();
}
does anyone have an idea or tip how i can do this.
Thanks in advance.