Well I'm at this point:
/*
Using 8 outputs and saving output presets in the EEPROM
*/
#include <Keypad.h> //Inlcude Keypad Library
#include <EEPROM.h> //Include EEPROM Library
#include <DigitalToggle.h> //Include DigitalToggle Library
int ledPins[] = {
0,1,2,3,4,5,6,7}; //Defining program mode Leds
int bypassled = 11; //Defining the bypass Led
int latchPin = 14; //Defining latchPin from the 74HC595
int clockPin = 15; //Defining clockPin from the 74HC595
int dataPin = 13; //Defining dataPin from the 74HC595
const byte filas = 4; // rows of the Keypad
const byte colus = 4; // columns of the Keypad
char teclas[filas][colus] = { //mapping the Keypad layout
{
'1', '2', '3', '4' }
,
{
'5', '6', '7', '8' }
,
{
'9', '0', 'A', 'B' }
,
{
'C', 'D', 'E', 'F' }
};
// defining the pins that are used for the rows and columns of the Keypad
byte filaPins[filas] = {
16, 17, 18, 19 };
byte coluPins[colus] = {
8, 9, 10, 12 };
Keypad teclado = Keypad( makeKeymap(teclas), filaPins, coluPins, filas, colus );
byte dataOut = 0;
byte valores = B00000000;
int posi = 0;
byte memo0 = B00000000; //the bypass value is always the same, so it's not necessary to save it in the EEPROM
byte memo[] = {
0,5,10,15,20,25,30,35,40,45,50,55,60,65}; // defining the EEPROM adresses
void setup()
{
for(int index = 0; index <= 8; index++) //defining output pins
{
pinMode(ledPins[index], OUTPUT);
}
pinMode(bypassled, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for(int index = 0; index <= 7; index++)
{
digitalWrite(ledPins[index], LOW); // shutdown the programming Leds
}
digitalWrite(bypassled, HIGH); // lighting the bypass Led
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, memo0);
digitalWrite(latchPin, HIGH);
delay(1000); //wait a second........
}
void loop()
{
teclado.setDebounceTime(10);
char key = teclado.getKey();
switch(key) //the key we select sends a memory content assigned to this key
{
case '1':
enviamemo(0);
break;
case '2':
enviamemo(1);
break;
case '3':
enviamemo(2);
break;
case '4':
enviamemo(3);
break;
case '5':
enviamemo(4);
break;
case '6':
enviamemo(5);
break;
case '7':
enviamemo(6);
break;
case '8':
enviamemo(7);
break;
case '9':
enviamemo(8);
break;
case '0':
enviamemo(9);
break;
case 'A':
enviamemo(10);
break;
case 'B':
enviamemo(11);
break;
case 'C':
enviamemo(12);
break;
case 'D':
enviamemo(13);
break;
case 'E':
modobypass(); //In case we select the 'E' key we set the bypass mode
break;
case 'F':
modoPrograma(); //if we select the 'F' key we are entering in the programming mode
break;
}
}
void modoPrograma()
{
digitalWrite(bypassled, LOW);
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, memo0);
digitalWrite(latchPin, HIGH);
delay(500);
for (int i = 0; i <= 2; i++)
{
for(int index = 0; index <= 7; index++)
{
digitalWrite(ledPins[index], HIGH); // we make blink the programming Leds three times, so we know that we are entering programming mode
}
delay(500);
for(int index = 0; index <= 7; index++)
{
digitalWrite(ledPins[index], LOW);
}
delay(500);
}
}
{
char key;
do
{
key = teclado.getKey();
switch(key)
{
case '1': //Now we select which outputs we want to have ON or OFF
digitalToggle(ledPins[0]);
break; //The programming Leds shows us which Output will be ON or OFF
case '2': //in the preset, every Led corresponds to an Output.
digitalToggle(ledPins[1]);
break; //we use the digitalToggle library to change the state of each Led
case '3':
digitalToggle(ledPins[2]);
break;
case '4':
digitalToggle(ledPins[3]);
break;
case '5':
digitalToggle(ledPins[4]);
break;
case '6':
digitalToggle(ledPins[5]);
break;
case '7':
digitalToggle(ledPins[6]);
break;
case '8':
digitalToggle(ledPins[7]);
break;
}
}
while (key != 'E'); //If we press the 'E' key we go to the next step
}
posi = 0; //we reset posi
valores = B00000000; //we reset valores
for(int i=0; i <= 7; i++) //we save every Led state in the byte valores
{
bitWrite(valores, posi, digitalRead (ledPins[i]));
posi = posi + 1;
}
guardamemoria(valores); // calling the save function
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, memo0);
digitalWrite(latchPin, HIGH);
delay(500);
for (int i = 0; i <= 2; i++)
{
for(int index = 0; index <= 7; index++)
{
digitalWrite(ledPins[index], HIGH); // we make blink the programming Leds three times, so we know that we are exiting programming mode
}
delay(500);
for(int index = 0; index <= 7; index++)
{
digitalWrite(ledPins[index], LOW);
}
delay(500);
}
}
}
void guardamemoria(byte valores) //function to save the byte valores in the EEPROM, this byte contains the preset information that we have programmed
{
char key;
do
{
char key = teclado.getKey(); //HERE IS WHERE THE ARDUINO STAYS FOREVER AND IT DOESN'T EXIT, IT DOESN'T MATTER WHICH KEY I PRESS!!!!!
switch(key) //Now we select in which adress of the EEPROM we want to save the Byte value
{
case '1':
grabamemo(0, valores);
break;
case '2':
grabamemo(1, valores);
break;
case '3':
grabamemo(2, valores);
break;
case '4':
grabamemo(3, valores);
break;
case '5':
grabamemo(4, valores);
break;
case '6':
grabamemo(5, valores);
break;
case '7':
grabamemo(6, valores);
break;
case '8':
grabamemo(7, valores);
break;
case '9':
grabamemo(8, valores);
break;
case '0':
grabamemo(9, valores);
break;
case 'A':
grabamemo(10, valores);
break;
case 'B':
grabamemo(11, valores);
break;
case 'C':
grabamemo(12, valores);
break;
case 'D':
grabamemo(13, valores);
break;
}
}
while (key != 'F');
}
void grabamemo(int pos, byte valores) //saving to the EEPROM function
{
EEPROM.write(memo[pos], valores);
}
void enviamemo(int pos) //function to send the preset saved on the EEPROM adress to the 74HC595
{
digitalWrite(bypassled, LOW);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, memo[pos]);
digitalWrite(latchPin, HIGH);
}
void modobypass()
{
digitalWrite(bypassled, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, memo0);
digitalWrite(latchPin, HIGH);
}
Sometimes I'm really thinking about the "easy option" using a bigger Atmel microcontroller........