Sunday, September 24, 2006

HW 2 Attempt

Since I did not get Arduino to work I am posting what I wanted to do with the switch:

Light controller:

Switch 1 toggles from STROBE to CONTINUOUS lighting
Switch 2 turns ligt ON or OFF

Arduino compiled program:

//Light switch

int switchToggle = 5; // Toggles between STROBE or CONTINUOUS
int switchOnOff = 2; // On Off switch
int brightLedPin = 3; // Light source LED
int dimLedPin = 4; // Indicator LED LED INDICATOR => OFF = CONTINUOUS ON = STROBE
int toggleState = 0; // CONTINUOUS = 0 STROBE = 1
int OnOffState = 0; // ON = 1 OFF = 0

void setup() {
pinMode(switchToggle, INPUT); // set the switch pin to be an input
pinMode(switchOnOff, INPUT); // set the switch pin to be an input
pinMode(brightLedPin, OUTPUT); // set the bright LED pin to be an output
pinMode(dimLedPin, OUTPUT); // set the dim LED pin to be an output
}

void loop() {

// Read the switch input:
switchToggle = digitalRead(switchToggle);
switchOnOff = digitalRead(switchOnOff);

//LED INDICATOR OFF = CONTINUOUS, ON = STROBE
if (switchToggle == 0){
digitalWrite(dimLedPin, LOW); // turn off indicator
}
else {
digitalWrite(dimLedPin, HIGH); // turn ion indicator
}

//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 have to check to see if I wired the On/Off toggle switch correctly...

No comments: