thanks again for helping. I am having some issues. I went through the code and found a "(" missing and I had to go through and delete a bunch of spaces so that every thing that should be highlighted would be....... pinMode, digitalWrites, if, case, and so on.
I tried to load the code so I could test it and I'm getting several error codes.
pretty much a bunch of \stray 302 and \stray 240
I changed pin location from the original because i'm using a ProMini at the moment. I also removed the green and red leds from my project
#define Pressed HIGH
#define Released LOW
#define PinOn HIGH
#define PinOff LOW
// outputs
const byte relayPin = 12;
const byte heartBeatLED = 13;
// pulse settings
const byte onTimePin = A0; // pot to determine digitalWrite HIGH
const byte offTimePin = A2; // pot to determin digitalWrite LOW
const byte switchApin = 2; // on/off switch A value of 1 when high
const byte switchBpin = 3; // on/off switch B value of 2 when high
const byte switchCpin = 4; // on/off switch C value of 4 when high
const byte switchDpin = 5; // on/off switch D value of 8 when high
unsigned long delayValueH; // delay high value
unsigned long delayValueL; // delay low value
unsigned long heartBeatMillis;
unsigned long actionMillis;
unsigned long actionDelay;
byte Count;
byte actionCounter;
// input sensors
const byte sensorPin = 9; // on/off sensor
enum STATE {startState, lowState, highState};
STATE ActionState = startState;
// s e t u p ( )
//**********************************************************************
void setup()
{
pinMode(heartBeatLED, OUTPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin,PinOff);
pinMode(GledPin, OUTPUT);
digitalWrite(GledPin,PinOff);
pinMode(RledPin, OUTPUT);
digitalWrite(RledPin, PinOff);
pinMode(sensorPin, INPUT_PULLUP);
pinMode(switchApin, INPUT_PULLUP);
pinMode(switchBpin, INPUT_PULLUP);
pinMode(switchCpin, INPUT_PULLUP);
pinMode(switchDpin, INPUT_PULLUP);
} //END of s e t u p ( )
// l o o p ( )
//**********************************************************************
void loop()
{
//***************************
//HeartBeat LED, should toggle every 200ms 'if the code is nonblocking'
if (millis() - heartBeatMillis >= 200)
{
heartBeatMillis = millis(); //reset timing
//Toggle heartBeatLED
digitalWrite(heartBeatLED,digitalRead(heartBeatLED));
}
//***************************
toggleAction();
} //END of l o o p ( )
//======================================================================
// F U N C T I O N S
//======================================================================
// t o g g l e A c t i o n ( )
//**********************************************************************
void toggleAction()
{
switch (ActionState)
{
//***************************
case startState:
{
if (digitalRead(sensorPin) == Pressed)
{
delayValueH = analogRead(onTimePin);
delayValueL = analogRead(offTimePin);
Count = (digitalRead(switchDpin) * 8) +
(digitalRead(switchCpin) * 4) +
(digitalRead(switchBpin) * 2) +
(digitalRead(switchApin);
actionDelay = delayValueL;
actionMillis = millis();
digitalWrite(relayPin, PinOff);
actionCounter = Count;
ActionState = lowState;
}
}
break;
//***************************
case lowState:
{
if (millis() - actionMillis < actionDelay)
{
break;
}
digitalWrite(relayPin, PinOn);
actionDelay = delayValueH;
actionMillis = millis();
ActionState = highState;
}
break;
//***************************
case highState:
{
if (millis() - actionMillis < actionDelay)
{
break;
}
digitalWrite(relayPin, PinOff);
actionCounter--;
if (actionCounter == 0)
{
ActionState = startState;
break;
}
actionDelay = delayValueL;
actionMillis = millis();
ActionState = lowState;
}
break;
} //End of switch/case
}//End of t o g g l e A c t i o n ( )
//======================================================================
// E N D O F C O D E
//======================================================================
#define Pressed HIGH
#define Released LOW
//#define Pressed LOW //debug
//#define Released LOW //debug
#define PinOn HIGH
#define PinOff LOW
// outputs
const byte relayPin = 12;
const byte heartBeatLED = 13;
// pulse settings
const byte onTimePin = A0; // pot to determine digitalWrite HIGH
const byte offTimePin = A2; // pot to determin digitalWrite LOW
const byte switchApin = 2; // on/off switch A value of 1 when high
const byte switchBpin = 3; // on/off switch B value of 2 when high
const byte switchCpin = 4; // on/off switch C value of 4 when high
const byte switchDpin = 5; // on/off switch D value of 8 when high
unsigned long delayValueH; // delay high value
unsigned long delayValueL; // delay low value
unsigned long heartBeatMillis;
unsigned long actionMillis;
unsigned long actionDelay;
byte Count;
byte actionCounter;
// input sensors
const byte sensorPin = 9; // on/off sensor
enum STATE {startState, lowState, highState};
STATE ActionState = startState;
// s e t u p ( )
//**********************************************************************
void setup()
{
pinMode(heartBeatLED, OUTPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, PinOff);
//pinMode(GledPin, OUTPUT); //this had to be commented
//digitalWrite(GledPin,PinOff); //this had to be commented
//pinMode(RledPin, OUTPUT); //this had to be commented
//digitalWrite(RledPin, PinOff); //this had to be commented
pinMode(sensorPin, INPUT_PULLUP);
pinMode(switchApin, INPUT_PULLUP);
pinMode(switchBpin, INPUT_PULLUP);
pinMode(switchCpin, INPUT_PULLUP);
pinMode(switchDpin, INPUT_PULLUP);
} //END of s e t u p ( )
// l o o p ( )
//**********************************************************************
void loop()
{
//***************************
//HeartBeat LED, should toggle every 200ms 'if the code is nonblocking'
if (millis() - heartBeatMillis >= 200)
{
heartBeatMillis = millis(); //reset timing
//Toggle heartBeatLED
digitalWrite(heartBeatLED, digitalRead(heartBeatLED));
}
//***************************
toggleAction();
} //END of l o o p ( )
//======================================================================
// F U N C T I O N S
//======================================================================
// t o g g l e A c t i o n ( )
//**********************************************************************
void toggleAction()
{
switch (ActionState)
{
//***************************
case startState:
{
if (digitalRead(sensorPin) == Pressed)
{
delayValueH = analogRead(onTimePin);
delayValueL = analogRead(offTimePin);
//delayValueH = 500; //debug
//delayValueL = 200; //debug
Count = (digitalRead(switchDpin) * 8) +
(digitalRead(switchCpin) * 4) +
(digitalRead(switchBpin) * 2) +
(digitalRead(switchApin)); //corrected line
//(digitalRead(switchApin); <----<<<< you erased a ) therfore had an error
//Count = 5; //debug
actionDelay = delayValueL;
actionMillis = millis();
digitalWrite(relayPin, PinOff);
actionCounter = Count;
ActionState = lowState;
}
}
break;
//***************************
case lowState:
{
if (millis() - actionMillis < actionDelay)
{
break;
}
digitalWrite(relayPin, PinOn);
actionDelay = delayValueH;
actionMillis = millis();
ActionState = highState;
}
break;
//***************************
case highState:
{
if (millis() - actionMillis < actionDelay)
{
break;
}
digitalWrite(relayPin, PinOff);
actionCounter--;
if (actionCounter == 0)
{
ActionState = startState;
break;
}
actionDelay = delayValueL;
actionMillis = millis();
ActionState = lowState;
}
break;
} //End of switch/case
}//End of t o g g l e A c t i o n ( )
//======================================================================
// E N D O F C O D E
//======================================================================
ok cool thanks. I'm still having copy issues with the code. I'm gonna just split screen and type it out.
i'll get back to you when i'm done. again, thank you.
nice! works pretty good. seems like when the switches are set to zero (all in the off position) it continuously digitalWrites with what ever pulse rate is set to.
I added two "if statements" I was having issues with switching the sensor pin on and off with the other switches set to zero.
seems to work alright.
i'm using a LED right now for the relay. I'm getting a really small and fast flash on the LED.
and when I switch a counter switch on (no matter which one) then it will continuously write the relayPin HIGH.... I have to press the reset button to get it to work right.
#define Pressed HIGH
#define Released LOW
//#define Pressed LOW //debug
//#define Released HIGH //debug
#define PinOn HIGH
#define PinOff LOW
// outputs
const byte relayPin = 12;
const byte heartBeatLED = 13;
// pulse settings
const byte onTimePin = A0; // pot to determine digitalWrite HIGH
const byte offTimePin = A2; // pot to determin digitalWrite LOW
const byte switchApin = 2; // on/off switch A value of 1 when high
const byte switchBpin = 3; // on/off switch B value of 2 when high
const byte switchCpin = 4; // on/off switch C value of 4 when high
const byte switchDpin = 5; // on/off switch D value of 8 when high
unsigned long delayValueH; // delay high value
unsigned long delayValueL; // delay low value
unsigned long heartBeatMillis;
unsigned long actionMillis;
unsigned long actionDelay;
byte Count;
byte actionCounter;
// input sensors
const byte sensorPin = 9; // on/off sensor
enum STATE {startState, lowState, highState};
STATE ActionState = startState;
// s e t u p ( )
//**********************************************************************
void setup()
{
pinMode(heartBeatLED, OUTPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, PinOff);
//pinMode(GledPin, OUTPUT); //this had to be commented
//digitalWrite(GledPin,PinOff); //this had to be commented
//pinMode(RledPin, OUTPUT); //this had to be commented
//digitalWrite(RledPin, PinOff); //this had to be commented
pinMode(sensorPin, INPUT_PULLUP);
pinMode(switchApin, INPUT_PULLUP);
pinMode(switchBpin, INPUT_PULLUP);
pinMode(switchCpin, INPUT_PULLUP);
pinMode(switchDpin, INPUT_PULLUP);
} //END of s e t u p ( )
// l o o p ( )
//**********************************************************************
void loop()
{
//***************************
//HeartBeat LED, should toggle every 200ms 'if the code is nonblocking'
if (millis() - heartBeatMillis >= 200)
{
heartBeatMillis = millis(); //reset timing
//Toggle heartBeatLED
digitalWrite(heartBeatLED, digitalRead(heartBeatLED));
}
if ((digitalRead(switchApin)==LOW) && (digitalRead(switchBpin)==LOW) && (digitalRead(switchCpin)==LOW) && (digitalRead(switchDpin)==LOW) && (digitalRead(sensorPin)==HIGH))
{
digitalWrite(relayPin,LOW);
}
if ((digitalRead(switchApin)==LOW) && (digitalRead(switchBpin)==LOW) && (digitalRead(switchCpin)==LOW) && (digitalRead(switchDpin)==LOW) && (digitalRead(sensorPin)==LOW))
{
digitalWrite(relayPin,LOW);
}
//***************************
toggleAction();
} //END of l o o p ( )
//======================================================================
// F U N C T I O N S
//======================================================================
// t o g g l e A c t i o n ( )
//**********************************************************************
void toggleAction()
{
switch (ActionState)
{
//***************************
case startState:
{
if (digitalRead(sensorPin) == Pressed)
{
delayValueH = analogRead(onTimePin);
delayValueL = analogRead(offTimePin);
//delayValueH = 500; //debug
//delayValueL = 200; //debug
Count = (digitalRead(switchDpin) * 8) +
(digitalRead(switchCpin) * 4) +
(digitalRead(switchBpin) * 2) +
(digitalRead(switchApin)); //corrected line
//(digitalRead(switchApin); <----<<<< you erased a ) therfore had an error
//Count = 5; //debug
actionDelay = delayValueL;
actionMillis = millis();
digitalWrite(relayPin, PinOff);
actionCounter = Count;
ActionState = lowState;
}
}
break;
//***************************
case lowState:
{
if (millis() - actionMillis < actionDelay)
{
break;
}
digitalWrite(relayPin, PinOn);
actionDelay = delayValueH;
actionMillis = millis();
ActionState = highState;
}
break;
//***************************
case highState:
{
if (millis() - actionMillis < actionDelay)
{
break;
}
digitalWrite(relayPin, PinOff);
actionCounter--;
if (actionCounter == 0)
{
ActionState = startState;
break;
}
actionDelay = delayValueL;
actionMillis = millis();
ActionState = lowState;
}
break;
} //End of switch/case
}//End of t o g g l e A c t i o n ( )
//======================================================================
// E N D O F C O D E
//======================================================================
Do some debugging try removing the comment marks as shown here, see lines with <----<<<<
You will get 500 and 200 for the delays.
Note:
If the Pots are turned down too much, the flashing will be very fast.
To compensate you would have to add two bottom resistors to the pots as lower end limits.
//***************************
case startState:
{
if (digitalRead(sensorPin) == Pressed)
{
delayValueH = analogRead(onTimePin);
delayValueL = analogRead(offTimePin);
delayValueH = 500; //debug <----<<<< uncomment this line to see what happens
delayValueL = 200; //debug <----<<<< it takes the pots out of the equation
Count = (digitalRead(switchDpin) * 8) +
(digitalRead(switchCpin) * 4) +
(digitalRead(switchBpin) * 2) +
(digitalRead(switchApin)); //corrected line
//Count = 5; //debug
//ignore a value of zero
if(Count == 0)
{
break;
}
actionDelay = delayValueL;
actionMillis = millis();
digitalWrite(relayPin, PinOff);
actionCounter = Count;
ActionState = lowState;
}
}
break;
ill try what you posted, but the flash isn't due to being turned down too much. I have both pots set to almost half.
when there is a count setting and sensorPin is in a HIGH state then the LED works normally (good solid light with proper delay times for both on and off)
the flash i'm referring to is like half a second, if that.
it comes on fast and dim then its off for the set off delay (set by the pot) but when the "pulse on" would normally occur under normal conditions then the issue occurs. (led fast dim flash)