@ michinyon I struggled to get the concept of PLC's ladder logic in the beginning too, I am willing to learn that is why I am here. I have bought a few beginners books & have no trouble copying other peoples code & making adjustments to them, just trying to get to the next base and this forum is very helpful for that.
@ GoForSmoke Correct I don't know "C" Your sketch looks good and you are leading down the right path. I am using Freetronics Eleven (Uno clone, I believe) I have tried your sketch & made the changes but I am only guessing at some things which isn't good enough to make things work.
This is what I have done so far
but I have to head off to work but will spend more time on it when I get home.
const int photoPin = 2;
const byte buzzerPin = 12;
byte state = 0;
unsigned long buzzerStart = 0;
unsigned long waitFiveMinsStart = 0;
unsigned long buzzerPeriod = 1000UL;
unsigned long fiveMinutePeriod = 300000UL;
void setup()
{
Serial.begin(115200);
pinMode(buzzerPin, OUTPUT);
pinMode(photoPin, INPUT);
}
void loop()
{
switch (state)
{
//case 0: //do nothing until the beam is broken
if (photoPin, HIGH); //adjust value or change to digitalRead if appropriate
{
state = 1;
digitalWrite(buzzerPin, HIGH); //turn on the buzzer
buzzerStart = millis();
}
break;
//case 1: //buzzer sounds for one second
if (millis() - buzzerStart >= buzzerPeriod)
{
state = 2;
digitalWrite(buzzerPin, LOW); //turn off the buzzer
waitFiveMinsStart = millis();
}
// break;
//case 2: //do nothing until five minutes has elapsed
if (millis() - waitFiveMinsStart >= fiveMinutePeriod)
{
state = 0;
}
// break;
}
I assume I don't need the serial.
State = 2 I am confused with this, 0 = LOW = Off, 1 = HIGH = On, is my understanding or is this referring to the case: which I put // in front of?