Hi everyone!
Here I am, Marc, an arduino newbie. Long time electronic enthusiast (doesn't mean my electronic skills are much higher than my coding ones...) and new comer to ucontroller programming.
I am currently trying to do a simple event sequencer.
I wrote a couple of lines to test and confront myself with reality
And of course I did run into some problems!
So here they are :
1 : I intended to make a 3seconds button pressed condition but when I press it multiple times, it seems I block the sketch and even though the led respond (it blinks with the press of the button) I cannot "unblock" the sequence
2 : sometimes the timed action (10seconds in this case) doesn't do the 10seconds at all. It varies from 2 to 10seconds.
And it usually varies more when I press the start button multiple times (in order to try the condition).
I am a bit lost right now since I thought I had made a pretty "clear" sketch and I can't seem to see where does theses errors come from...
Thanks by advance for your help!
Marc
// START Sequence
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int start = 2; //Start button
int Emerg = 3; //Emergency stop button
int PPump = 4; //Preheat pump Relay
int servo = 5; //PWM output for servo
int motor = 6; //PWM output for motor speed
int modesw = 7; //Mode Ventilation/Start switch
int spark = 8; //Spark output
int led = 9; //status led
unsigned long teststart = 0;
unsigned long test = 0;
boolean startok=false; //start condition
boolean running=false;
int sw_laststate=LOW;
unsigned long time;
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
Serial.println("StartSequence");
// initialize the digital pin as an output.
pinMode(start, INPUT);
pinMode(Emerg, INPUT);
pinMode(PPump, OUTPUT);
pinMode(servo, OUTPUT);
pinMode(motor, OUTPUT);
pinMode(modesw, INPUT);
pinMode(spark, OUTPUT);
pinMode(led, OUTPUT);
}
void loop() {
sw_laststate = digitalRead(start);
if (startok==false && digitalRead(start)==true)
{
digitalWrite(led,HIGH);
if (test==0)
{
test=millis();
Serial.println(test,2);
}
if ((millis()-test)>3000 && digitalRead(start)==true)
{
teststart==millis() ;
Serial.println(teststart,2);
startok=true;
test=0;
digitalWrite(led,LOW);
}
}
else{
test=millis();
digitalWrite(led,LOW);
}
if (startok==true && (millis()-teststart)<10000)
{
running=true;
digitalWrite(spark,HIGH);
Serial.println(millis(),2);
}
else
{
digitalWrite(servo,HIGH);
digitalWrite(spark,LOW);
startok=false;
running=false;
}
}