Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //include the library code
- #include <LiquidCrystal.h>
- #include <EEPROM.h>
- #include <Hx711.h>
- LiquidCrystal lcd(12, 11, 5, 4, 3, 1);
- Hx711 scale(A2, A3);
- const int button = 2; // This is the button for the Goal
- const int button1 = 6; // This is the button for the Alarm
- int Piezo = 8;
- int volatile ButtonState = 0;
- float Drink;
- const float eps = 1e-6;
- long changeTime, Alarm;
- int n;
- double a[100100];
- float Goal = 3000;
- void setup() {
- Serial.begin(9600);
- lcd.begin(16, 2);
- pinMode(button, INPUT);
- pinMode(button1, INPUT);
- pinMode(Piezo, OUTPUT);
- ButtonState = digitalRead(button);
- attachInterrupt(0,pin_ISR,RISING);
- lcd.print("Welcome to the");
- lcd.setCursor(0, 1);
- lcd.print("Reminder Bottle!");
- }
- void loop() {
- lcd.clear();
- scale.getGram();
- a[++n]=scale.getGram();
- for (int i=1; i<n; ++i)
- {Drink += a[i]>a[i+1]?a[i]-a[i+1]:0;}
- Serial.println(scale.getGram(), 1); // Check at the program
- lcd.print("level: ");
- lcd.print(scale.getGram(), 1); // Print the water left
- lcd.print(" ml");
- lcd.setCursor(0,1);
- lcd.print("Drink: ");
- lcd.print(Drink);// Print the water consumption
- lcd.print(" ml");
- delay(3000);
- if(Weight <= eps && (millis() - changeTime) > 5400000)
- {alarm();
- }
- if(button1 == HIGH && (millis() - Alarm) > 3600000)
- {hourlyAlarm();
- }
- }
- void pin_ISR()
- {
- if (ButtonState == HIGH);
- {
- lcd.clear();
- if(Drink>Goal)
- {lcd.print("Success!");}
- else {lcd.print("Drink more!");}
- }
- }
- void alarm()
- {
- lcd.clear();
- lcd.print("Check your bottle");
- lcd.setCursor(0,1);
- lcd.print("or drink more");
- changeTime = millis();
- }
- void hourlyAlarm()
- {
- lcd.clear();
- lcd.print("Drinking time!");
- tone(Piezo,700,500);
- delay(3000);
- digitalWrite(Piezo, LOW);
- Alarm = millis();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement