Tuesday, September 26, 2006

Light House project

Light house controller that controls how long light stays ON and OFF.

LEDs indicate if you are increasing or decreasing ON and OFF times.

Brigth LED is the Light House beacon.

Here is the program:

//Light Houes Controller

//Swtiches
int switchONMore = 2; // Increases ON time
int switchONLess = 3; // Decreases ON time
int switchOFFMore = 4; // Increases OFF time
int switchOFFLess = 5; // Decreases OFF time

//LEDs
int LightHouseLed = 6; //Beacon
int OnMoreLed = 7; // ON MORE LED
int OnLessLed = 8; // ON LESS LED
int OffMoreLed = 9; // OFF MORE LED
int OffLessLed = 10; // OFF LED 1

//Variables
int OnTime; //Time light will be ON - 0 to 3 (short to long)
int OffTime; //Time ligth wlll be OFF - 0 to 3 (short to long)
int OnMore; //Increase OnTime
int OnLess; //Decrease OnTime
int OffMore; //Increase OffTime
int OffLess; //Decrease OffTime
int IndLight = 3000; //Indicator light time

void setup() {
//Set Input Pins
pinMode(switchONMore, INPUT); // set the switch pin to be an input
pinMode(switchONLess, INPUT); // set the switch pin to be an input
pinMode(switchOFFMore, INPUT); // set the switch pin to be an input
pinMode(switchOFFLess, INPUT); // set the switch pin to be an input

//Set Output Pins
pinMode(LightHouseLed, OUTPUT); //Lighthouse beacon LED
pinMode(OnMoreLed, OUTPUT); // set LED to be an output
pinMode(OnLessLed, OUTPUT); // set LED to be an output
pinMode(OffMoreLed, OUTPUT); // set LED to be an output
pinMode(OffLessLed, OUTPUT); // set LED to be an output
}

void loop() {
// Read the switch inputs:
OnMore = digitalRead(switchONMore);
OnLess = digitalRead(switchONLess);
OffMore = digitalRead(switchOFFMore);
OffLess = digitalRead(switchOFFLess);

//Increase or decrease timers and indicate on LED
if (OnMore == 1){
OnTime = OnTime + 1;
digitalWrite(OnMoreLed, HIGH); // turn ON indicator
delay(IndLight);
digitalWrite(OnMoreLed, LOW); // turn OFF indicator
}
if (OnLess == 1){
OnTime = OnTime - 1;
digitalWrite(OnLessLed, HIGH); // turn ON indicator
delay(IndLight);
digitalWrite(OnLessLed, LOW); // turn OFF indicator
}
if (OffMore == 1){
OffTime = OffTime + 1;
digitalWrite(OffMoreLed, HIGH); // turn ON indicator
delay(IndLight);
digitalWrite(OffMoreLed, LOW); // turn OFF indicator
}
if (OffLess == 1){
OffTime = OffTime - 1;
digitalWrite(OffLessLed, HIGH); // turn ON indicator
delay(IndLight);
digitalWrite(OffLessLed, LOW); // turn OFF indicator
}

//Blink LightHouse beacon
digitalWrite(LightHouseLed, HIGH); // turn ON beacon
delay(OnTime);
digitalWrite(LightHouseLed, LOW); // turn ON beacon
delay(OffTime);

/*
//STROBE routine
while (switchOnOff == 1 && switchToggle == 1){
//ON and on STROBE
digitalWrite(brightLedPin, HIGH); // turn on LED
delay(3000);
digitalWrite(brightLedPin, LOW); // turn off LED
}

//CONTINUOUS MODE
if (switchOnOff == 1 && switchToggle == 0) {
digitalWrite(brightLedPin, HIGH); // turn on LED
}
else {
digitalWrite(brightLedPin, LOW); // turn off LED
}
*/
}

Now to the wiring!

No comments: