Ok take a look at this, so now if if the first “if” statement is true, will it now read the “else if” line of code after it while its happening?
#include <Servo.h>
Servo myservo; // create servo object to control a servo
//VG 02 Mixture Controller v0.2
//Craeted by Matt Ryder, Vulcan Gasifier LLC May 5, 2015
//Last edit; May 12, 2015
// These constants won't change:
const int O2SensePin = A1; // pin that the O2 sensor is attached to
const int O2SwtPin = A2; //Pin Auto Mode Switch is attached to
const int O2ManPin = A0; // Reads the O2 Manual Adjust Potentiometer on pin A1
const int threshold1 = 600; //Threshold limits for rich gas condition
const int threshold2 = 640;
const int threshold3 = 690;
const int target1 = 710; // Target Parameter for rich condition
const int target2 = 700; // Target Parameter for lean condition
const int target3 = 790; // Target Paremeter for extream Lean condition
const int threshold4 = 720; //Threshold limits for lean gas condition
const int threshold5 = 800;
int pos = 0; // variable to store the servo position
int val; // variable to read the value from the analog pin
int lastpos = val; // variable to store the servo last position
int O2SwticthState = 0; // variable for reading the Fuel Mixer Mode status
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// Need to create a set point for servo start position after manual tuning
{
val = analogRead(O2ManPin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 20, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
lastpos = val; // sets lastpos to equaul the position of the manually set position
delay(10); // waits for the servo to get there
}
}
void loop()
{
// read the state of the pushbutton value:
O2SwticthState = digitalRead(O2SwtPin);
// read the value of the O2 sensor:
int sensorReading = analogRead(A1);
if (O2SwticthState == LOW)
{
val = analogRead(O2ManPin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 20, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
lastpos = val; // sets lastpos to equaul the position of the manually set position
delay(10); // waits for the servo to get there
}
else
{
delay (10);
}
if (sensorReading <= threshold1)
{
// we need to move the servo 1 degrees in the POSITIVE
// direction so we need to add ADD to the last known
// position.
myservo.write (lastpos + 10); // Moves servo negative 1 degrees
// now we need to save that last position value
lastpos = lastpos +10;
delay(10); // Delay time between 1 degree movments
// Decreasing the number = slower response time
}
else if (sensorReading >= target1);
myservo.write (lastpos);
delay (50);
if (sensorReading <= threshold2)
{
// we need to move the servo 1 degrees in the POSITIVE
// direction so we need to add ADD to the last known
// position.
myservo.write (lastpos + 2); // Moves servo negative 1 degrees
// now we need to save that last position value
lastpos = lastpos +2;
delay(10); // Delay time between 1 degree movments
// Decreasing the number = slower response time
}
else if (sensorReading >= target1);
myservo.write (lastpos);
delay (50);
if (sensorReading <= threshold3)
{
// we need to move the servo 1 degrees in the POSITIVE
// direction so we need to add ADD to the last known
// position.
myservo.write (lastpos + 1); // Moves servo negative 1 degrees
// now we need to save that last position value
lastpos = lastpos +1;
delay(200); // Delay time between 1 degree movments
// Decreasing the number = slower response time
}
else if (sensorReading >= target1);
myservo.write (lastpos);
delay (100);
if (sensorReading > threshold4)
{
// we need to move the servo 1 degrees in the POSITIVE
// direction so we need to add ADD to the last known
// position.
myservo.write (lastpos - 1); // Moves servo negative 1 degrees
// now we need to save that last position value
lastpos = lastpos -1;
delay(200); // Delay time between 1 degree movments
// Decreasing the number = slower response time
}
else if (sensorReading <= target2);
myservo.write (lastpos);
delay (100);
if (sensorReading > threshold5)
{
// we need to move the servo 1 degrees in the POSITIVE
// direction so we need to add ADD to the last known
// position.
myservo.write (lastpos - 1); // Moves servo negative 1 degrees
// now we need to save that last position value
lastpos = lastpos -1;
delay(100); // Delay time between 1 degree movments
// Decreasing the number = slower response time
}
else if (sensorReading <= target3);
myservo.write (lastpos);
delay (50);
}