Hello everyone. I have written a program that uses a simple hardware interface with one button, which when pressed by the user, initiates a sequence of flashing LEDs over a short time and only after an elapsed period of pause. The user then cannot press the button to create another sequence within the specified pause time, which I have set to 10 seconds. There are also two separate LEDs to show whether the pause has elapsed, i.e. if the system is "armed."
I created my LED sequence with a function in my program that uses delays and HIGH/LOW to create the LED flashes. I would instead like to read text files from an SD card, and have my program sequenctially pick from these files to generate the sequence of lights.
Here's my program:
#include <Bounce.h>
int MAST = 2; //mast
int YAPORT = 3; //yardarm port side
int YASTBD = 4; //yardarm starboard side
int BOW = 5; //bow
int REDled = 8;
int GREENled = 7;
int ARMED = 0;
//Sequence
int SEQUENCEbutton = 10;
unsigned long SequenceLastFired;
//sequence reset time, during which sequence button will not work after pressed (should be eventually set to 15 minutes)
int SequenceResetTime = 10000;
//button debouncing
Bounce SEQUENCEbouncer = Bounce (SEQUENCEbutton,1);
void setup ()
{
pinMode (MAST, OUTPUT);
pinMode (BOW, OUTPUT);
pinMode (YAPORT, OUTPUT);
pinMode (YASTBD, OUTPUT);
pinMode (SEQUENCEbutton, INPUT);
digitalWrite (MAST, LOW);
digitalWrite (BOW, LOW);
digitalWrite (YAPORT, LOW);
digitalWrite (YASTBD, LOW);
Serial.begin (9600);
}
void loop ()
{
if (ARMED == 0)
{
digitalWrite (REDled, HIGH);
digitalWrite (GREENled, LOW);
}
if (ARMED == 1)
{
digitalWrite (REDled, LOW);
digitalWrite (GREENled, HIGH);
}
if ((millis() - SequenceLastFired) > SequenceResetTime)
{
ARMED = 1;
}
else
{
ARMED = 0;
}
//check for button presses
SEQUENCEbouncer.update();
int SEQUENCEbuttonState = SEQUENCEbouncer.read();
if (SEQUENCEbuttonState == HIGH && (millis() - SequenceLastFired > SequenceResetTime))
{
SEQUENCEfire();
}
Serial.println (ARMED);
}
//=======================SEQUENCE CODE===============================
void SEQUENCEfire ()
{
ARMED = 0;
digitalWrite (REDled, HIGH);
digitalWrite (GREENled, LOW);
//FOGHORN CODE HERE?
delay (1000);
digitalWrite (MAST, HIGH);
delay (100);
digitalWrite (MAST, LOW);
delay (800);
digitalWrite (BOW, HIGH);
delay (100);
digitalWrite (BOW, LOW);
delay (300);
digitalWrite (MAST, HIGH);
digitalWrite (BOW, HIGH);
delay (100);
digitalWrite (MAST, LOW);
digitalWrite (BOW, LOW);
delay (450);
digitalWrite (MAST, HIGH);
delay (100);
digitalWrite (MAST, LOW);
delay (1200);
digitalWrite (BOW, HIGH);
delay (100);
digitalWrite (BOW, LOW);
delay (950);
digitalWrite (MAST, HIGH);
digitalWrite (BOW, HIGH);
delay (100);
digitalWrite (MAST, LOW);
digitalWrite (BOW, LOW);
delay (250);
digitalWrite (MAST, HIGH);
digitalWrite (BOW, HIGH);
delay (100);
digitalWrite (MAST, LOW);
digitalWrite (BOW, LOW);
delay (250);
digitalWrite (MAST, HIGH);
digitalWrite (BOW, HIGH);
delay (100);
digitalWrite (MAST, LOW);
digitalWrite (BOW, LOW);
delay (250);
digitalWrite (MAST, HIGH);
digitalWrite (BOW, HIGH);
delay (100);
digitalWrite (MAST, LOW);
digitalWrite (BOW, LOW);
delay (250);
SequenceLastFired = millis();
}
The above program functions as desired. I will post the new program in a second post in this thread due to size limitations (hope this is OK).