Controlling individual addressable RGB LEDs with Keypad

Hey all,

I have been mulling over this project for a while and done some experimenting but my knowledge is very limited so Id like some direction and assistance if anyone has any ideas.

Using Arduino, I would essential like to be able to turn an addressable LED WS2812B which have been setup in a daisy chain, say 200 LEDs, external power, sign from one pin on an Arudino board.

I would like to be able to use a Sparkfun Qwiic Keypad (3x4 matrix) to select which LED to turn on.

Example. Keying 0101 would turn on the first LED and turn Everything else off. Keying 0109 would turn on LED #9 and everything else off.

I would also like to set some scenes in different densities (light/medium/heavy) whereby keying in for example 9001 would turn on 25 random LEDs and after 10 seconds turn off one of these LEDs and turn on another and repeating every 10 seconds to show some “random activity”; a medium scene (9002) would have 50 LEDs on and a heavy scene (9003), 100 LEDs.

There is a reason im using a four digit input as Im hoping to expand this a bit and Im thinking forward with the syntax.

The ultimate goal, which by my research will complicate things significantly is using something like Alexa to be able to vocally do the switching by saying “Alexa, turn on House 1”

All of that sounds possible up to the point of using Alexa, with which I am not familiar

Do you have a question ?

Sorry, yes.

Suggestions on Libraries to use, possibly a hand to tweak and streamline code once I get started.
Any suggestions on similar projects that anyone knows of to use as a starting point.

Everything ive come across is more related to sequential effects over multiple LEDs rather than individual control.

Ive looked at ALA, FastLED, Adafruit. Is one of these more appropriate or works with the keypad more effectively code-wise or is there another one I haven't come across yet.

The FastLED library is well known and can do everything that you described.

One tip for you. When you start to write the code do not use any delay()s in it or the program will be unresponsive because the delay() function stalls the program while the delay occurs. Instead look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE and use millis() for timing. Do not be tempted to think that you can use delay() and change to millis() later or you will regret it

Once you have written something you will get plenty of help here

Thanks, The FastLED coding seems simple enough so far, my trouble at the moment is sifting through the Sparkfun Qwiic Examples for the appropriate code to extract for my use the taking the input and using that to correlate to an LED.

A few more questions,

  1. from a correlation POV, is IF statements the best way or is there another way.

  2. do I HAVE to have a screen to print to for this to work as it seems like every example has printing involved.

  3. because I want to use a 4 digit code, do I need to make the * or # an "enter" key as it seems the coding is base on a timeout to finish accepting inputs?

from a correlation POV, is IF statements the best way or is there another way.

The if statement will work but beyond a few tests it becomes tedious to write but is very readable. Of course, for the simple case of turning on/off a single LED you don't need an if at all because the number entered by the user will include the number of the LED but I do not understand your proposed coding scheme. To me, entering say 1231 would turn on LED 123 and 1230 would turn it off with perhaps 1239 changing its state. That would be simple to code

do I HAVE to have a screen to print to for this to work as it seems like every example has printing involved.

You will need to use the Serial monitor when testing/debugging code but do not need it afterwards. A 2 line LCD screen connected by IC2 to reduce pin useage would also be helpful so that users could see what they have entered.

because I want to use a 4 digit code, do I need to make the * or # an "enter" key as it seems the coding is base on a timeout to finish accepting inputs?

My advice would be to use a special key to signal the end of entry which also gives you the chance to use another key to abort entry in case of mistakes

I am not familiar with the Qwiic Keypad nor, I suspect, are many here. Simpler matrix keypads use more pins but are a doddle to read using the Keypad library and are familiar to many here

As to your more advanced patterns, you could consider using 4 digit data entry such as 9001 to trigger pattern 1, 9006 to trigger pattern 6 etc. This would lend itself to triggering different functions based on the number entered, again without the use of multiple if statements by the use of an array of function pointers.

What you are hoping to do sounds like fun

Thanks for the help so far.

The reason I'm using the four digital input as it is, is because I'd like to integrate it into a hotel building I have on the set whereby the code AABB is A=Floor # and B = Room #. So Floor 12 Room 8 would be 1208.

Perfect on the serial.monitor

What matrix keypad would you suggest, I'm open to any, i would just like a solid looking and feeling keypad rather than the flexible red & blue membrane ones.

The Sparkfun keypad i have, if I removed the sparkfun ATtiny85 would this still be useable and would it increase the knowledge base for me to draw form? Note, Im not limit on PINs and I only need one for the LED signal, the rest are available.

The reason I'm using the four digital input as it is, is because I'd like to integrate it into a hotel building I have on the set whereby the code AABB is A=Floor # and B = Room #. So Floor 12 Room 8 would be 1208.

There is no problem with 4 digit input but my suggestion was aimed at keeping the coding simple and avoiding multiple if statements and a code like 1208 for Floor 12 Room 8 does not lend itself to using arrays or structs to decode the input unless there is only one building, although it could be done at the expense of more code

As to which matrix keypad, something like this matrix keypad generally works well

Sorry, but I know nothing about the Sparkfun keypad. I have little doubt that you could use it

Why not start by using the Serial monitor for input during the testing/proving phase ? Isolate the input code into its own function and replace it later with keypad entry

What I’ve found useful for searching is to enter the term 4x4 keypad, for example, into and then select images/pictures or whatever. This way you can see a dozen items on the page at a time and follow links to the interesting ones. There’s lots of noise and duplication but it’s still faster than trudging through a page of text links.

No worries, I'll do some more research and testing, Ill keep you updated

Righto, so I’m getting somewhere but nowhere…

Ive managed to get the Qwiic Keypad working and I can see the entries in the Serial.monitor
Ive got the leds working independently controlling from within the code.

Now I need how to work out how to store the keypad input as a 4 digit array and use the # as an enter key (5th keypress)

Once I have the keypresses stored i then need to correlate this with the led number it relates to; then I need to be able to switch this led on and everything else off.

UKHeliBob - I tried using millis instead of delay but I must be doing something wrong as it wont compile, ive left the delay() for now, if you can give some guidance please

#include <Wire.h>
#include "SparkFun_Qwiic_Keypad_Arduino_Library.h"
#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 6
KEYPAD keypad1;
CRGB leds[NUM_LEDS];
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 1000;
void setup(void)
{
  Serial.begin(9600);
  if (keypad1.begin() == false)
  {
    Serial.println("Keypad does not appear to be connected. Please check wiring. Freezing...");
    while (1);
  }
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  FastLED.setBrightness(25);
}
void loop(void)
{
  currentMillis = millis();
  keypad1.updateFIFO();
  char button = keypad1.getButton();
  if (button == -1)
  {
    Serial.println("No keypad detected");
    delay(1000);
  }
  else if (button != 0)
  {
    if (button == '#') Serial.println();
    else if (button == '*') Serial.print(" ");
    else Serial.print(button);
  }
  delay(25);
  leds[0] = CRGB::Red;
  leds[1] = CRGB::White;
  leds[2] = CRGB::Blue;
  leds[3] = CRGB::Green;
  leds[4] = CRGB::Red;
  leds[5] = CRGB::White;
  leds[6] = CRGB::Red;
  leds[7] = CRGB::White;
  leds[8] = CRGB::White;
  leds[9] = CRGB::White;
  FastLED.show();
}

I tried using millis instead of delay but I must be doing something wrong as it wont compile

Please post your best effort and the full error message

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE itself has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code” it can as you now see, be quite garbled and is always more difficult to read due to the font.

It is inappropriate to attach it as a “.ino” file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And even that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only single blanks between complete functional blocks.