/*
Arduino | coding-help
小兔子 [KOSM], — 9:51 PM 9/7/26
hii im really new to coding and i wanted to know how i
could inprove/ fix this code?
im trying to get the ldr to activate the 2 leds when its dark
but im not sure im doing this right
*/
int ledcat = 13;
int ledcattwo = 12;
int ledredlight = 11;
int buttonpin = 2;
int buttonValue;
int potVal;
void setup() {
pinMode(ledcat, OUTPUT);
pinMode(ledcattwo, OUTPUT);
pinMode(ledredlight, OUTPUT);
pinMode(buttonpin, INPUT);
Serial.begin(38400);
}
void loop() {
buttonValue = digitalRead(buttonpin);
if (buttonValue == HIGH) {
digitalWrite(ledredlight, HIGH);
digitalWrite(ledcat, LOW);
digitalWrite(ledcattwo, LOW);
delay(100);
}
if (buttonValue == LOW) {
digitalWrite(ledredlight, LOW);
digitalWrite(ledcat, LOW);
digitalWrite(ledcattwo, LOW);
}
delay(10);
{
potVal = analogRead(A0);
Serial.print("ldr: ");
Serial.println(potVal);
digitalWrite(ledcat, HIGH);
digitalWrite(ledcattwo, HIGH);
delay(potVal);
digitalWrite(ledcat, LOW);
digitalWrite(ledcattwo, LOW);
}
}