Hello,
I am trying to use Unsigned Long to be able to turn on 5 different zone arrays of LED's in sequence with the first Zone coming on and staying on until all 5 zones have lit up. I tried using Delay function but that will not work for my application. I need Zone 1 to come on, then 1.2 seconds later, Zone 2, then 1.2 seconds later Zone 3, etc, through Zone 5. Then after all 5 zones are ON for 20 seconds, turn ALL off. Using Arduino Uno with PWM outputs driving relays for LED arrays. I can get it to drive arrays in sequence using Delay but it does not work properly. Please check my code...I keep getting 'else without a previous if' error in void loop( ). I only have two arrays connected right now for testing but I can't move forward without getting rid of this error. Hopefully it is only a syntax error but I can't figure it out. Please help.
/*
AHC 5 Zone LED Relay Circuit With Reset Button
Turns on and off 5 Zone LED Arrays and pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
- LED attached from pin 13 to ground
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from switch ground
*/
// Constants used here to set pin numbers:
const int buttonPin = 2; // Pushbutton Input Pin
const int ledPin = 13; // Built In LED pin
const int relayPin1 = 3; // Output Pin for Zone 1
const int relayPin2 = 5; // Output Pin for Zone 2
const int relayPin3 = 6; // Output Pin for Zone 3
const int relayPin4 = 9; // Output Pin for Zone 4
const int relayPin5 = 10; // Output Pin for Zone 5
const unsigned long zone1interval = 10800; //Zone 1 On Time Interval
const unsigned long zone2interval = 9600; //Zone 2 On Time Interval
const unsigned long zone3interval = 8400; //Zone 3 On Time Interval
const unsigned long zone4interval = 7200; //Zone 4 On Time Interval
const unsigned long zone5interval = 6000; //Zone 5 On Time Interval
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
unsigned long push_button; //user Pushes Button
unsigned long zone1time;
unsigned long zone2time;
unsigned long zone3time;
unsigned long zone4time;
unsigned long zone5time;
void setup() {
// initialize the LED pins as Zone Outputs:
//Pin 3 is Zone 1
//Pin 5 is Zone 2
//Pin 6 is Zone 3
//Pin 9 is Zone 4
//Pin 10 is Zone 5
pinMode(ledPin, OUTPUT);
pinMode(relayPin1, OUTPUT); //Zone 1
pinMode(relayPin2, OUTPUT); //Zone 2
pinMode(relayPin3, OUTPUT); //Zone 3
pinMode(relayPin4, OUTPUT); //Zone 4
pinMode(relayPin5, OUTPUT); //Zone 5
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
zone1time=millis(); //Sets Zone Intervals to milliseconds
zone2time=millis();
zone3time=millis();
zone4time=millis();
zone5time=millis();
} //End Of Setup
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH);
// turn LED's on by Zone
digitalWrite(ledPin, HIGH);
digitalWrite(relayPin1, HIGH);
zone1time=millis();
digitalWrite(relayPin2, HIGH);
zone2time=millis();
digitalWrite(relayPin3, HIGH);
digitalWrite(relayPin4, HIGH);
digitalWrite(relayPin5, HIGH);
else
digitalWrite(relayPin1, LOW);
digitalWrite(relayPin2, LOW);
digitalWrite(relayPin3, LOW);
digitalWrite(relayPin4, LOW);
digitalWrite(relayPin5, LOW);
} //End of Loop