I have a project where some numbers and dashes get entered into a key pad and then get displayed on a 5 digit 7" tall LED display. The displays use a shift register on each digit. I only need to send clock and data, no latch needed. I ended up using a pair of max485 on each end to get the signals to the display with out errors. Power comes from the sign end. Because I am using RS485 chips I can run as many displays as needed (up to around 30 tho I only need 2.)
I used the danger shield shift register and keypad library as a starting point. The finished project has:
10 memory locations stored in eeprom
back space and clear (back space works on the recalled numbers!)
programmable display auto clear
programmable flash count
Here is the code . Comments welcome. Ultimately around 12 systems will be build! I will post pics and other info as requested and as I have time.
Main Loop
/* v8
Created by
Tom Bourke
CWALV LLC.
License granted to base other projects on this code.
Share and share alike.
*/
#include <Keypad.h>
#include <EEPROM.h>
#include "_init.h"
#include "_data.h"
int disp[] = {20, 20, 20, 20, 20}; // display string stored as int
int dispd = 0; // digit we are working on
long interval = 250; // interval at which to blink (milliseconds)
int flashcount = 10; //** how many times to flash
int flashes = 0; // how many times it has left to flash
int flash = 0; // just flashed?
int ledPin = 13; // LED connected to digital pin 13
long previousMillis = 0; // will store last time LED was updated
long disp_time = 10000; //** time to dispalay info, 1000 = 1 second
long last_key_press = 0; // will store last time key was pressed
// ** now set in eeprom
int flashcountlocation = 100; // memory location of flashcount setting
int timeoutlocation = 110; // memory location of timeout setting
void setup()
{
ds_init();
keypad.addEventListener(keypadEvent); // add an event listener for this keypad
pinMode(ledPin, OUTPUT); // keypress LED
}
void loop()
{
recalflashcount(); // update flashcount
recaltimeout(); // update timeout
if (millis() - last_key_press > disp_time) // clear display after time out
{
cleardisplay();
printdisplay();
}
char key = keypad.getKey();
if (key != NO_KEY) // begin keypress loop
{
last_key_press = millis(); // reset keypress counter
digitalWrite(ledPin, HIGH); // turn the keypress LED on
if (dispd < 5) // test if display is full
{
switch (key)
{
case '1':
disp[dispd] = 1;
dispd++;
break;
case '2':
disp[dispd] = 2;
dispd++;
break;
case '3':
disp[dispd] = 3;
dispd++;
break;
case '4':
disp[dispd] = 4;
dispd++;
break;
case '5':
disp[dispd] = 5;
dispd++;
break;
case '6':
disp[dispd] = 6;
dispd++;
break;
case '7':
disp[dispd] = 7;
dispd++;
break;
case '8':
disp[dispd] = 8;
dispd++;
break;
case '9':
disp[dispd] = 9;
dispd++;
break;
case '0':
disp[dispd] = 0;
dispd++;
break;
case 'a': //read mem location
readmem();
break;
case 'b': //write mem location
recordmem();
break;
case 'c': // delete last digit entered
if (dispd > 0)
{
dispd = dispd -1;
if (disp[dispd] > 9)
{
disp[dispd] = disp[dispd] -10;
dispd++;
}
else
{
disp[dispd] = 20;
}
}
break;
case 'd': // add dash to previous digit
dash();
break;
case '#': // clear display
cleardisplay();
break;
case '*':
flashes = flashcount;
if (dispd == 0)
{
disp[0] = 18;
disp[1] = 18;
disp[2] = 18;
disp[3] = 18;
disp[4] = 8;
dispd = 5;
}
break;
}
}
else // if display is full we can still do this stuff
{
switch (key)
{
case 'a': //read mem location
readmem();
break;
case 'b': //write mem location
recordmem();
break;
case 'c': // delete last digit entered
if (dispd > 0)
{
dispd = dispd -1;
if (disp[dispd] > 9)
{
disp[dispd] = disp[dispd] -10;
dispd++;
}
else
{
disp[dispd] = 20;
}
}
break;
case '#': // clear display
cleardisplay();
break;
case '*': // flash
flashes = flashcount;
break;
}
}
printdisplay();
} // end of keypress loop
if (flashes > 0) // flash LED display if needed
{
flash = 1;
if (millis() - previousMillis > interval)
{
previousMillis = millis(); // save the last time you blinked the LED
flashes = flashes -1;
blankdisplay();
delay (100);
}
else
{
printdisplay();
}
}
else
{
if (flash != 0)
{
flash = 0;
printdisplay();
}
}
delay (20);
digitalWrite(ledPin, LOW); // turn the keypress LED off
// debug info
/* Serial.print("dispd");
Serial.print(" ");
Serial.print(dispd);
Serial.print(" ");
Serial.print("disp");
Serial.print(" ");
Serial.print(disp[0]);
Serial.print(" ");
Serial.print(disp[1]);
Serial.print(" ");
Serial.print(disp[2]);
Serial.print(" ");
Serial.print(disp[3]);
Serial.print(" ");
Serial.print(disp[4]);
Serial.print(" ");
Serial.print(flashes);
Serial.println(" ");
*/
} // end of main loop