Arduino Countdown Timer
3 berichten
• Pagina 1 van 1
Arduino Countdown Timer
ik heb deze timer nagebouwt :
/*
arduino CondownTimer
====================
by Markus Klingler
5min-70min
set time in steps of 5 minutes with a button
====================
*/
//liberys
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//pins
const byte button = 10; //the button (conectet to ground)
const byte buzzer =8; //a piezo buzzer (conectet to ground)
const byte bgr=9; //backgroundlight from lcd (conectet to ground)
const byte outp=7; //an output pin, it drivs up when time's up
byte readbutton =1;
//values -why it dos'nt work with unsigned long?
double time =0; //the absolutly time in microseconds
double timeb =0; //the restly time till the end - it displayt on lcd in minutes and seconds
double secondsa=0; //values to convert "timeb" to display it on lcd in seconds and minutes
int secondsb=0;
double secondsc=0;
int minutes=0;
double timebgr=0; //for backlight timeout
double mic=0;
//======================================init the board
void setup(){
//set inputs and outputs
pinMode(button, INPUT);
digitalWrite(button,1);
pinMode(buzzer, OUTPUT);
pinMode(bgr, OUTPUT);
digitalWrite(bgr, HIGH);
pinMode(outp, OUTPUT);
pinMode(outp,LOW);
//init lcd
lcd.begin(16, 2);
lcd.clear();
//display welcome message
lcd.print(" Arduino");
lcd.setCursor(0,1);
lcd.print(" Timer V2.2");
delay(1000);
//clear lcd
lcd.clear();
lcd.print("Press to setTime");
}
//======================================main Loop
void loop(){
//--------------------------------print the time
//convert timeb value
secondsa=timeb/1000000;
minutes=secondsa/60;
secondsc=minutes*60;
secondsb=secondsa-secondsc;
//and print it to lcd
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
if(minutes<10){
lcd.print("00");
lcd.setCursor(1,1);
}
lcd.print(minutes);
lcd.setCursor(2,1);
lcd.print(":");
lcd.setCursor(3,1);
lcd.print(" ");
lcd.setCursor(3,1);
if(secondsb<10){
lcd.print("00");
lcd.setCursor(4,1);
}
lcd.print(secondsb);
delay(50);
//--------------------------------countdown
if(time!=0){ //count only time isn't 0 (button dos'nt pressd)
lcd.setCursor(0,0);
lcd.print("Countdown ");
timeb=time-micros();
mic=micros();
if(timebgr<mic){ //Backlight timeout - check if button 2 seconds dosn't pressd
analogWrite(bgr, 80); //and dimm the backlight of lcd
}
//time's up (end loop)
while(timeb<=0){
digitalWrite(outp,HIGH);
lcd.setCursor(0,0);
lcd.print("Time is up ");
tone(buzzer, 1100);
delay(500);
noTone(buzzer);
digitalWrite(bgr,LOW);
delay(500);
digitalWrite(bgr,HIGH);
}
}
//--------------------------------button and timeseting
//read button
readbutton= digitalRead(button);
//button presed
if(readbutton==LOW){
delay(50);
digitalWrite(bgr,HIGH);
if(time==0){ //do this if time = 0 (while starting, if button pressed fist)
time=time+micros();
timeset(); //call sub: timeset
}
//set the time
mic=micros();
if(timebgr>mic){ //set time if backlight 100% - else no
timeset();
}
timebgr=micros()+2000000; //for backlight timeout
readbutton=digitalRead(button);
while(readbutton==LOW){
readbutton=digitalRead(button);
delay(50);
}
}
}
//======================================sub: timeset
// to set time while button pressed
void timeset(){
tone(buzzer, 1100, 50);
if(time<4200000000){ //add 5 minutes if time smaler then 70 minutes (the overflowpoint of micros();)
time=time+300000000; //time + 5 minutes
}else{ //or no if biger then 70 minutes
lcd.setCursor(0,0);
lcd.print("Max Time reached");
delay(750);
}
}
nu wil ik een relais kunnen aansturen,maar ik weet niet hoe ik dit moet , zou iemand me verder kunnen helpen?
groetjes
richard
/*
arduino CondownTimer
====================
by Markus Klingler
5min-70min
set time in steps of 5 minutes with a button
====================
*/
//liberys
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//pins
const byte button = 10; //the button (conectet to ground)
const byte buzzer =8; //a piezo buzzer (conectet to ground)
const byte bgr=9; //backgroundlight from lcd (conectet to ground)
const byte outp=7; //an output pin, it drivs up when time's up
byte readbutton =1;
//values -why it dos'nt work with unsigned long?
double time =0; //the absolutly time in microseconds
double timeb =0; //the restly time till the end - it displayt on lcd in minutes and seconds
double secondsa=0; //values to convert "timeb" to display it on lcd in seconds and minutes
int secondsb=0;
double secondsc=0;
int minutes=0;
double timebgr=0; //for backlight timeout
double mic=0;
//======================================init the board
void setup(){
//set inputs and outputs
pinMode(button, INPUT);
digitalWrite(button,1);
pinMode(buzzer, OUTPUT);
pinMode(bgr, OUTPUT);
digitalWrite(bgr, HIGH);
pinMode(outp, OUTPUT);
pinMode(outp,LOW);
//init lcd
lcd.begin(16, 2);
lcd.clear();
//display welcome message
lcd.print(" Arduino");
lcd.setCursor(0,1);
lcd.print(" Timer V2.2");
delay(1000);
//clear lcd
lcd.clear();
lcd.print("Press to setTime");
}
//======================================main Loop
void loop(){
//--------------------------------print the time
//convert timeb value
secondsa=timeb/1000000;
minutes=secondsa/60;
secondsc=minutes*60;
secondsb=secondsa-secondsc;
//and print it to lcd
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
if(minutes<10){
lcd.print("00");
lcd.setCursor(1,1);
}
lcd.print(minutes);
lcd.setCursor(2,1);
lcd.print(":");
lcd.setCursor(3,1);
lcd.print(" ");
lcd.setCursor(3,1);
if(secondsb<10){
lcd.print("00");
lcd.setCursor(4,1);
}
lcd.print(secondsb);
delay(50);
//--------------------------------countdown
if(time!=0){ //count only time isn't 0 (button dos'nt pressd)
lcd.setCursor(0,0);
lcd.print("Countdown ");
timeb=time-micros();
mic=micros();
if(timebgr<mic){ //Backlight timeout - check if button 2 seconds dosn't pressd
analogWrite(bgr, 80); //and dimm the backlight of lcd
}
//time's up (end loop)
while(timeb<=0){
digitalWrite(outp,HIGH);
lcd.setCursor(0,0);
lcd.print("Time is up ");
tone(buzzer, 1100);
delay(500);
noTone(buzzer);
digitalWrite(bgr,LOW);
delay(500);
digitalWrite(bgr,HIGH);
}
}
//--------------------------------button and timeseting
//read button
readbutton= digitalRead(button);
//button presed
if(readbutton==LOW){
delay(50);
digitalWrite(bgr,HIGH);
if(time==0){ //do this if time = 0 (while starting, if button pressed fist)
time=time+micros();
timeset(); //call sub: timeset
}
//set the time
mic=micros();
if(timebgr>mic){ //set time if backlight 100% - else no
timeset();
}
timebgr=micros()+2000000; //for backlight timeout
readbutton=digitalRead(button);
while(readbutton==LOW){
readbutton=digitalRead(button);
delay(50);
}
}
}
//======================================sub: timeset
// to set time while button pressed
void timeset(){
tone(buzzer, 1100, 50);
if(time<4200000000){ //add 5 minutes if time smaler then 70 minutes (the overflowpoint of micros();)
time=time+300000000; //time + 5 minutes
}else{ //or no if biger then 70 minutes
lcd.setCursor(0,0);
lcd.print("Max Time reached");
delay(750);
}
}
nu wil ik een relais kunnen aansturen,maar ik weet niet hoe ik dit moet , zou iemand me verder kunnen helpen?
groetjes
richard
Advertisement
Re: Arduino Countdown Timer
er gaat een led aan in het origineel.
daar kun je dus een relais opzetten, wel met een fet, uln2003 of een transistor (vaak zitten die op de relaisbordjes die je kunt kopen.
daar kun je dus een relais opzetten, wel met een fet, uln2003 of een transistor (vaak zitten die op de relaisbordjes die je kunt kopen.
paul deelen
shooter@home.nl
shooter@home.nl
3 berichten
• Pagina 1 van 1
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 43 gasten