Thanks. I tried commenting them out, but I didn't see the warnign go away.
How bad can things get with low memory?
I have a set of functions that reads a 1x4 keypad and displays a two digit su, It works just fine.
Then I have the code you saw, and it works just fine.
But when I combined them, its like the keypad never gets read. If I persist, I can eventually get it to read a digit, but its like everything is going really slow.
Is that due to low memory or bad coding?
// Big thanks to david_2018 on Arduino forum for getting the pointer fun to work
// 11/16/2019 Added keypad input and display of keypad input
#include <TM1637Display.h>
#define CLK 8
#define DIO 9
TM1637Display display(CLK, DIO);
#define key1 5 //connect wire 1 to pin 2
#define key2 4 //connect wire 2 to pin 3
#define key3 3 //connect wire 3 to pin 4
#define key4 2 //connect wire 4 to pin 5
// TO DOs::: Add a time for 30 seconds to see if a second 2 digit code is entered
// This is a safety procaution that allows me to retype the digits in if they are mistyped or miss read.
// After the 30 seconds times out, then turn off or dim the display
#define NUM_ARRAYS 7
#define ARRAY_SIZE 50
#include <HashMap.h>
#include <Arduino.h>
#include <FastLED.h>
#define DATA_PIN 7 //this is the data pin connected to the LED strip. If using WS2801 you also need a clock pin
#define NUM_LEDS 50 //change this for the number of LEDs in the strip
#define COLOR_ORDER RGB
CRGB leds[NUM_LEDS];
const CRGB red = CRGB (255, 0, 0);
const CRGB green = CRGB (0, 255, 0);
const CRGB blue = CRGB(0, 0, 255);
const CRGB orange = CRGB(255, 165, 0);
const CRGB white = CRGB(255, 255, 255);
const CRGB off = CRGB(0, 0, 0);
//define an enum so patterns can be referred to by their names
enum patterns {
RedOnly_leds,
GreenOnly_leds,
BlueOnly_leds,
OrangeOnly_leds,
WhiteOnly_leds,
RGBOW_leds,
AllOff_leds,
NUM_patterns //used to indicate the number of patterns
};
//this array is only needed if you want to print out the names corresponding to the pattern arrays
const char patternNames[][16] = {
"RedOnly_leds",
"GreenOnly_leds",
"BlueOnly_leds",
"OrangeOnly_leds",
"WhiteOnly_leds",
"RGBOW_leds",
"AllOff_leds"
};
// Red, Green, Blue, Orange, White with alternatign offs Sequence
CRGB patternArrays[NUM_patterns][ARRAY_SIZE] = {
// only the RED bulbs (in same position as when all lit)
//RedOnly_leds
{ red, off, off, off, off, off, off, off, off, off, off, off,
red, off, off, off, off, off, off, off, off, off, off, off,
red, off, off, off, off, off, off, off, off, off, off, off,
red, off, off, off, off, off, off, off, off, off, off, off,
red, off
},
// only the GREEN bulbs (in same poistion as when all lit)
//GreenOnly_leds
{ off, off, green, off, off, off, off, off, off, off, off, off,
off, off, green, off, off, off, off, off, off, off, off, off,
off, off, green, off, off, off, off, off, off, off, off, off,
off, off, green, off, off, off, off, off, off, off, off, off,
off, green
},
// only the BLUE bulbs (in same poistion as when all lit)
//BlueOnly_leds
{ off, off, off, off, blue, off, off, off, off, off, off, off,
off, off, off, off, blue, off, off, off, off, off, off, off,
off, off, off, off, blue, off, off, off, off, off, off, off,
off, off, off, off, blue, off, off, off, off, off, off, off,
off, off
},
// only the ORANGE bulbs (in same poistion as when all lit)
//OrangeOnly_leds
{ off, off, off, off, off, off, orange, off, off, off, off, off,
off, off, off, off, off, off, orange, off, off, off, off, off,
off, off, off, off, off, off, orange, off, off, off, off, off,
off, off, off, off, off, off, orange, off, off, off, off, off,
off, off
},
// only the WHITE bulbs (in same poistion as when all lit)
//WhiteOnly_leds
{ off, off, off, off, off, off, off, off, white, off, off, off,
off, off, off, off, off, off, off, off, white, off, off, off,
off, off, off, off, off, off, off, off, white, off, off, off,
off, off, off, off, off, off, off, off, white, off, off, off,
off, off
},
//RGBOW_leds
{ red, off, green, off, blue, off, orange, off, white, off, green, off,
red, off, green, off, blue, off, orange, off, white, off, green, off,
red, off, green, off, blue, off, orange, off, white, off, green, off,
red, off, green, off, blue, off, orange, off, white, off, green, off,
red, green
},
//AllOff_leds
{ off, off, off, off, off, off, off, off, off, off, off, off,
off, off, off, off, off, off, off, off, off, off, off, off,
off, off, off, off, off, off, off, off, off, off, off, off,
off, off, off, off, off, off, off, off, off, off, off, off,
off, off
}
};
patterns i;
void setup( void )
{
Serial.begin(9600);
FastLED.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); //setting up the FastLED
pinMode(key1, INPUT_PULLUP);// set pin as input
pinMode(key2, INPUT_PULLUP);// set pin as input
pinMode(key3, INPUT_PULLUP);// set pin as input
pinMode(key4, INPUT_PULLUP);// set pin as input
display.setSegments(0); //Turn off / clear all display segments
display.setBrightness(7);
}
int keypressed = 0;
int keystroke_counter = 0; // counts how many key strokes have been recorded
int keypad_total = 0; // this is the total of the keypad entries added as a two digit value
void loop( void )
{
static byte last_key1S = 1;
static byte last_key2S = 1;
static byte last_key3S = 1;
static byte last_key4S = 1;
byte key1S = digitalRead(key1);// read key1
byte key2S = digitalRead(key2);// read key2
byte key3S = digitalRead(key3);// read key3
byte key4S = digitalRead(key4);// read key4
// Set lights manually to RGBOW colors at the start
memcpy (leds, patternArrays[RGBOW_leds], sizeof patternArrays[RGBOW_leds]);
FastLED.show();
delay(5000);
//
// Read and display user 2 digit input
//
Serial.println( "got here to key loop" );
if (key1S != last_key1S) {
if (key1S == 0) { //went from HIGH to LOW
Serial.println("key 1 is pressed");
keypressed = 1;
keystroke_counter = keystroke_counter + 1;
}
}
last_key1S = key1S;
if (key2S != last_key2S) {
if (key2S == 0) { //went from HIGH to LOW
Serial.println("key 2 is pressed");
keypressed = 2;
keystroke_counter = keystroke_counter + 1;
}
}
last_key2S = key2S;
if (key3S != last_key3S) {
if (key3S == 0) { //went from HIGH to LOW
Serial.println("key 3 is pressed");
keypressed = 3;
keystroke_counter = keystroke_counter + 1;
}
}
last_key3S = key3S;
if (key4S != last_key4S) {
if (key4S == 0) { //went from HIGH to LOW
Serial.println("key 1 is pressed");
keypressed = 4;
keystroke_counter = keystroke_counter + 1;
}
}
last_key4S = key4S;
Serial.println("keystroke_counter total is ");
Serial.println(keystroke_counter);
if (keystroke_counter == 1) {
keypad_total = keypressed * 10;
}
else if (keystroke_counter == 2) {
keypad_total = keypad_total + keypressed;
}
else {
Serial.println("keypad total is ");
Serial.println(keypad_total);
}
if (keystroke_counter == 2) {
Serial.println("keypad total is ");
Serial.println(keypad_total);
// Show decimal numbers with/without leading zeros
display.showNumberDec(keypad_total, false); // Expect: ___keypad_total
delay(5000);
Serial.println(" about to subtract 10");
keypad_total = keypad_total - 10; //Subtract 10 to get answer between 1 and 4
display.showNumberDec(keypad_total, false); // Expect: ___keypad_total
delay(5000);
keystroke_counter = 0; // 2 Digit keystoke received. Reset counter to zero
keypad_total = 0; //// 2 Digit keystoke received. Reset total to zero
}
}
void flash_pattern( patterns pPtr ) { //flash the pattern passed into this function, then off with 4 seconds delay
memcpy (leds, patternArrays[pPtr], sizeof patternArrays[pPtr] );
FastLED.show();
}