timmer resseting without complete reset of counter?

Hi, I have a small bug over here.... here is a relay activator (pin) with LCD display and buzzer (pin2) for a location spot here. I need to set a switch only for resseting my timer and lcd but not reseting the ''hits counter'') just to get an other 20:09 min back on time. (only if a person dont take the complete 15 minutes, so we wont wait the ''5-10 minutes to complete the ''location time'' before going back on) thank you. ( I can had a switch just to reset the time )

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int switchPin = 2;
int hits = 0;

int switchState = 0;
int pin = 13;
int pin2 = 12;

int prevSwitchState = 0;
void setup() {

lcd.begin(16, 2);

pinMode(switchPin,INPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Welcome ");
lcd.setCursor(0, 1);
lcd.print("location timmer");
}
void loop() {

switchState = digitalRead(switchPin);

if (switchState != prevSwitchState) {
if (switchState == HIGH) {
hits = hits + 1;
digitalWrite(pin, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("#location number");
lcd.setCursor(7, 1);
lcd.print(hits);
delay(15601000); // location 15 minutes
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 15Min done ");
lcd.setCursor(0, 1);
lcd.print("Return to deck");
digitalWrite(pin2, HIGH);
delay(3000);
digitalWrite(pin2, LOW);
delay(3000);
digitalWrite(pin2, HIGH);
delay(3000);
digitalWrite(pin2, LOW);
delay(3601000); // 3 minutes
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" timer down ");
lcd.setCursor(0, 1);
lcd.print(" Return to deck ");
delay(1601000); //return to deck
digitalWrite(pin2, HIGH);
delay(1601000);
digitalWrite(pin2, LOW);
digitalWrite(pin, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Total locations:");
lcd.setCursor(7, 1);
lcd.print(hits);
}
}
prevSwitchState = switchState;
}

Your long delay calculations don't fit into an int. Add a "UL" after one of the numbers to force the calculation to be unsigned long.

delay(15*60*1000UL)

you have a lot of blocking delay() functions in your code.

you should look into the BlinkWithoutDelay example in the IDE. It will allow you, for example, to use pushbuttons without the blocking affecting their performance.

you'll notice that pushbutton does not seem to respond as you may expect.

is it possible to show me an example, not yet able to understand everything. I'll explain you what kind of program i'm using

it's a Flyboard company we have here, we rent flyboard with a 15 and 20 min. locations.

the Buzzer is to let the driver on the seadoo know that there is (first buzz) 15 min is done and the second one is to let him know it's time to go back to deck because the other relay output is for the ignition switch kill so it stops the engine after 20 minutes. If someone renting the flyboard stops after 10 minutes because he cannot get more than that we have to wait the complete 20 minutes to set it back on :confused: thats my problem here, that's why I would like to ''when I push the switch back on it counts an other ''rental'' and sets the timer back to 20 minutes !?

KeithRB:
Your long delay calculations don't fit into an int. Add a "UL" after one of the numbers to force the calculation to be unsigned long.

delay(15*60*1000UL)

thanks bout it, didn't know :wink:

here's where i'm at right now... is the ex: millis() +5000, same S*%@ as Delay?

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int switchPin = 2;
const int relayPin = 13;
unsigned long off_time;
int hits = 0;

boolean relayState=false;

int switchState = 0;
int prevSwitchState = 0;

void setup() {
lcd.begin (16,2);
pinMode(relayPin, OUTPUT);
pinMode(switchPin, INPUT);
digitalWrite(relayPin, LOW);
}

void loop(){

if ((relayState) && (millis()>=off_time))
{
digitalWrite(relayPin,LOW);
relayState = false;
}
else if (!relayState)
{
switchState = digitalRead(switchPin);
if(switchState == HIGH)
{
digitalWrite(relayPin, HIGH);
relayState = true;
off_time = millis()+500;
}
lcd.setCursor (0,0);
lcd.print ("Flyboard Rental");
lcd.setCursor (7,1);
lcd.print(hits);
switchState = digitalRead(switchPin);
if (switchState != prevSwitchState) {
if (switchState == HIGH) {
hits = hits + 1;}

}}}

idle_up:
here's where i'm at right now... is the ex: millis() +5000, same S*%@ as Delay?

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int switchPin = 2;
const int relayPin = 13;
unsigned long off_time;
int hits = 0;

boolean relayState=false;

int switchState = 0;
int prevSwitchState = 0;

void setup() {
lcd.begin (16,2);
pinMode(relayPin, OUTPUT);
pinMode(switchPin, INPUT);
digitalWrite(relayPin, LOW);
}

void loop(){

if ((relayState) && (millis()>=off_time))
{
digitalWrite(relayPin,LOW);
relayState = false;
}
else if (!relayState)
{
switchState = digitalRead(switchPin);
if(switchState == HIGH)
{
digitalWrite(relayPin, HIGH);
relayState = true;
off_time = millis()+500;
}
lcd.setCursor (0,0);
lcd.print ("Flyboard Rental");
lcd.setCursor (7,1);
lcd.print(hits);
switchState = digitalRead(switchPin);
if (switchState != prevSwitchState) {
if (switchState == HIGH) {
hits = hits + 1;}

}}}

OK, so let me understand this better:

a person is renting a jetski

they push the button, it
a) increments a counter indicating the number of time chunks they must now pay for
b) closes a relay and allows the jet ski to be started
c) starts a timer that will cause a buzz at 5mins remaining

