Hi, beginner programmer here...
I get the following error while trying to upload the following script:
Multiple_Lights_1PB__4LED_v3:93: error: expression cannot be used as a function
(digitalRead(ledPin_Option_3) == LOW )
Any clues?
Source:
/*Using a Single Button, create mutliple options based on how long the button is pressed
/* Modified to: read state of light to light up a serie of LED one by one */
The circuit:
LED attached from pin 13 to ground through a 220 ohm resistor
LED attached from pin 12 to ground through a 220 ohm resistor
one side of momentary pushbutton attached to pin 2
other side of momentary pushbutton attached to Ground
Note 1: on most Arduinos there is already an LED on the board
attached to pin 13.Note 2: In this circuit, when the button is pressed, Ground Voltage is what will be applied.
Created DEC 2014 by Scuba Steve
Modified JAN 2015 by Michael James
Both members of https://programmingelectronics.comThis code is in the public domain
*//////////Declare and Initialize Variables////////////////////////////
//We need to track how long the momentary pushbutton is held in order to execute different commands
//This value will be recorded in seconds
float pressLength_milliSeconds = 0;// Define the minimum length of time, in milli-seconds, that the button must be pressed for a particular option to occur
int optionOne_milliSeconds = 100;
// int optionTwo_milliSeconds = 2000;
int optionThree_milliSeconds = 3000;
int optionFour_milliSeconds = 4000;
int optionFive_milliSeconds = 2000;//The Pin your button is attached to
int buttonPin = 2;//Pin your LEDs are attached to
int ledPin_Option_1 = 13;
int ledPin_Option_2 = 12;
int ledPin_Option_3 = 11;
int ledPin_Option_4 = 10;void setup(){
// Initialize the pushbutton pin as an input pullup
// Keep in mind, when pin 2 has ground voltage applied, we know the button is being pressed
pinMode(buttonPin, INPUT_PULLUP);//set the LEDs pins as outputs
pinMode(ledPin_Option_1, OUTPUT);
pinMode(ledPin_Option_2, OUTPUT);
pinMode(ledPin_Option_3, OUTPUT);
pinMode(ledPin_Option_4, OUTPUT);//Start serial communication - for debugging purposes only
Serial.begin(9600);} // close setup
void loop() {
//Record roughly the tenths of seconds the button in being held down
while (digitalRead(buttonPin) == LOW ){delay(100); //if you want more resolution, lower this number
pressLength_milliSeconds = pressLength_milliSeconds + 100;//display how long button is has been held
Serial.print("ms = ");
Serial.println(pressLength_milliSeconds);}//close while
//Different if-else conditions are triggered based on the current state of DigitalRead
//Start with the longest time option first//Option OFF - Execute the 5th option (LOW) if the button is held for the correct amount of time
if (pressLength_milliSeconds >= optionFive_milliSeconds){digitalWrite(ledPin_Option_1, LOW);
digitalWrite(ledPin_Option_2, LOW);
digitalWrite(ledPin_Option_3, LOW);
digitalWrite(ledPin_Option_4, LOW);}
// If no lights are HIGH make the 1st LED only = HIGH
if (digitalRead(ledPin_Option_1) == LOW )
(digitalRead(ledPin_Option_2) == LOW )
(digitalRead(ledPin_Option_3) == LOW )
(digitalRead(ledPin_Option_4) == LOW ) {digitalWrite(ledPin_Option_1, HIGH);
digitalWrite(ledPin_Option_2, LOW);
digitalWrite(ledPin_Option_3, LOW);
digitalWrite(ledPin_Option_4, LOW);
}//Option OFF - Execute the 5th option (LOW) if the button is held for the correct amount of time
if (pressLength_milliSeconds >= optionFive_milliSeconds){digitalWrite(ledPin_Option_1, LOW);
digitalWrite(ledPin_Option_2, LOW);
digitalWrite(ledPin_Option_3, LOW);
digitalWrite(ledPin_Option_4, LOW);}
// If LED 1 is HIGH make the 2nd LED = HIGH
if (digitalRead(ledPin_Option_1) == HIGH )
(digitalRead(ledPin_Option_2) == LOW )
(digitalRead(ledPin_Option_3) == LOW )
(digitalRead(ledPin_Option_4) == LOW ) {digitalWrite(ledPin_Option_1, HIGH);
digitalWrite(ledPin_Option_2, HIGH);
digitalWrite(ledPin_Option_3, LOW);
digitalWrite(ledPin_Option_4, LOW);
}//Option OFF - Execute the 5th option (LOW) if the button is held for the correct amount of time
if (pressLength_milliSeconds >= optionFive_milliSeconds){digitalWrite(ledPin_Option_1, LOW);
digitalWrite(ledPin_Option_2, LOW);
digitalWrite(ledPin_Option_3, LOW);
digitalWrite(ledPin_Option_4, LOW);}
// If LED 1,2 are HIGH make the 3rd LED = HIGH
if (digitalRead(ledPin_Option_1) == HIGH )
(digitalRead(ledPin_Option_2) == HIGH )
(digitalRead(ledPin_Option_3) == LOW )
(digitalRead(ledPin_Option_4) == LOW ) {digitalWrite(ledPin_Option_1, HIGH);
digitalWrite(ledPin_Option_2, HIGH);
digitalWrite(ledPin_Option_3, HIGH);
digitalWrite(ledPin_Option_4, LOW);
}//Option OFF - Execute the 5th option (LOW) if the button is held for the correct amount of time
if (pressLength_milliSeconds >= optionFive_milliSeconds){digitalWrite(ledPin_Option_1, LOW);
digitalWrite(ledPin_Option_2, LOW);
digitalWrite(ledPin_Option_3, LOW);
digitalWrite(ledPin_Option_4, LOW);}
// If LED 1,2,3 are HIGH make the 4th LED = HIGH
if (digitalRead(ledPin_Option_1) == HIGH )
(digitalRead(ledPin_Option_2) == HIGH )
(digitalRead(ledPin_Option_3) == HIGH )
(digitalRead(ledPin_Option_4) == LOW ) {digitalWrite(ledPin_Option_1, HIGH);
digitalWrite(ledPin_Option_2, HIGH);
digitalWrite(ledPin_Option_3, HIGH);
digitalWrite(ledPin_Option_4, HIGH);
}//Option OFF - Execute the 5th option (LOW) if the button is held for the correct amount of time
if (pressLength_milliSeconds >= optionFive_milliSeconds){digitalWrite(ledPin_Option_1, LOW);
digitalWrite(ledPin_Option_2, LOW);
digitalWrite(ledPin_Option_3, LOW);
digitalWrite(ledPin_Option_4, LOW);}
//close if options
//every time through the loop, we need to reset the pressLength_Seconds counter
pressLength_milliSeconds = 0;} // close void loop
Thank you, Regards