I tried to remove some excess blank lines and give it a saner indentation...
//Interrupt implemenation.
const int led = 13;
const int zone1 = 8;
const int zone2 = 9;
const int zone3 = 10;
const int zone4 = 11;
const int in1 = 2; //Interrupt 0;
const int in2 = 3; //Interrupt 1;
int ledState = LOW;
int buttonState =0;
unsigned long previousMillis = 0,preM1=0,preM2=0,preM3=0,preM4=0,preMS=0,preInt=0,preUni;
long interval = 1000;
unsigned long UniTime = 1000; //60*60*60*1000;
int StateCheck =1;
int StateCheck2 =0;
int ZoneCheck=1,ZoneCopy=1;
int i=0;
int Track=0,Track1=0,Track2=0,Track3=0,Track4=0,TrackS,TrackUni;
unsigned long PreMcounter =0;
unsigned long MilliCounter =0;
void setup() {
// digital pins=output
pinMode(led, OUTPUT);
pinMode(zone1, OUTPUT);
pinMode(zone2, OUTPUT);
pinMode(zone3, OUTPUT);
pinMode(zone4, OUTPUT);
pinMode(in1, INPUT);
pinMode(in2, INPUT);
attachInterrupt(0, StateChange, LOW);
attachInterrupt(1, Check, LOW);
}
void loop() {
switch (ZoneCheck) {
case 1:
if (StateCheck == 1) {
Flash();
Zone1F(UniTime);
}
else {
digitalWrite(zone1, LOW);
}
break;
case 2:
if (StateCheck == 1) {
Flash();
Zone2F(UniTime);
}
else {
digitalWrite(zone2, LOW);
}
break;
case 3:
if (StateCheck == 1) {
Flash();
Zone3F(UniTime);
}
else {
digitalWrite(zone3, LOW);
}
break;
case 4:
if (StateCheck == 1) {
Flash();
Zone4F(UniTime);
}
else{
digitalWrite(zone4, LOW);
}
break;
case 5:
if (StateCheck == 2) {
ZoneCopy = ZoneCheck;
Zone1F(10000);
}
break;
}
Flash();
}
//----------------------------------------------------------------------------
//Special Zone function on Zone1
int ZoneSpec1(int c)
{
if (TrackS==0)
{
preMS = millis();
TrackS=1;
}
unsigned long curMS = millis();
if(curMS - preMS < c)
{
digitalWrite(zone1, HIGH);
digitalWrite(zone2, LOW);
digitalWrite(zone3, LOW);
digitalWrite(zone4, LOW);
}
else
{
digitalWrite(zone1, LOW);
TrackS =0;
StateCheck = 0;
}
}
//----------------------------------------------------------------------------
//Zone Functions
int Zone1F(int c)
{
if (Track1==0)
{
preM1 = millis();
Track1=1;
}
unsigned long curM1 = millis();
if(curM1 - preM1 < c)
{
digitalWrite(zone1, HIGH);
}
else if (curM1 - preM1 > c)
{
digitalWrite(zone1, LOW);
Track1 =0;
ZoneCheck = 2;
}
}
//---------------------------------------------------------------------------------
int Zone2F(int c)
{
if (Track2==0)
{
preM2 = millis();
Track2=1;
}
unsigned long curM2 = millis();
if(curM2 - preM2 < c)
{
digitalWrite(zone2, HIGH);
}
else
{
digitalWrite(zone2, LOW);
Track2 =0;
ZoneCheck = 3;
}
}
//-----------------------------------------------------------------------------------
int Zone3F(int c)
{
if (Track3==0)
{
preM3 = millis();
Track3=1;
}
unsigned long curM3 = millis();
if(curM3 - preM3 < c)
{
digitalWrite(zone3, HIGH);
}
else
{
digitalWrite(zone3, LOW);
Track3 = 0;
ZoneCheck = 4;
}
}
//-------------------------------------------------------------------------------------
int Zone4F(int c)
{
if (Track4==0)
{
preM4 = millis();
Track4=1;
}
unsigned long curM4 = millis();
if(curM4 - preM4 < c)
{
digitalWrite(zone4, HIGH);
}
else
{
digitalWrite(zone4, LOW);
Track4 =0;
ZoneCheck = 1;
StateCheck = 0;
}
}
//---------------------------------------------------------------------------------------------
//LEDBlink Storie
void Flash()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led, ledState);
}
}
//----------------------------------------------------------------------------------------------
//PORTED CODE !
void Check()
{
ZoneCopy = ZoneCheck;
if (StateCheck == 0)
{
StateCheck = 2;
ZoneCheck = 5;
// digitalWrite(led, HIGH);
detachInterrupt(1);
attachInterrupt(1, Check, LOW);
}
else if(StateCheck == 1)
{
StateCheck = 2;
ZoneCheck = 5;
// digitalWrite(led, LOW);
detachInterrupt(1);
attachInterrupt(1, Check, LOW);
}
}
//--------------------------------------------------------------------------------------------------
int UniDelay(int c)
{
int i=0;
if (TrackUni==0)
{
preUni = millis();
TrackUni=1;
}
int t = (c*10000);
unsigned long curUni = millis();
if(curUni - preUni < t)
{
i++;
}
else
{
TrackUni =0;
}
}
//--------------------------------------------------------------------------------------------------
/* void StateCheck(int x)
{
for (int i=0;i<x+1;i++)
{
if (StateCheck == 1)
{}
else if(StateCheck == 0)
{break;}
}
}*/
/*
int Zone1F(int c)
{
unsigned long preM = previousMillis;
unsigned long curM = millis();
if ((curM - preM) <= c)
{
curM = millis();
digitalWrite(zone1, HIGH);
//StateChange();
ZoneCheck = 1;
previousMillis = preM;
}
else if ((curM - preM) > c)
{
digitalWrite(zone1, LOW);
//StateChange()
ZoneCheck = 2;
previousMillis = preM;
}
}
*/
void StateChange()
{
if (StateCheck == 0)
{
StateCheck = 1;
Track =0;
// digitalWrite(led, HIGH);
}
else if(StateCheck == 1) {
StateCheck = 0;
//digitalWrite(led, LOW);
}
}
Uh ?
detachInterrupt(1);
attachInterrupt(1, Check, LOW);
Still quite puzzling code, especially without any comment.
You should either add copious comments or describe what you're trying to achieve.