This shows you the differences between two versions of the page.
pm:prj2024:iotelea:dalya.tobescu [2024/05/26 22:33] dalya.tobescu |
pm:prj2024:iotelea:dalya.tobescu [2024/05/26 23:04] (current) dalya.tobescu |
||
---|---|---|---|
Line 405: | Line 405: | ||
static float lastWeight = 0; | static float lastWeight = 0; | ||
static bool isStable = false; | static bool isStable = false; | ||
- | static bool isFirstRun = true; // Add a variable to track the first run | + | static bool isFirstRun = true; |
static bool plate = false; | static bool plate = false; | ||
static float plateWeight = 0; | static float plateWeight = 0; | ||
+ | static int ledBrightness = 0; // Variable to store LED brightness | ||
+ | |||
LoadCell.update(); | LoadCell.update(); | ||
float weight = LoadCell.getData(); | float weight = LoadCell.getData(); | ||
Line 435: | Line 437: | ||
if (isStable) { | if (isStable) { | ||
- | if (plate == false) { | + | if (!plate) { |
lcd.clear(); | lcd.clear(); | ||
lcd.setCursor(0, 0); // Set cursor to the first row | lcd.setCursor(0, 0); // Set cursor to the first row | ||
Line 464: | Line 466: | ||
// Check if the button is pressed | // Check if the button is pressed | ||
if (digitalRead(buttonPin) == HIGH) { | if (digitalRead(buttonPin) == HIGH) { | ||
- | digitalWrite(ledPin, LOW); | + | analogWrite(ledPin, 0); // Turn off the LED |
Serial.println("Reset button pressed"); | Serial.println("Reset button pressed"); | ||
plate = false; | plate = false; | ||
weight = 0; | weight = 0; | ||
lcd.clear(); | lcd.clear(); | ||
- | lcd.setCursor(0, 1); // set cursor to second row | + | lcd.setCursor(0, 1); // Set cursor to the second row |
lcd.print(" Reset... "); | lcd.print(" Reset... "); | ||
LoadCell.start(1000); | LoadCell.start(1000); | ||
Line 477: | Line 479: | ||
} | } | ||
+ | // Plate button functionality with PWM | ||
if (digitalRead(plateButton) == HIGH) { | if (digitalRead(plateButton) == HIGH) { | ||
- | // turn LED on: | ||
Serial.println("PLATE FUNCTION"); | Serial.println("PLATE FUNCTION"); | ||
- | digitalWrite(ledPin, HIGH); | ||
plate = true; | plate = true; | ||
lcd.clear(); | lcd.clear(); | ||
- | lcd.setCursor(0, 1); // set cursor to second row | + | lcd.setCursor(0, 1); // Set cursor to the second row |
lcd.print(" Plate function "); | lcd.print(" Plate function "); | ||
LoadCell.start(1000); | LoadCell.start(1000); | ||
Line 489: | Line 490: | ||
delay(1000); // Allow some time for the reset to stabilize | delay(1000); // Allow some time for the reset to stabilize | ||
lcd.clear(); | lcd.clear(); | ||
+ | |||
+ | // Gradually increase LED brightness using PWM | ||
+ | for (int brightness = 0; brightness <= 255; brightness += 5) { | ||
+ | analogWrite(ledPin, brightness); | ||
+ | delay(10); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Decrease LED brightness over time | ||
+ | if (ledBrightness > 0) { | ||
+ | ledBrightness -= 5; | ||
+ | if (ledBrightness < 0) { | ||
+ | ledBrightness = 0; | ||
+ | } | ||
+ | analogWrite(ledPin, ledBrightness); | ||
} | } | ||