// Project 1 example ... Set up an 4 LED navigation controller
// abp 10.7.17
const int timebase = 500; // set a 500ms timebase for state changes
const int LED1 = 5; // assign I/O pins
const int LED2 = 6;
const int LED3 = 7;
const int LED4 = 8;
int tick_clk = 1; // time base counter
int time1 = 1; // secondary time base for group sequence
int buoy4_state = 0; // buoy is a Green FL 4
int buoy3_state = 0; // buoy is a Green FL 2.5
int buoy2_state = 0; // buoy is a Red QF
int buoy1_state = 0; // buoy is a Red FL( 2+ 1) 6s
void setup()
{
pinMode(LED1, OUTPUT); // Set port modes
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
Serial.begin(9600); // opens serial port for debug
}
void loop()
{
// buoy 4 is Green FL4 flash 500ms off 3500ms 0 0 0 0 0 0 0 1...
if (tick_clk %8 == 0 ) // buoy 4 is Green FL4 flash 500ms off 3500ms
{
buoy4_state = 1;
}
else
{
buoy4_state = 0;
}
//buoy 3 is Green FL 2.5 flash 500ms off 2000ms 0 0 0 0 1....
if (tick_clk %5 == 0 )
{
buoy3_state = 1;
}
else
{
buoy3_state = 0;
}
//buoy 2 is Red QF flash 500ms off 5000ms 0 1 0 1 0 1 ....
if (tick_clk %2 == 0 ) //bouy 2 is Red QF flash 500ms off 5000ms
{
buoy2_state = 1;
}
else
{
buoy2_state = 0;
}
//buoy 1 is Red group flash ( 2+1 )6 sec 0 0 0 0 0 0 1 0 1 0 0 1....
// need seconday time check to keep bounded by 12 because of sequence
if (time1 > 12)
{
time1 = 1; // reset to keep intervals of 12 samples
}
if (time1 %7 == 0 || time1 %9 == 0 || time1 %12 == 0 )
{
buoy1_state = 1;
}
else
{
buoy1_state = 0;
}
tick_clk++;
time1++;
control(buoy1_state, buoy2_state, buoy3_state, buoy4_state);
}
void control(int led1, int led2, int led3, int led4 )
{
digitalWrite(LED1,led1); // output states provided to pins
digitalWrite(LED2,led2);
digitalWrite(LED3,led3);
digitalWrite(LED4,led4);
delay(timebase);
}