Skip to content

Instantly share code, notes, and snippets.

@IdrisCytron
Last active September 13, 2020 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IdrisCytron/157d8e11bd14d48330b31351b7bacc11 to your computer and use it in GitHub Desktop.
Save IdrisCytron/157d8e11bd14d48330b31351b7bacc11 to your computer and use it in GitHub Desktop.
Control NeoPixel RGB LED Color Code Using Keypad and Maker Nano.
/*
Project: Control NeoPixel RGB LED Color Code Using Keypad and Maker Nano #ArduinoNano
Board: Arduino Nano (Maker Nano)
Connections:
Nano | I2C LCD Grove
GND - GND
5V - VCC
SDA - SDA
SCL - SCL
Nano | Keypad
12 - pin 1 (most left)
11 - pin 2
10 - pin 3
9 - pin 4
7 - pin 5
6 - pin 6
5 - pin 7
4 - pin 8
Nano | RGB LED Stick
GND - GND
5V - VCC
3 - SIG
External libraries:
- Grove LCD RGB Backlight by Seeed Studio V1.0.0 (Manager)
- Keypad by Mark Stanley V3.1.1 (Manager)
- NeoPixelBus by Makuna V2.5.7 (Manager)
*/
#include <Wire.h>
#include <rgb_lcd.h>
#include <Keypad.h>
#include <NeoPixelBrightnessBus.h>
rgb_lcd lcd;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {7, 6, 5, 4};
byte colPins[COLS] = {12, 11, 10, 9};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const uint16_t PixelCount = 10;
const uint8_t PixelPin = 3;
NeoPixelBrightnessBus<NeoRgbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
#define BUZZER 8
#define NOTE_G4 392
#define NOTE_B4 494
#define NOTE_D5 587
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("[#]Color=000000");
lcd.setCursor(0, 1);
lcd.print("[*]Bright=050 ");
delay(1000);
strip.Begin();
strip.Show();
tone(BUZZER, NOTE_G4, 70);
delay(100);
tone(BUZZER, NOTE_D5, 70);
delay(70);
}
byte count = 0;
byte row = 0;
enum {NONE, COLOR, BRIGHT};
byte data = NONE;
String dataString = "";
char dataArray[6];
byte rgb[3];
int brightness = 50;
int pixel;
void loop()
{
char key = keypad.getKey();
if (key == '#' && data == NONE) {
lcd.setCursor(9, 0);
lcd.print("------");
count = 0;
data = COLOR;
dataString = "";
tone(BUZZER, NOTE_D5, 50);
delay(50);
}
else if (key == '*' && data == NONE) {
lcd.setCursor(10, 1);
lcd.print("---");
count = 0;
data = BRIGHT;
dataString = "";
tone(BUZZER, NOTE_B4, 50);
delay(50);
}
else if (key && data == COLOR) {
tone(BUZZER, NOTE_G4, 50);
delay(50);
count++;
lcd.setCursor(9, 0);
if (key == '*') key = 'E';
else if (key == '#') key = 'F';
dataString += key;
lcd.print(dataString);
if (count == 6) {
dataString.toCharArray(dataArray, 7);
unsigned long number = strtoul(dataArray, nullptr, 16);
for (int i = 2; i >= 0; i--) {
rgb[i] = number & 0xFF;
number >>= 8;
}
// for (int i = 0; i < 3; i++) {
// Serial.print(rgb[i]);
// Serial.println();
// }
strip.SetBrightness(brightness);
for (pixel = 0; pixel < PixelCount; pixel++) {
strip.SetPixelColor(pixel, RgbColor(rgb[1],rgb[0],rgb[2]));
}
strip.Show();
data = NONE;
}
}
else if (key && data == BRIGHT) {
if (key >= '0' && key <= '9') {
tone(BUZZER, NOTE_G4, 50);
delay(50);
count++;
lcd.setCursor(10, 1);
dataString += key;
lcd.print(dataString);
}
if (count == 3) {
brightness = dataString.toInt();
if (brightness > 255) {
brightness = 255;
lcd.setCursor(10, 1);
lcd.print(brightness);
}
strip.SetBrightness(brightness);
for (pixel = 0; pixel < PixelCount; pixel++) {
strip.SetPixelColor(pixel, RgbColor(rgb[1],rgb[0],rgb[2]));
}
strip.Show();
data = NONE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment