Hi Everyone,
I wonder if anyone can help me.
I'm starting a new project and it requires that there are 8 LEDs connected to the arduino with an RCWL-0516 microwave radar sensor.
What happens is that when the Microwave sensor is triggered then the LEDs flash.
As mentioned before there will be 8 LEDs (4 green and 4 red).
At the moment I've got the LEDs connected to the arduino with 220R resistors to ground then the trigger pins to the positive side of each LED. They all use a common ground.
I've got the LEDs lighting sequentially with the following code:
for (int I = 0; I < 9; i++){
digitalWrite(LedPin[i], HIGH);
delay(250);
digitalWrite(LedPin[i], LOW);
}
What I want to happen is that the 4 green LEDs flash then the 4 red ones. The green ones needs to flash at the same time and so do the red ones.
I have created an array for the LEDpins to sit in:
int LedPin[] = {2, 3 ,4 ,5 ,6, 7, 8, 9};
In the void setup I've got:
pinMode(LedPin, OUTPUT)
Green LEDs connected to 2,4,6,8 and red LEDs connected to 3,5,7,9
In the loop I've got this:
if (digitalRead(AntPin) == HIGH) {
for (int g = 0; g < 8; g = g+2) { // this selects the output pins for the green leds
digitalWrite(LedPin[g], HIGH);
delay(500);
digitalWrite(LedPin[g], LOW);
}
The above code works so when the RCWL-0516 is triggered (pin 12) then the LEDs light up but they light up in sequential order.
What I would like to know is there a way to get all 4 green LEDs to light up at the same time without having loads of digitalWrite statements for each individual LED pin.
I could be sloppy and write out each digitalWrite statement for each individual LED pin but I like my code to look tidy .
Any help would be appreciated.
Kindest Regards,
Brett.