Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1.  
  2. //include the library code
  3. #include <LiquidCrystal.h>
  4. #include <EEPROM.h>
  5. #include <Hx711.h>
  6.  
  7. LiquidCrystal lcd(12, 11, 5, 4, 3, 1);
  8. Hx711 scale(A2, A3);
  9.  
  10. const int button = 2; // This is the button for the Goal
  11. const int button1 = 6; // This is the button for the Alarm
  12. int Piezo = 8;
  13. int volatile ButtonState = 0;
  14. float Drink;
  15. const float eps = 1e-6;
  16. long changeTime, Alarm;
  17. int n;
  18. double a[100100];
  19. float Goal = 3000;
  20.  
  21. void setup() {
  22.   Serial.begin(9600);
  23.   lcd.begin(16, 2);
  24.  
  25.   pinMode(button, INPUT);
  26.   pinMode(button1, INPUT);
  27.   pinMode(Piezo, OUTPUT);
  28.   ButtonState = digitalRead(button);
  29.   attachInterrupt(0,pin_ISR,RISING);
  30.  
  31.   lcd.print("Welcome to the");
  32.   lcd.setCursor(0, 1);
  33.   lcd.print("Reminder Bottle!");
  34. }
  35.  
  36. void loop() {
  37.   lcd.clear();
  38.   scale.getGram();
  39.   a[++n]=scale.getGram();
  40.   for (int i=1; i<n; ++i)
  41.   {Drink += a[i]>a[i+1]?a[i]-a[i+1]:0;}        
  42.   Serial.println(scale.getGram(), 1); // Check at the program
  43.   lcd.print("level: ");
  44.   lcd.print(scale.getGram(), 1); // Print the water left
  45.   lcd.print(" ml");
  46.   lcd.setCursor(0,1);
  47.   lcd.print("Drink: ");
  48.   lcd.print(Drink);// Print the water consumption
  49.   lcd.print(" ml");
  50.   delay(3000);
  51.   if(Weight <= eps && (millis() - changeTime) > 5400000)
  52.   {alarm();
  53.   }
  54.   if(button1 == HIGH && (millis() - Alarm) > 3600000)
  55.   {hourlyAlarm();
  56.   }
  57. }
  58.            
  59. void pin_ISR()
  60. {
  61.   if (ButtonState == HIGH);
  62.   {
  63.   lcd.clear();
  64.   if(Drink>Goal)
  65.   {lcd.print("Success!");}
  66.   else {lcd.print("Drink more!");}
  67.   }
  68. }
  69.  
  70. void alarm()
  71.  {
  72.    lcd.clear();
  73.    lcd.print("Check your bottle");
  74.    lcd.setCursor(0,1);
  75.    lcd.print("or drink more");
  76.    changeTime = millis();
  77.  }
  78. void hourlyAlarm()
  79.  {
  80.    lcd.clear();
  81.    lcd.print("Drinking time!");
  82.    tone(Piezo,700,500);
  83.    delay(3000);
  84.    digitalWrite(Piezo, LOW);
  85.    Alarm = millis();
  86.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement