Pages: [1]   Go Down
Author Topic: Photo resistor  (Read 627 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
}
if (((lightLevel > 127.5) || (lightLevel < 191.25)))
{
  for(index = 0; index <= 0; index++)
  analogWrite(ledPins[index], HIGH);
}
if (((lightLevel > 191.25) || (lightLevel < 255)))
{
  for(index = 0; index <= 3; index++)
  analogWrite(ledPins[index], LOW);
}}
  
« Last Edit: March 16, 2013, 07:58:16 pm by penguin19 » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8653
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void off()
{
  (ledPins[index], LOW); 
}
That function doesn't actually do anything.  From context I think you intended to write:
Code:
void off()
{
  for (int index=0; index < 3; index++)
    digitalWrite(ledPins[index], LOW); 
}

Other parts of the code may be wrong in similar ways.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed the off function like this:
Code:
void off()
{
 int index;
 
  for (int index = 0; index < 4; index ++)
  digitalWrite(ledPins[index], HIGH);
}
I tried turning the pins LOW, but they remained on. I then tested them on HIGH to see what would happen and they blink on and then remain off. Any idea why this happens? Could my wiring on the board be wrong?

I got the dim function to work by doing this:
Code:
void dim()
{
   lightLevel=analogRead(sensorPin);
//manualTune();
autoTune();
 for (int index = 0; index < 4; index ++)
analogWrite(ledPins[index], lightLevel);
}

Still can't get the gauge function to work though...
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 596
Posts: 33283
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

you don't need the
Code:
int index;
Because you already declare the variable in
 
Code:
for (int index = 0; index < 4; index ++)

Quote
I tried turning the pins LOW, but they remained on.
No. If that is what you see something is putting them high again.

This sort of test is wrong:-
Code:
if (((lightLevel > 191.25) || (lightLevel < 255)))
You are using the || which is the logical OR, so if the light level is less than 255 then it is true irrespective of the first part. I think you mean && the and operator here.
Logged

Pages: [1]   Go Up
Jump to: