skiphansen / dmitrygr-einkTags

Dmitry Grinberg's Custom firmware for various eInk price tags
Other
10 stars 3 forks source link

please help #2

Closed trvchao closed 2 weeks ago

trvchao commented 2 weeks ago

i was trying to make this thing that sounds a buzzer when light is detected(through a photoresistor), and for some reason, the photoresistor is staying at the same light level no matter what i do. this means the buzzer is always ringing, and it won't stop unless i take out the photoresistor. even if i cover the photoresistor, the light level stays at 1023

here is my code:

`const int photoResistorPin = A0; // Analog pin for the photoresistor const int buzzerPin = 9; // Digital pin for the piezo buzzer

const int lightThreshold = 1000;

bool isLightDetected = false;

void setup() { Serial.begin(9600);

// Set the buzzer pin as output pinMode(buzzerPin, OUTPUT); }

void loop() { // Read the value from the photoresistor int lightValue = analogRead(photoResistorPin);

// Determine if light is detected bool currentLightDetected = lightValue > lightThreshold;

if (currentLightDetected != isLightDetected) { isLightDetected = currentLightDetected;

if (isLightDetected) {
  Serial.println("Light detected");
  tone(buzzerPin, 1000); 
} else {
  Serial.println("Light not detected");
  noTone(buzzerPin);     // Stop the buzzer
}

}

delay(100); } `

skiphansen commented 2 weeks ago

This has nothing to do with this repo. There are no buzzers, photo transistors or Arudinos here.