Attempting to upload a Catchphrase clone to my Uno Minima R4 and the code I have grabbed from the internet is not allowing me many topics. I want to add 500+ words to this code and it only allows a few dozen, keeps erroring out with message below about Global Variables. Does anyone know how I can simplify the code to allow this many variables plus many more?? I only have a handful of variables uploaded just to validate my code I have, but I want to add hundreds more but I am maxed.
Global variables use 1985 bytes (96%) of dynamic memory, leaving 63 bytes for local variables. Maximum is 2048 bytes.
#include <LiquidCrystal.h> // include the library code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
//counting vars
int newGame = 0;
int timerCounter = 0;
int timerMaxCount = 60;
int teamOneReadScore = 0;
int teamTwoReadScore = 0;
int teamOneWins = 0;
int teamTwoWins = 0;
//setting up the buzzer
const int buzzerPin = 10; // the number of the buzzer pin
int buzzerState = LOW; // buzzerState used to set the buzzer
long previousMillis = 0; // will store last time buzzer was updated
long buzzerInterval = 300; // buzzerInterval (milliseconds)
// setting up start button
int startButtonPin = 9;
int startButtonPushCounter = 0; // counter for the number of button presses
int startButtonState = 0; // current state of the button
int startButtonLastestState = 0; // previous state of the button
// setting up next button
int nextButtonPin = 8;
int nextButtonPushCounter = 0;
int nextButtonState = 0;
int nextButtonLastestState = 0;
// setting up teamOne button
int teamOneButtonPin = 7;
int teamOneButtonPushCounter = 0;
int teamOneButtonState = 0;
int teamOneButtonLastestState = 0;
// setting up teamTwo button
int teamTwoButtonPin = 6;
int teamTwoButtonPushCounter = 0;
int teamTwoButtonState = 0;
int teamTwoButtonLastestState = 0;
String words[] = {
"Alsace Lorraine","American League","April O'Neil","AquaLink","Aria","Arizona Cardinals","Arson","Assault","Atlanta Braves","Atlanta Falcons","Atlantic Ave","Avocado tree","Arizona Diamondbacks","B & E","Bake n Broil","Ballantree St","Ballast Point","Balls back","Baltimore Ravens","Baltimore Orioles","Barry's Beach Shack","Baseball Bat","Bases Loaded","Beavis and Butthead","Behind the Back","Belmont Heights","Belmont Shore","Big League Chew","Big Leagues","Bixby Knolls","Bixby Road","Bixby Village","Bakrnd Investigation","Blitz","Bloody Mary","Blooper","Blue Line","Bluff Park","Bobblehead","Bond","Boston Red Sox","Bottomless Mimosas","Bourbon","Boys in Blue","Brandy Burger","Breakers Hotel","Breathalyzer","Bud Light","Buffalo Bills","Bullpen","Bunt","Burglary","C17 Globe Master","Cactus Cooler","Cactus League","Caddyshack","California Ave","California Heights","Call Bowl","Calvin Broadus","Cambodia Town","Cameron Diaz","Carl Weathers","Carl's Jr","Carmelitos","Carolina Panthers","Catalina Express","Catalina Island","Catwalk","Caught Looking","Cedar Ave","Cerritos Ave","Change Up","Chase Utley","Cherry Ave","Chestnut Ave","Chicago Bears","Chicago Cubs","Chicago White Sox","Chief of Police","Christmas Parade","Cincinnati Bengals","Cincinnati Reds","Circa","Classic Car Show","Cleveland Guardians","Cleveland Browns","Code 3","Code 7","Colorado Rockies","Contra","Coors Light","Cops in Nihongo","Cosmopolitan","Coyote Ugly","Cup In Cup"}; // an array of words for catchphrase
int maxSize = sizeof(words)/sizeof(String);
int interval = 0;
void setup() {
lcd.begin(2,16);
shuffle();
pinMode(startButtonPin, INPUT_PULLUP); // button as input
digitalWrite(startButtonPin, HIGH); // turns on pull-up resistor after input
pinMode(nextButtonPin, INPUT_PULLUP);
digitalWrite(nextButtonPin, HIGH);
pinMode(teamOneButtonPin, INPUT_PULLUP);
digitalWrite(teamOneButtonPin, HIGH);
pinMode(teamTwoButtonPin, INPUT_PULLUP);
digitalWrite(teamTwoButtonPin, HIGH);
pinMode(buzzerPin, OUTPUT); //buzzer setup
lcd.print("Press Start!");
}
void loop() {
printScore();
timerTone();
startButtonState = digitalRead(startButtonPin);
if (startButtonState != startButtonLastestState) {
if(digitalRead(startButtonPin) == LOW){
if(timerCounter == 0){
startGame();
}
else {
digitalWrite(buzzerPin, LOW);
timerCounter = 0;
}
}
}
startButtonLastestState = startButtonState;
nextButtonState = digitalRead(nextButtonPin);
if (nextButtonState != nextButtonLastestState) {
if(digitalRead(nextButtonPin) == LOW){
printWord();
}
}
nextButtonLastestState = nextButtonState;
teamOneButtonState = digitalRead(teamOneButtonPin);
if (teamOneButtonState != teamOneButtonLastestState) {
if(digitalRead(teamOneButtonPin) == LOW){
teamOneScore();
}
}
teamOneButtonLastestState = teamOneButtonState;
teamTwoButtonState = digitalRead(teamTwoButtonPin);
if (teamTwoButtonState != teamTwoButtonLastestState) {
if(digitalRead(teamTwoButtonPin) == LOW){
teamTwoScore();
}
}
teamTwoButtonLastestState = teamTwoButtonState;
}
// shuffle the list of words
void shuffle(){
for (int a=0; a<maxSize; a++){
int r = random(a+1);
String temp = words[a];
words[a] = words[r];
words[r] = temp;
}
}
//start the game
void startGame() {
lcd.clear();
lcd.print(words[interval]);
interval++;
newGame++;
timerCounter ++;
if (interval == maxSize) {
interval = 0;
shuffle();
}
}
//print the word
void printWord() {
if (timerCounter !=0) {
lcd.clear();
lcd.print(words[interval]);
interval++;
if (interval == maxSize) {
interval = 0;
shuffle();
}
}
}
//timer with buzzer
void timerTone() {
unsigned long currentMillis = millis();
if (timerCounter > 0) {
if (timerCounter < timerMaxCount) {
if(currentMillis - previousMillis > buzzerInterval) {
previousMillis = currentMillis;
if (buzzerState == LOW){
buzzerState = HIGH;
}
else{
buzzerState = LOW;
}
digitalWrite(buzzerPin, buzzerState);
timerCounter++;
}
}
}
if (timerCounter == timerMaxCount) {
digitalWrite(buzzerPin, LOW);
timerCounter = 0;
}
}
//teamOne score
void teamOneScore() {
if (newGame != 0) {
teamOneReadScore++;
lcd.setCursor(0, 1); // bottom left
lcd.print("One: ");
lcd.print(teamOneReadScore);
if (teamOneReadScore > 10) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Team One wins!");
newGame = 0;
teamOneReadScore = 0;
teamTwoReadScore = 0;
teamOneWins = 1;
timerCounter = 0;
digitalWrite(buzzerPin, LOW);
}
}
}
//teamTwo score
void teamTwoScore() {
if (newGame != 0) {
teamTwoReadScore++;
lcd.setCursor(9, 1); // bottom right
lcd.print("Two: ");
lcd.print(teamTwoReadScore);
if (teamTwoReadScore > 10) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Team Two wins!");
newGame = 0;
teamOneReadScore = 0;
teamTwoReadScore = 0;
teamTwoWins = 1;
timerCounter = 0;
digitalWrite(buzzerPin, LOW);
}
}
}
//print score
void printScore() {
if (newGame > 0) {
lcd.setCursor(0, 1); // bottom left
lcd.print("One: ");
lcd.print(teamOneReadScore);
lcd.setCursor(9, 1); // bottom right
lcd.print("Two: ");
lcd.print(teamTwoReadScore);
}
}
