qazrix
September 6, 2017, 11:39am
1
When i make darkness only pin 7 works
int lightPin = 0; //define a pin for Photo resistor
int ledPin1 = 5;
int ledPin2 = 6;
int ledPin3 = 7;
void setup(){
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop(){
int lectura = analogRead(lightPin);
if(lectura < 500)
{
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
}
else if(lectura >= 500 && lectura < 300)
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
}
else if(lectura >= 500 && lectura < 500)
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
}
else if(lectura >= 700)
{
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
}
delay(100);
}
When i make darkness only pin 7 works
God will be most upset with you.
if(lectura >= 500 && lectura < 300)
so how can this variable be above 500 and below 300 at the same time?
if(lectura >= 500 && lectura < 500)
and how can this variable be above 500 and below 500 at the same time?
1 Like
vaj4088
September 6, 2017, 10:42pm
3
Also, this is a bad idea:
int lightPin = 0; //define a pin for Photo resistor
Pins 0 and 1 are generally used on Arduinos by the serial port for debugging and for code downloading. I am not saying that Pins 0 and 1 can't be used if handled carefully, but otherwise I would suggest that you choose a different pin .
Wawa
September 7, 2017, 1:11am
4
vaj4088:
int lightPin = 0; //define a pin for Photo resistor
Pins 0 and 1 are generally used on Arduinos by the serial port for debugging and for code downloading.
... analogRead(lightPin); // the compiler switches here to A0
int lightPin = 0; // bad practice if you mean the analogue pin
int lightPin = A0; // better
Leo..
vaj4088
September 7, 2017, 2:45am
5
I didn't know that about analogRead(). Thanks!