Got my son a puppy but he's sort of young, 12, I'd like him to have a timer that tells him to walk the pup. I'd like to teach him responsibility and while I thought based on online countdown timers that this would be easier I'm now stuck on an error and the pup is nearly 16 weeks the walks are really starting to make a difference, hard to keep up with a lab!
I don't want my son stuck on his video games so hopefully this litter timer can get him and the pup into a good routine.
//puppy timer, remember 1000 millis = 1 second
#include <LiquidCrystal.h>
#include <Tone.h>
//initialize the library with the number of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Tone tone1 = 8; //sets piezo outpin pin as a tone output
int startButton = 10; //start switch on digital pin 10
int start = 1024; //value for storage of start button
int hours1 = 2; //timer1 variable to display hours on lcd
int minutes1 = 30; //timer1 variable to display minutes on lcd
int seconds1 = 0; //timer1 variable to display seconds on lcd
int totalseconds1 = 0; //total time of timer1
int hours2 = 0; //timer2 variable to display hours on lcd
int minutes2 = 15; //timer2 variable to display minutes on lcd
int seconds2 = 0; //timer2 variable to display seconds on lcd
int totalseconds2 = 0; //total time of timer2
int msg = 0; //value for the welcome message
void setup()
{
// put your setup code here, to run once:
//set up the LCD's number of column and rows:
lcd.begin(16,2);
pinMode(tone1, OUTPUT); //sets pin 8 as piezo output
pinMode(startButton, INPUT); //sets pin 10 as start input
msg = 0; //value of welcome message
start = 1024; //value of start button
}
void loop()
{
// put your main code here, to run repeatedly:
if(msg==0) //show the welcome message only 1 time
{
lcd.setCursor(0,0);
lcd.print("Puppy Walk");
lcd.setCursor(0,1);
lcd.print("Schedule for me");
delay(2500);
msg = 2;
lcd.clear();
}
do
{
//begins
lcd.setCursor(0,0);
lcd.print(""); //if hours are less than 10, put a zero in front
lcd.print(hours1); //without this code, it'll show as H:M:S (1:M:S)
lcd.print(":");
lcd.print(""); //if minutes are less than 10, put zero in front
lcd.print(minutes1); //without this code, it'll show as H:M:S (H:1:S)
lcd.print(":");
if (seconds1 < 10) lcd.print("0"); //if seconds are less than 10, put zero in front
lcd.print(seconds1); //without this code, it'll show as H:M:1
start = digitalRead(startButton); //reads start button
if (start == 0) //if the start button was pressed...
{
totalseconds1 = seconds1 + (minutes1 * 60) + (hours1 * 60 * 60); //converts time to seconds
}
if (totalseconds1 == 0)
lcd.clear();
lcd.setCursor(0,0);
lcd.print("");
lcd.print(hours2);
lcd.print(":");
lcd.print("");
lcd.print(minutes2);
lcd.print(":");
if (seconds2 < 10) lcd.print("0");
lcd.print(seconds2);
{
totalseconds2 = seconds2 + (minutes2 * 60) + (hours2 * 60 * 60);
}
} while(start != 0); //menu of preset time repeats until button is pressed
//Once the button has been pressed, it goes into next while and won't finalize until end
while (totalseconds1 > 0)
{
delay (1000); //decrement in periods of 1 second
totalseconds1--;
hours1 = ((totalseconds1 / 60)/ 60); //converts total seconds into hours
minutes1 = (totalseconds1 / 60) % 60; //converts total seconds into minutes
seconds1 = totalseconds1 % 60; //converts total seconds into periods of 60 seconds
lcd.setCursor(0,0);
lcd.print("Next walk in..."); //we display timer remaining message
lcd.setCursor(4,1);
if (hours1 < 10) lcd.print("0"); //if hours are less than 10, put a zero in front of it
lcd.print(hours1);
lcd.print(":");
if (minutes1 < 10) lcd.print("0");
lcd.print(minutes1);
if (seconds1 < 10) lcd.print("0");
lcd.print(seconds1);
if (totalseconds1 == 0) //time block 1 has finalized
{
while(1)
{
lcd.clear();
lcd.setCursor(5,0);
lcd.print("Walk the puppy!");
lcd.setCursor(3,1);
lcd.print("15 Minutes");
tone1.play(400, 600);
delay(100);
tone1.play(587, 300);
delay(100);
}
}
}
while (totalseconds2 > 0)
{
delay (1000); //decrementation of periods by 1 second for timer2
totalseconds2--;
hours2 = ((totalseconds2 / 60)/ 60);
minutes2 = (totalseconds2 / 60) % 60;
seconds2 = totalseconds2 % 60;
lcd.setCursor(0,0);
lcd.print("Walk dog for");
lcd.setCursor(4,1);
if (hours2 < 10) lcd.print("0");
lcd.print(hours2);
lcd.print(":");
if (minutes2 < 10) lcd.print("0");
lcd.print(minutes2);
lcd.print(":");
if (seconds2 < 10) lcd.print("0");
lcd.print(seconds2);
if (totalseconds2 == 0)
{
while(1)
{
lcd.clear();
lcd.setCursor(5,0);
lcd.print("Next walk in...");
lcd.setCursor(3,1);
lcd.print("2 hrs 30 mins");
tone1.play (400, 600);
delay(100);
tone1.play (587, 300);
delay(100);
}
}
}
}
I don't understand why I'm getting this error:
Special_Timer_Sketch2:9: error: conversion from 'int' to non-scalar type 'Tone' requested
Special_Timer_Sketch2.ino: In function 'void setup()':
Special_Timer_Sketch2:32: error: cannot convert 'Tone' to 'uint8_t' for argument '1' to 'void pinMode(uint8_t, uint8_t)'
I'd like the timer to run as follows:
Turned on with a switch
Start button for the countdown to begin (each day we wakes up we'll hit this to begin timing the day's walks)
2 hour and 30 minute countdown
15 minute countdown (pup is being walked)
2 hour and 30 minute countdown again
15 minute countdown (pup is being walked)
at the end of each countdown i'd like it to sound the piezo speaker with a tone then go on to the next countdown.
I'm willing to pay if necessary and am hoping to finish before he's out of school next friday. Thanks for your time in advance.