Hi i am making a personal project , i want to make a pill dispenser , i want to make a 20second break so that the elderly will be given enough time to take the pills before it start counting down again for the next timing of dispense. I don't know how to make a break whereas it doesn't do anyth for 20 secs then the next countdown will happen. And i want it to be switched off after the third dispense of the day and turned on before the first dispenser.
This is my code i am halfway to completion.
#include <LiquidCrystal.h>
int S = 10 ;
int M = 0;
int H = 0;
LiquidCrystal lcd(9,7,10,11,12,13); // pins connected to LCD
void setup()
{
lcd.begin(16,2);//set up the LCD's number of columns and rows
}
void loop()
{
lcd.setCursor(3,0);
lcd.print ("Dispensing");
lcd.setCursor(6,1);
lcd.print(":");
lcd.setCursor(9,1);
lcd.print(":");
S--;
delay(1000);
if(S<0)
{
M--;
S=59;
}
if(M<0)
{
H--;
M=59;
}
if(H<0) { H=6; M=0; S=0; } if(M>9)
{
lcd.setCursor(7,1);
lcd.print(M);
}
else
{
lcd.setCursor(7,1);
lcd.print("0");
lcd.setCursor(8,1);
lcd.print(M);
lcd.setCursor(9,1);
lcd.print(":");
}
if(S>9)
{
lcd.setCursor(10,1);
lcd.print(S);
}
else
{
lcd.setCursor(10,1);
lcd.print("0");
lcd.setCursor(11,1);
lcd.print(S);
lcd.setCursor(12,1);
lcd.print(" ");
}
if(H>9)
{
lcd.setCursor(4,1);
lcd.print (H);
}
else
{
lcd.setCursor(4,1);
lcd.print("0");
lcd.setCursor(5,1);
lcd.print(H);
lcd.setCursor(6,1);
lcd.print(":");
}
}
// BELOW IS A CODE I TRIED BUT IT DOESN'T WORK due to it slowing down the number of seconds going down by 7secs. And there's something wrong with the display on the screen.
#include <LiquidCrystal.h>
int S = 2;
int M = 0;
int H = 0;
static const uint32_t DELAY_1_S = 1000UL;
static const uint32_t DELAY_1_MINUTE = DELAY_1_S * 60UL;
static const uint32_t DELAY_1_HOUR = DELAY_1_MINUTE * 60UL;
LiquidCrystal lcd(9,7,10,11,12,13); // pins connected to LCD
void setup()
{
lcd.begin(16,2);//set up the LCD's number of columns and rows
}
void loop()
{
lcd.setCursor(3,0);
lcd.print ("Dispensing");
lcd.setCursor(6,1);
lcd.print(":");
lcd.setCursor(9,1);
lcd.print(":");
S--;
delay(1000);
if(S<0)
{
M--;
S=59;
}
if(M<0)
{
H--;
M=59;
}
if(H<0) { H=6; M=0; S=0; } if(M>9)
{
lcd.setCursor(7,1);
lcd.print(M);
delay(7UL * DELAY_1_S); // Delay 7 seconds
}
else
{
lcd.setCursor(7,1);
lcd.print("0");
lcd.setCursor(8,1);
lcd.print(M);
lcd.setCursor(9,1);
lcd.print(":");
}
if(S>9)
{
lcd.setCursor(10,1);
lcd.print(S);
}
else
{
lcd.setCursor(10,1);
lcd.print("0");
lcd.setCursor(11,1);
lcd.print(S);
lcd.setCursor(12,1);
lcd.print(" ");
}
if(H>9)
{
lcd.setCursor(4,1);
lcd.print (H);
}
else
{
lcd.setCursor(4,1);
lcd.print("0");
lcd.setCursor(5,1);
lcd.print(H);
lcd.setCursor(6,1);
lcd.print(":");
}
}