if you set the clock at 0
then at 1 second do a thing
at 1.1 seconds do another thing.....
you never delay, you just keep doing everything else, but at the right time, you do a thing.
try 2 LED's connected to pins 6 and 8
there is a difference between the preferred way to code, and easily read code that is more like a list
since your first cannon will need the LED's and solenoid to work together, this snippet is made so you can easily see the timing.
we use flags to tell us if a thing is an some state.
the flag1 can tell us that is has passed a time, without every knowing the time.
you can see that it is long but if you look at it, there are two if() statements.
the first prevents the LED from coming on later in the timing. the second sets the prescribed time.
what is missing is a way to start this, for this exercise, you reset.
and also missing is the heater.
this is a variation of Blink without delay.
/*
* cannon fodder
* this exercise is to flash an LED on and off using the clock.
* the Arduino is started and the system clock millis() is at 0 and
* as the system clock counts up, the lights go on and off
*/
const int LED1 = 6;// the number of the LED pin
const int solenoid1 = 8 ; the number of pin for the solenoid, but now for an LED to test
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int fire1, fire1_active , fire_flag1 , flag1, button, solenoid1_flag;
unsigned long timing1, start1 ;
void setup() { //+++++++++++++++++++++++++++ setup ++++++++++++++
Serial.begin(9600);
pinMode(LED1, OUTPUT); // initialize the LED pin as an output:
pinMode(solenoid1, OUTPUT);
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
flag1 = 0 ;
solenoid1_flag = 0 ;
}
void loop() { //+++++++++++++++++++++++++++ LOOP ++++++++++++++
timing1 = millis() ;
if (solenoid1_flag ==1) { if (timing1 >= 3500) { digitalWrite(solenoid1, LOW) ;solenoid1_flag=2; }}
if (solenoid1_flag ==0) { if (timing1 >= 2300) { digitalWrite(solenoid1, HIGH) ;solenoid1_flag=1; }}
if (flag1 ==11){ if (timing1 >= 3000) { digitalWrite(LED1, LOW) ;flag1=12; }}
if (flag1 ==10){ if (timing1 >= 2900) { digitalWrite(LED1, HIGH);flag1=11; }}
if (flag1 ==9) { if (timing1 >= 2800) { digitalWrite(LED1, LOW) ;flag1=10; }}
if (flag1 ==8) { if (timing1 >= 2700) { digitalWrite(LED1, HIGH);flag1=9; }}
if (flag1 ==7) { if (timing1 >= 2600) { digitalWrite(LED1, LOW) ;flag1=8; }}
if (flag1 ==6) { if (timing1 >= 2500) { digitalWrite(LED1, HIGH);flag1=7; }}
if (flag1 ==5) { if (timing1 >= 2400) { digitalWrite(LED1, LOW) ;flag1=6; }}
if (flag1 ==4) { if (timing1 >= 2300) { digitalWrite(LED1, HIGH);flag1=5; }}
if (flag1 ==3) { if (timing1 >= 2200) { digitalWrite(LED1, LOW) ;flag1=4; }}
if (flag1 ==2) { if (timing1 >= 2100) { digitalWrite(LED1, HIGH);flag1=3; }}
if (flag1 ==0) { if (timing1 >= 2000) { digitalWrite(LED1, LOW) ;flag1=2; }}
}