Hello all, I'm working on a project that involves an input and an output. I have a photocell that I would like to use to influence the brightness of 4 leds blinking in s.o.s. Currently, when I upload this code the leds blink fine but the photocell doesn't seem to effect the brightness. How can change my code to better have the photocell effect the brightness and be more sensitive to light? Thanks in advance.
Current Code:
int pin1 = 13;
int pin2 = 12;
int pin3 = 11;
int pin4 = 10;
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider
int LEDpin = 11; // connect Red LED to pin 11 (PWM pin)
int LEDbrightness; //
void setup()
{
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
}
void analogRead()
{
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading); // the raw analog reading
// LED gets brighter the darker it is at the sensor
// that means we have to -invert- the reading from 0-1023 back to 1023-0
photocellReading = 1023 - photocellReading;
//now we have to map 0-1023 to 0-255 since thats the range analogWrite uses
LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
analogWrite(LEDpin, LEDbrightness);
delay(100);
}
void loop()
{
dot(); dot(); dot();
dash(); dash(); dash();
dot(); dot(); dot();
delay(3000);
}
void dot()
{
digitalWrite(pin1, HIGH);
delay(250);
digitalWrite(pin1, LOW);
delay(250);
digitalWrite(pin2, HIGH);
delay(250);
digitalWrite(pin2, LOW);
delay(250);
digitalWrite(pin3, HIGH);
delay(250);
digitalWrite(pin3, LOW);
delay(250);
digitalWrite(pin4, HIGH);
delay(250);
digitalWrite(pin4, LOW);
delay(250);
}
void dash()
{
digitalWrite(pin1, HIGH);
delay(1000);
digitalWrite(pin1, LOW);
delay(250);
digitalWrite(pin2, HIGH);
delay(1000);
digitalWrite(pin2, LOW);
delay(250);
digitalWrite(pin3, HIGH);
delay(1000);
digitalWrite(pin3, LOW);
delay(250);
digitalWrite(pin4, HIGH);
delay(1000);
digitalWrite(pin4, LOW);
delay(250);
}