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 ");
}
}
}