when the 20min timer expires,
a) the relay opens the ignition circuit and the jet ski stops

at that time the person pushes the button again , they activate another rental cycle.

Do I have it?

so you have two outputs ( the Relay and the Buzzer) and the lcd display?

one input... some sort of (water tight) pushbutton)

you can play with this uncompiled and untested bit of code:

#define RENTAL_PERIOD 20
#define BUZZER_ON_TIME 15

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int buttonPin = 2;
const int ignitionPin = 12;
const int buzzerPin = 13;

int secondsRemaining;
int state;
int lcdState;
int hits = 0;
int switchState = 0;
int prevSwitchState = 0;
unsigned int lcdCounter;

unsigned long startTime;
unsigned long oneSecond = 1000UL;
//
void setup() 
{  
  Serial.begin(9600);
  secondsRemaining = RENTAL_PERIOD * 60;
  lcd.begin(16, 2);
  pinMode(buttonPin,INPUT);
  pinMode(ignitionPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   Welcome   ");
  lcd.setCursor(0, 1);
  lcd.print("location timmer");
  delay(1000);
}
void loop() 
{  
  switchState = digitalRead(buttonPin);//let's get the button press out of the wy of the rest of th ecode
  if (switchState != prevSwitchState) 
  {
    if (switchState == HIGH) 
    {
      if (state == 0) 
      {
        pinMode(ignitionPin, HIGH);
        state = 1;
        startTime = millis();
        hits++;
        lcd.clear();
      }
      else
      {
        //do nothing
      }
    }
  }
  if (state == 1)
  {
    if (millis() - startTime >= oneSecond)
    {
      secondsRemaining--;
      updateLCD();
      startTime += oneSecond;
    }
    if (secondsRemaining == BUZZER_ON_TIME * 60)
    {
      digitalWrite(buzzerPin, HIGH);
    }
    if (secondsRemaining == BUZZER_ON_TIME * 60 + 15) //15 second buzzer
    {
      digitalWrite(buzzerPin, LOW);
    }
    if (secondsRemaining <= 0)
    {
      state = 0;
      lcd.clear();
    } 
  }
  else if (state == 0)
  {
    digitalWrite(ignitionPin, LOW);
    if (millis() - startTime >= oneSecond)
    {
      updateLCD();
      startTime += oneSecond;
    }
  }
}
//
void updateLCD()
{
  if (state = 1)
  {
    int myMinutes = secondsRemaining / 60;
    int mySeconds = secondsRemaining % 60;
    lcd.setCursor(0, 0);
    lcd.print("Time: ");
    if (myMinutes < 10) lcd.print("0");
    lcd.print(myMinutes);
    lcd.print(":");
    if (mySeconds < 10) lcd.print("0");
    lcd.print(mySeconds);
    lcd.setCursor(0, 1);
    lcd.print("Number of Hits:");
    if (hits < 10) lcd.print(" ");
    lcd.print(hits);
  }
  else
  {
    lcdCounter++;
    if (lcdCounter % 3 == 0) lcdState = (1 - lcdState);//toggle display over 3 seconds
    if (lcdState)
    {
      lcd.setCursor(0, 0);
      lcd.print("   15Min done   ");
      lcd.setCursor(0, 1);
      lcd.print(" Return to deck ");
    }
    else
    {
      lcd.setCursor(0, 0);
      lcd.print("Total Locations: ");
      lcd.print(hits);
      lcd.setCursor(0, 1);
      lcd.print("FlyBoard Rental ");
    }
  }
}

BulldogLowell:

idle_up:
here's where i'm at right now... is the ex: millis() +5000, same S*%@ as Delay?

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int switchPin = 2;
const int relayPin = 13;
unsigned long off_time;
int hits = 0;

boolean relayState=false;

int switchState = 0;
int prevSwitchState = 0;

void setup() {
lcd.begin (16,2);
pinMode(relayPin, OUTPUT);
pinMode(switchPin, INPUT);
digitalWrite(relayPin, LOW);
}

void loop(){

if ((relayState) && (millis()>=off_time))
{
digitalWrite(relayPin,LOW);
relayState = false;
}
else if (!relayState)
{
switchState = digitalRead(switchPin);
if(switchState == HIGH)
{
digitalWrite(relayPin, HIGH);
relayState = true;
off_time = millis()+500;
}
lcd.setCursor (0,0);
lcd.print ("Flyboard Rental");
lcd.setCursor (7,1);
lcd.print(hits);
switchState = digitalRead(switchPin);
if (switchState != prevSwitchState) {
if (switchState == HIGH) {
hits = hits + 1;}

}}}

OK, so let me understand this better:

a person is renting a jetski

they push the button, it
a) increments a counter indicating the number of time chunks they must now pay for
b) closes a relay and allows the jet ski to be started
c) starts a timer that will cause a buzz at 5mins remaining

