I am looking for help with this code. I would prefer to use an Uno or nano for this project. I slowly added the code little by little to see what was preventing it from running on the uno.
Hardware:
4x4 keypad
I2C display
LED strip lights
Summary:
I have a string of addressable LED lights that run the perimeter of my poker table. Ultimately the code keeps track of which seats are occupied and lights up the dealer, small blind, and big blind seats. the code does the following:
- prompts the user to enter empty seats
- user enters empty seat numbers
- user hits * to proceed to game
- if the user presses '#' the code will advance the dealer seats to the next filled seat
- if the user presses 'D' it will remove a seat
6 after each action. the code reloops (updates the LCD & LEDs)
#include <Keypad.h>
#include <Adafruit_NeoPixel.h>
#define PIN 13
#define NUMPIXELS 100
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//Constants
const int numS = 10;
const int numSLED = 10;
//Variables
int smallB;
int smallBE = false;
int bigB;
int dealerS = 0;
boolean seats[numS];
boolean setupComplete = false;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayt = 100;
int numm;
int deadBlind = false;
//keypad
const byte numRows = 4; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad
char keymap[numRows][numCols] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = { 9, 8, 7, 6 }; //Rows 0 to 3
byte colPins[numCols] = { 5, 4, 3, 2 }; //Columns 0 to 3
//initializes an instance of the Keypad class
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup() {
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("failed"));
for (;;)
;
}
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 10);
pixels.begin();
resetSeats();
promptEmptySeats();
pixels.setBrightness(20);
}
//If key is pressed, this key is stored in 'keypressed' variable
//If key is not equal to 'NO_KEY', then this key is printed out
//if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process
void loop() {
display.clearDisplay();
updateLCD();
updateLEDs();
char key = '\0';
while (key == '\0') {
key = myKeypad.getKey();
}
switch (key) {
case 'D':
key = '\0';
display.clearDisplay();
display.setCursor(0, 10);
display.print("KO Seat?");
display.display();
delay(250);
while (key == '\0') {
key = myKeypad.getKey();
}
removeSeat(key);
break;
case '#':
key = '\0';
display.clearDisplay();
display.setCursor(0, 10);
display.print("next dealer");
display.display();
delay(250);
advanceDealer();
break;
case 'B':
key = '\0';
display.clearDisplay();
display.setCursor(0, 10);
display.println("Blink Seat");
display.display();
delay(250);
blinkSeat();
break;
}
}
void resetSeats() {
for (int i = 0; i < numS; i++) {
seats[i] = true;
}
}
void promptEmptySeats() {
display.clearDisplay();
display.setCursor(0, 10);
display.println("Remove ");
display.print("Seat #s: ");
display.display();
while (!setupComplete) {
char key = myKeypad.getKey();
if (key != NO_KEY) {
if (isdigit(key)) {
removeSeat(key);
display.clearDisplay();
display.setCursor(0, 10);
display.println("Remove ");
display.print("Seat #: ");
display.display();
} else if (key == '*') {
setupComplete = true;
startGame();
}
}
}
while (!seats[dealerS]) {
dealerS++;
}
smallB = dealerS + 1;
while (!seats[smallB]) {
smallB++;
}
bigB = smallB + 1;
while (!seats[bigB]) {
bigB++;
}
}
void removeSeat(char seatNum) {
char key = myKeypad.getKey();
int seat;
int displayS;
if (seatNum == '0') {
displayS = 10; // Seat 10
} else {
displayS = seatNum - '0';
}
display.clearDisplay();
display.setCursor(0, 0);
display.print(displayS);
display.print(" removed");
display.display();
delay(1000);
if (seatNum == '0') {
seat = 9; // Seat 10
} else {
seat = seatNum - '1';
}
if (seat >= 0 && seat < numS) {
seats[seat] = false;
}
if (seatNum == smallB) {
display.print("small B eliminated");
display.display();
smallBE = true;
}
}
void advanceDealer() {
do {
dealerS++;
if (dealerS + 1 > numS) {
dealerS = 0;
}
} while (!seats[dealerS]);
advanceSB();
advanceBB();
}
void advanceSB() {
int nextSB = dealerS;
do {
nextSB++;
if (nextSB + 1 > numS) {
nextSB = 0;
}
} while (!seats[nextSB]);
smallB = nextSB;
}
void advanceBB() {
int nextBB = smallB;
do {
nextBB++;
if (nextBB + 1 > numS) {
nextBB = 0;
}
} while (!seats[nextBB]);
bigB = nextBB;
}
void addSeat() {
display.clearDisplay();
display.print("add seat");
display.display();
}
void blinkSeat() {
display.clearDisplay();
display.setCursor(0, 10);
display.print("Start");
display.display();
}
void startGame() {
display.clearDisplay();
display.setCursor(0, 10);
display.print("Start");
display.display();
}
void updateLCD() {
display.clearDisplay();
display.setCursor(0, 10);
display.print("D:");
display.print(dealerS + 1);
display.print(" ");
display.print("Sm:");
display.print(smallB + 1);
display.print(" ");
display.print("Big:");
display.println(bigB + 1);
display.display();
for (int i = 0; i < numS; i++) {
if (seats[i]) {
display.print(i + 1);
display.display();
}
}
}
void updateLEDs() {
pixels.clear();
Serial.println(dealerS);
int Dstart = numSLED * (dealerS);
int Dend = Dstart + (numSLED - 1);
for (int j = Dstart; j <= Dend; j++) {
pixels.setPixelColor(j, pixels.Color(255, 255, 255));
Serial.print(j);
pixels.show();
}
int Sstart = numSLED * (smallB);
int Send = Sstart + (numSLED - 1);
for (int j = Sstart; j <= Send; j++) {
pixels.setPixelColor(j, pixels.Color(0, 0, 255));
}
int Bstart = numSLED * (bigB);
int Bend = Bstart + (numSLED - 1);
for (int j = Bstart; j <= Bend; j++) {
pixels.setPixelColor(j, pixels.Color(255, 100, 0));
}
display.display();
pixels.show();
}