Hello guys!
I will ask you for some help. I hvae keypad, arduino mega and four 7Led-segments displays, which I made it. I wrote program but this only works for numbers from 0-9.
So i will need program like this:
Every pass thru loop, check if a key was pressed.
If it was 0-9, save it in dataArray[digitNumber]. If the next key pressed was not #, save it as digit0 again. Keep doing that until # is received, then send dataArray[digitNumber] to the first display, and add 1 to digitNumber.
After the 4th digit is displayed, reset digitNumber back to the first digit. Arrays start at 0, so for 4 digits you would have digitNumber go 0,1,2,3, when it reached 4 you reset to 0.
Or, once a 0-9 key was pressed, immediately display it, but don't move to the next display until # was pressed so the used can confirm the number he pressed was actually accepted.
#include <Keypad.h>
const byte numRows= 4;
const byte numCols= 4;
//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', '+'}
};
byte rowPins[numRows] = {13,12,11,10}; //Rows 0 to 4
byte colPins[numCols]= {9,8,7,6}; //Columns 0 to 4
//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
#define lr1 14// red
#define lr2 15
#define lr3 16
#define lr4 17
#define lr5 18
#define lr6 19
#define lr7 20
#define lr8 21
#define lr9 22
#define lr10 23
#define lr11 24
#define lr12 25
#define lr13 26
#define lr14 27
#define lz1 28 // green
#define lz2 29
#define lz3 30
#define lz4 31
#define lz5 32
#define lz6 33
#define lz7 34
#define lz8 35
#define lz9 36
#define lz10 37
#define lz11 38
#define lz12 39
#define lz13 40
#define lz14 41
void setup()
{
pinMode(lr1, OUTPUT);
pinMode(lr2, OUTPUT);
pinMode(lr3, OUTPUT);
pinMode(lr4, OUTPUT);
pinMode(lr5, OUTPUT);
pinMode(lr6, OUTPUT);
pinMode(lr7, OUTPUT);
pinMode(lr8, OUTPUT);
pinMode(lr9, OUTPUT);
pinMode(lr10, OUTPUT);
pinMode(lr11, OUTPUT);
pinMode(lr12, OUTPUT);
pinMode(lr13, OUTPUT);
pinMode(lr14, OUTPUT);
pinMode(lz1, OUTPUT);
pinMode(lz2, OUTPUT);
pinMode(lz3, OUTPUT);
pinMode(lz4, OUTPUT);
pinMode(lz5, OUTPUT);
pinMode(lz6, OUTPUT);
pinMode(lz7, OUTPUT);
pinMode(lz8, OUTPUT);
pinMode(lz9, OUTPUT);
pinMode(lz10, OUTPUT);
pinMode(lz11, OUTPUT);
pinMode(lz12, OUTPUT);
pinMode(lz13, OUTPUT);
pinMode(lz14, OUTPUT);
digitalWrite(lr1,LOW);
digitalWrite(lr2,LOW);
digitalWrite(lr3, LOW);
digitalWrite(lr4, LOW);
digitalWrite(lr5, LOW);
digitalWrite(lr6, LOW);
digitalWrite(lr7, LOW);
digitalWrite(lr8, LOW);
digitalWrite(lr9, LOW);
digitalWrite(lr10, LOW);
digitalWrite(lr11, LOW);
digitalWrite(lr12, LOW);
digitalWrite(lr13, LOW);
digitalWrite(lr14, LOW);
digitalWrite(lz1, LOW);
digitalWrite(lz2, LOW);
digitalWrite(lz3, LOW);
digitalWrite(lz4, LOW);
digitalWrite(lz5, LOW);
digitalWrite(lz6, LOW);
digitalWrite(lz7, LOW);
digitalWrite(lz8, LOW);
digitalWrite(lz9, LOW);
digitalWrite(lz10, LOW);
digitalWrite(lz11, LOW);
digitalWrite(lz12, LOW);
digitalWrite(lz13, LOW);
digitalWrite(lz14, LOW);
Serial.begin(9600);
}
void loop()
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
switch (keypressed)
{
case '*':
digitalWrite(lr1,LOW);
digitalWrite(lr2,LOW);
digitalWrite(lr3, LOW);
digitalWrite(lr4, LOW);
digitalWrite(lr5, LOW);
digitalWrite(lr6, LOW);
digitalWrite(lr7, LOW);
break;
case '0':
digitalWrite(lr1,LOW);
digitalWrite(lr2,LOW);
digitalWrite(lr3, LOW);
digitalWrite(lr4, LOW);
digitalWrite(lr5, LOW);
digitalWrite(lr6, LOW);
break;
case '1':
digitalWrite(lr2, HIGH);
digitalWrite(lr3, HIGH);
break;
case '2':
digitalWrite(lr1, HIGH);
digitalWrite(lr2, HIGH);
digitalWrite(lr7, HIGH);
digitalWrite(lr5, HIGH);
digitalWrite(lr4, HIGH);
break;
case '3':
digitalWrite(lr1, HIGH);
digitalWrite(lr2, HIGH);
digitalWrite(lr7, HIGH);
digitalWrite(lr3, HIGH);
digitalWrite(lr4, HIGH);
break;
case '4':
digitalWrite(lr6, HIGH);
digitalWrite(lr7, HIGH);
digitalWrite(lr2, HIGH);
digitalWrite(lr3, HIGH);
break;
case '5':
digitalWrite(lr1, HIGH);
digitalWrite(lr6, HIGH);
digitalWrite(lr7, HIGH);
digitalWrite(lr3, HIGH);
digitalWrite(lr4, HIGH);
break;
case '6':
digitalWrite(lr1, HIGH);
digitalWrite(lr5, HIGH);
digitalWrite(lr7, HIGH);
digitalWrite(lr3, HIGH);
digitalWrite(lr4, HIGH);
digitalWrite(lr6, HIGH);
break;
case '7':
digitalWrite(lr1, HIGH);
digitalWrite(lr2, HIGH);
digitalWrite(lr3, HIGH);
break;
case '8':
digitalWrite(lr1, HIGH);
digitalWrite(lr2, HIGH);
digitalWrite(lr3, HIGH);
digitalWrite(lr4, HIGH);
digitalWrite(lr5, HIGH);
digitalWrite(lr6, HIGH);
digitalWrite(lr7, HIGH);
break;
case '9':
digitalWrite(lr1, HIGH);
digitalWrite(lr2, HIGH);
digitalWrite(lr7, HIGH);
digitalWrite(lr3, HIGH);
digitalWrite(lr4, HIGH);
digitalWrite(lr6, HIGH);
break;
default:
Serial.print(keypressed);
}
}
}