I am trying to build a circuit that will flash lights using BlinkWithoutDelay when an a voltage input is applied.
I'm using a threshhold statement to identify when the 12-14 Volts is applied. My issue is I need two things to be true for LED's to come on. It must be time in Millis for the Blink without delay and the signal voltage must be there. So I'm trying to use a double conditional IF statement to do this.
if (led13State == LOW) and if (analogValue > threshold)
These are the errors I get when I try to compile.
error: expected identifier before 'if'
error: expected `;' before 'if'
Thank you. Thank you. I was so close but couldn't get it but that did the trick! Now I need to upload and field test it. Here is my full code. I'll change the subject line to SUCCESS
/* Blink without Delay
Turns on and off a light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to
// set pin numbers:
const int led13 = 13; // the number of the LED pin
const int led2 = 2;
const int led3 = 3;
const int led4 = 4;
const int analogPin = A0; // pin that the sensor is attached to
const int threshold = 1000; // an arbitrary threshold level that's in the range of the analog input
// Variables will change:
int led13State = LOW; // ledState used to set the LED
int led2State = LOW;
int led3State = LOW;
int led4State = LOW;
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 200; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output: $42.00 Harbor Honda to mount $139
pinMode(led13, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
int analogValue = analogRead(analogPin);
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
// I went a different direction and tried Blink Without Delay.
// So my issue now is how to get the LED ( or a series of LEDs) to come on when two conditions are true.
// The Motorcycle Brake light must be on (sensed on Analog pin A0) - and - It must be time to come on.
// This looks like a double IF statement. How do I write that?
// First it looks at the current Millis to find out if it's time to change state.
// Then it looks to see if the current LED state is High or Low.
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if ((led13State == LOW) && (analogValue > threshold))
led13State = HIGH;
else
led13State = LOW;
// if the LED is off turn it on and vice-versa:
if (led2State == LOW)
led2State = HIGH;
else
led2State = LOW;
// set the LED with the ledState of the variable:
digitalWrite(led13, led13State);
digitalWrite(led2, led2State);
}
}