Sorry, did'ent think about it...
byte ledPins[] = {
5, 6, 7, 8};
void light1(){
byte ledLighting[7][4] = {
{
1, 1, 1, 1 }
,
{
0, 0, 0, 0 }
,
{
0, 0, 0, 1 }
,
{
0, 0, 1, 1 }
,
{
0, 1, 1, 1 }
,
{
1, 1, 1, 1 }
,
{
0, 0, 0, 0 }
};
int ledMillis[7][4] = {
{
1000, 500, 500, 500 }
,
{
1000, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
1000, 0, 0, 0 }
};
}
void light2(){
byte ledLighting2[7][4] = {
{
1, 1, 1, 1 }
,
{
0, 0, 0, 0 }
,
{
1, 0, 0, 1 }
,
{
0, 0, 1, 1 }
,
{
0, 1, 1, 1 }
,
{
1, 1, 0, 0 }
,
{
0, 0, 0, 0 }
};
int ledMillis2[7][4] = {
{
1000, 500, 500, 500 }
,
{
1000, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
500, 0, 0, 0 }
,
{
1000, 0, 0, 0 }
};
}
byte numSequences = 7;
byte numLeds = 4;
int ledSequenceNum = 0; // this is used in two functions
boolean ledSequenceDone = false;
int maxSeq = 2;
int sequence = 1;
//Here we handle the Globals of the button
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
const int buttonPin = 2; // the number of the pushbutton pin
void setup() {
Serial.begin(9600);
Serial.println("Starting LedSequence.ino");
for(byte n = 0; n < numLeds; n++){
pinMode(ledPins[n], OUTPUT);
}
}
void loop() {
readSwitchesAndSaveValues();
selectSequence();
implementSequence();
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
if(sequence == maxSeq)
{
sequence = 1;
}
else
{
sequence++;
}
switch(sequence)
{
case 1:
light1();
break;
case 2:
light2();
break;
}
}
}
void selectSequence() {
if (ledSequenceDone == true) {
ledSequenceNum ++;
if (ledSequenceNum >= numSequences) {
ledSequenceNum = 0;
}
ledSequenceDone = false;
}
}
void implementSequence() {
static byte ledNum; // static variables hold their value
static unsigned long lastLedOn;
static unsigned long ledInterval;
int ledLights;
int ledTimes;
unsigned long currentMillis = millis();
if (currentMillis - lastLedOn >= ledInterval) { // the usual time check
lastLedOn += ledInterval; // save the current time
digitalWrite(ledPins[ledNum], ledLights[ledSequenceNum][ledNum]); // light an led
ledNum ++; // move on to the next in the sequence
if (ledNum >= 4) {
ledNum = 0;
ledSequenceDone = true;
}
ledInterval = ledTimes[ledSequenceNum][ledNum];
}
}
void readSwitchesAndSaveValues(){
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
}
}
{
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}
}