so i have been getting help from some excellent users on here with this code. it has grown from just getting an input to operate an output, to having an alternating output, to having set and reset functions.
and now i have added analog inputs after running the code for them separately and this has caused a small headache.
the circuit has an alternating HIGH LOW digital output (ledPin), as well as another digital output for (alarmPin).
it also has an alarm acknowledge digital input.
in conjunction to this it also has 2 analog inputs which represent a threshold setpoint pot and a variable voltage output sensor, both of these are represented just as pots.
how this is supposed to work is that the ledPin will flash on and off, and if while it is off, if the sensor input supplies a value greater than the value of the threshold pot then the alarmPin will be set to HIGH.
if the value of the sensor pin is lower than the threshold value of the pot then the alarmPin will be LOW.
if the alarmPin goes high it will stay on until the alarmAcknowledge input is sent high.
i have managed to get the circuit to work with the analog inputs, just using digital inputs and having no threshold value.
and then i wrote another little bit of code to compare 2 analog values and give me a digital output if one val was higher than the other.
and then i combined them together and nowwwwwwww i am stuck.
i have gone over the arduino else if tutorials and changed, added,removed brackets and braces and am getting super frustrated.
unsigned long startMillis; //some global variables anywhere in the program
unsigned long currentMillis;
const unsigned long period = 1000; //the value is a number in milliseconds
const byte ledPin = 13; // using the built in led
const int alarmPin = 12; // output for alarm
int analogPin1 = 0; // threshold setpoint
int val = 0;
int analogPin2 = 0; // IR sensor alarm
int val2 = 0;
const int alarmAck = 10; //reset for alarm
void setup() {
// put your setup code here, to run once:
Serial.begin (115200); //start serial in case we need to print debugging info
pinMode (ledPin,OUTPUT);
pinMode (alarmPin,OUTPUT);
pinMode (alarmAck, INPUT);
startMillis = millis (); //initial start time
}
void loop() {
// put your main code here, to run repeatedly:
currentMillis = millis (); //get the current ''time'' (actually the number of milliseconds since the program started
if (currentMillis - startMillis >= period) // test whether the period has elapsed
{digitalWrite (ledPin, !digitalRead(ledPin)); //if so, change the state of the led
startMillis = currentMillis; } // IMPORTANT to save the start time of the current led state
val = analogRead; // get value of IR setpoint
val2 = analogRead; // get value of IR sensor
if
(digitalRead(ledPin) == LOW && (val2 >= val)); // if led high and val2 greater than or eqaul to val
{digitalWrite (alarmPin, HIGH); // turn alarm on
else // this ELSE is where i am getting the else without previous if error.
digitalWrite (alarmPin,Low);}
if (digitalRead (alarmAck) == HIGH && digitalRead (alarmPin) ==HIGH) //if alarm acknowledge input is high and alarm output is high turn alarm output off.
{digitalWrite (alarmPin, LOW);}
}