when the 20min timer expires,
a) the relay opens the ignition circuit and the jet ski stops

at that time the person pushes the button again , they activate another rental cycle.

Do I have it?

so you have two outputs ( the Relay and the Buzzer) and the lcd display?

one input... some sort of (water tight) pushbutton)

you can play with this uncompiled and untested bit of code:

#define RENTAL_PERIOD 20

#define BUZZER_ON_TIME 15

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int buttonPin = 2;
const int ignitionPin = 12;
const int buzzerPin = 13;

int secondsRemaining;
int state;
int lcdState;
int hits = 0;
int switchState = 0;
int prevSwitchState = 0;
unsigned int lcdCounter;

unsigned long startTime;
unsigned long oneSecond = 1000UL;
//
void setup()
{  
 Serial.begin(9600);
 secondsRemaining = RENTAL_PERIOD * 60;
 lcd.begin(16, 2);
 pinMode(buttonPin,INPUT);
 pinMode(ignitionPin, OUTPUT);
 pinMode(buzzerPin, OUTPUT);
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("   Welcome   ");
 lcd.setCursor(0, 1);
 lcd.print("location timmer");
 delay(1000);
}
void loop()
{  
 switchState = digitalRead(buttonPin);//let's get the button press out of the wy of the rest of th ecode
 if (switchState != prevSwitchState)
 {
   if (switchState == HIGH)
   {
     if (state == 0)
     {
       pinMode(ignitionPin, HIGH);
       state = 1;
       startTime = millis();
       hits++;
       lcd.clear();
     }
     else
     {
       //do nothing
     }
   }
 }
 if (state == 1)
 {
   if (millis() - startTime >= oneSecond)
   {
     secondsRemaining--;
     updateLCD();
     startTime += oneSecond;
   }
   if (secondsRemaining == BUZZER_ON_TIME * 60)
   {
     digitalWrite(buzzerPin, HIGH);
   }
   if (secondsRemaining == BUZZER_ON_TIME * 60 + 15) //15 second buzzer
   {
     digitalWrite(buzzerPin, LOW);
   }
   if (secondsRemaining <= 0)
   {
     state = 0;
     lcd.clear();
   }
 }
 else if (state == 0)
 {
   digitalWrite(ignitionPin, LOW);
   if (millis() - startTime >= oneSecond)
   {
     updateLCD();
      startTime += oneSecond;
   }
 }
}
//
void updateLCD()
{
 if (state = 1)
 {
   int myMinutes = secondsRemaining / 60;
   int mySeconds = secondsRemaining % 60;
   lcd.setCursor(0, 0);
   lcd.print("Time: ");
   if (myMinutes < 10) lcd.print("0");
   lcd.print(myMinutes);
   lcd.print(":");
   if (mySeconds < 10) lcd.print("0");
   lcd.print(mySeconds);
   lcd.setCursor(0, 1);
   lcd.print("Number of Hits:");
   if (hits < 10) lcd.print(" ");
   lcd.print(hits);
 }
 else
 {
   lcdCounter++;
   if (lcdCounter % 3 == 0) lcdState = (1 - lcdState);//toggle display over 3 seconds
   if (lcdState)
   {
     lcd.setCursor(0, 0);
     lcd.print("   15Min done   ");
     lcd.setCursor(0, 1);
     lcd.print(" Return to deck ");
   }
   else
   {
     lcd.setCursor(0, 0);
     lcd.print("Total Locations: ");
     lcd.print(hits);
     lcd.setCursor(0, 1);
     lcd.print("FlyBoard Rental ");
   }
 }
}

That's almost it :smiley: , what I need is (the driver can reset the button with the button on the seadoo at anytime (driver is one of our employe) so it will reset the time at 20:00 minutes eaven if the timer is still at 5 min left (but it will count an other hit and start the 20+buzzer minutes all over). I tried over and over to get the millis() code working, but still need a couple of hours on it. thanks for your help

get rid of this block of code by commenting out like so.... and test

  if (switchState != prevSwitchState) 
  {
    if (switchState == HIGH) 
    {
      //if (state == 0) //<<<<<<<<<<<THIS HERE<<<<<<<<<<<<<<
      //{
        pinMode(ignitionPin, HIGH);
        state = 1;
        startTime = millis();
        hits++;
        lcd.clear();
      //}
      //else
      //{
        //do nothing
      //}
    }
  }

Ill try it out tomorrow thank you i learned the bad way (delay) and now tryin to catch up :stuck_out_tongue: (and srry bout my english i'm french, from montreal canada)