Hello,
Simple problem, stuck! I'm making a display that has LEDs under the snow that will light up "randomly" when triggered by the PIR. I am having trouble getting the PIR into the code (stupid stuff). This is the code I have so far, help! TIA!
#include <stdio.h>
#define numberOfLEDs 18
long nextFlash[18];
int ledPin[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; // LED pins to use.
int ledState[18];
int inputPin = 0 // PIR sensor
void setup(){
pinMode(inputPin, INPUT);
for(int i = 0; i<numberOfLEDs; i++){
pinMode(ledPin[i],OUTPUT);
ledState[i] = LOW;
digitalWrite(ledPin[i], LOW); // all LEDs off
nextFlash[i] = millis() +random(10,700);
}
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
for(int i = 0; i<numberOfLEDs; i++){
if(millis() > nextFlash[i]){
if(ledState[i] == LOW) ledState[i] = HIGH;
else ledState[i] = LOW;
digitalWrite(ledPin[i],ledState[i]);
nextFlash[i] = millis()+random(10,1250) ; // next toggle random time
//delay(millis()+random(10,13));
}
}
}