Hello everyone, I have some code below which i got great help with last week.
now i have an extra IF statement and am getting a (Ivaluve required as left operand of assignment) at my second if statement.
the idea behind the code (and its just for fun) is that an output (ledPin) will turn on and off with the millis code.
While this is happening, another pin (sensorPin) will listen for a high input.
If both ledPin and sensorPin are high, i would like (alarmPin) to go high.
it seemed like it was going to be very simple, i was wrong.
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
const int sensorPin = 11; // input for ir sensor
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 (sensorPin, 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
if (ledPin == HIGH && sensorPin = HIGH)
{ digitalWrite (alarmPin, HIGH);}
}