Hi all,
I am still new to Arduino, I have a project to do.
I wanted to run LEDs in a running pattern, once I pressed and hold down the buttons, the LEDs keep running.
At the same time I have a 4-position rotary switch to select the brightness of LEDs
Here is the code
byte button = 7;
//byte led = 9;
byte led[4] = {2,3,4,5}; // 4 leds.
byte rSwitch[4] = {8,9,10,11}; // 4-position rotary switch
byte brightness;
void setup()
{
pinMode(button, INPUT);
for(int i = 0; i<4; i++)
{
pinMode(led[i], OUTPUT);
digitalWrite(led[i], LOW);
}
for(int a = 0; a<4; a++)
{
pinMode(rSwitch[a], INPUT);
}
void loop()
{
if(digitalRead(button) == HIGH) {// if button is pressed
if(digitalRead(rSwitch[1]) == HIGH { //select 1st brightness
brightness = 10; // set brightness
blink_led_task();
} // blink button
if(digitalRead(rSwitch[2]) == HIGH { //select 2nd brightness
brightness = 50; // set brightness
blink_led_task(); // blink button
}
if(digitalRead(rSwitch[3]) == HIGH { //select 3rd brightness
brightness = 100; // set brightness
blink_led_task(); // blink button
}
if(digitalRead(rSwitch[4]) == HIGH { //select 2nd brightness
brightness = 200; // set brightness
blink_led_task(); // blink button
}
}
else
{
for(int i = 0; i<4; i++)
digitalWrite(led[i], LOW); // turn off all led.
}
}
unsigned long blink_led_time;
void blink_led_task()
{
if(millis() - blink_led_time > 500) // 200 ms.
blink_led_time = millis();
else
return;
static byte number = 0;
for(int i = 0; i<4; i++)
digitalWrite(led[i], LOW); // turn off all leds first.
analogWrite(led[number], brightness);
number++;
if(number == 4)
number = 0; // reset back to zero.
// digitalWrite(led, digitalRead(led) ^ 1); // toggle led.
}
It does not compile, says there is something wrong about the bracket.
I did check but I can't see the problem.
Can anyone give me some hints or suggestion ?
Cheers