Hello everyone.
I recently created the circ-02 project from a tutorial which is basically an 8 led sequencer triggered by pins. Here is a link for more details: http://oomlout.com/a/products/ardx/circ-02/
I thought it would be a great idea to have it turn on when I turned the lights off in my room. After a little research I found the circ-09 tutorial [ http://oomlout.com/a/products/ardx/circ-02/ ] about implementing a photo-resistor so I did the tutorial implementing the 9th pin on the 8 led sequencer.
Both work perfectly on their own when loaded but I am looking to make a hybrid of the two so I can have a sweet night light.
My questions are:
1: Would one photo-resistor work for all 8 leds or would each individual led need its own?
- Would the sequencer code and photo-resistor code be compatible running along side with one another when both influence HIGH and LOW? and if yes what would be the best approach?
Codes and photos are posted below. All input is greatly appreciated and please forgive me if this is a no-brainier question ( I am very new to working with arduino).
Circ-02 code:
int ledPins[] = {2,3,4,5,6,7,8,9};
void setup()
{
for(int i = 0; i < 8; i++){
pinMode(ledPins*,OUTPUT);*
- } *
}
*void loop() *
{
- inAndOut(); *
}
void inAndOut(){
-
int delayTime = 100;*
-
for(int i = 0; i <= 3; i++){*
-
int offLED = i - 1;*
-
if(i == 0) { *
-
offLED = 3; *
-
} *
-
int onLED1 = 3 - i; *
-
int onLED2 = 4 + i; *
-
int offLED1 = 3 - offLED;*
-
int offLED2 = 4 + offLED;*
-
digitalWrite(ledPins[onLED1], HIGH);*
-
digitalWrite(ledPins[onLED2], HIGH); *
-
digitalWrite(ledPins[offLED1], LOW); *
-
digitalWrite(ledPins[offLED2], LOW); *
-
delay(delayTime);*
-
}*
-
for(int i = 3; i >= 0; i–){*
-
int offLED = i + 1; *
-
if(i == 3) { *
-
offLED = 0; *
-
} *
-
int onLED1 = 3 – i; *
-
int onLED2 = 4 + i; *
-
int offLED1 = 3 – offLED;*
-
int offLED2 = 4 + offLED;*
-
digitalWrite(ledPins[onLED1], HIGH);*
-
digitalWrite(ledPins[onLED2], HIGH); *
-
digitalWrite(ledPins[offLED1], LOW); *
-
digitalWrite(ledPins[offLED2], LOW); *
-
delay(delayTime);*
-
}*
}
Circ-09 code:
int lightPin = 0;
*int ledPin = 9; *
void setup()
{ -
pinMode(ledPin, OUTPUT);*
}
void loop()
{
int lightLevel = analogRead(lightPin);
lightLevel = map(lightLevel, 0, 900, 0, 255);
lightLevel = constrain(lightLevel, 0, 255);
*analogWrite(ledPin, lightLevel); *
}