Go Down

Topic: Photo resistor (Read 757 times) previous topic - next topic

penguin19

Feb 26, 2013, 01:54 am Last Edit: Mar 17, 2013, 01:58 am by penguin19 Reason: 1
Code: [Select]

}
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);
}}
 

johnwasser

Code: [Select]

void off()
{
  (ledPins[index], LOW); 
}

That function doesn't actually do anything.  From context I think you intended to write:
Code: [Select]

void off()
{
  for (int index=0; index < 3; index++)
    digitalWrite(ledPins[index], LOW); 
}


Other parts of the code may be wrong in similar ways.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

penguin19

I changed the off function like this:
Code: [Select]
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: [Select]
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...

Grumpy_Mike

you don't need the
Code: [Select]
int index;
Because you already declare the variable in
Code: [Select]
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: [Select]
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.

Go Up