#include <LiquidCrystal.h>
#define TICK 0.0 // the amount of milliseconds between any stopwatch update
const int SWPin = 10;
const int XPin = 0;
const int YPin = 1;
int seconds = 0;
int minutes = 0;
int hours = 0;
bool on = false;
// int onTime = 0;
// int offTime = 3;
// int durTime = 2;
// int tvac1;
// int tvac2 = tvac1 + durTime;
// int num;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // RS,EN,D4,D5,D6,D7 pin of LCD respectively
#define LED_PIN 9
/*
Arduino Turn LED On/Off using Serial Commands
Created April 22, 2015
Hammad Tariq, Incubator (Pakistan)
It's a simple sketch which waits for a character on serial
and in case of a desirable character, it turns an LED on/off.
Possible string values:
a (to turn the LED on)
b (tor turn the LED off)
*/
// char junk;
// String inputString="";
// void SSET() // run once, when the sketch starts
// {
// Serial.begin(115250); // set the baud rate to 9600, same should be of your Serial Monitor
// pinMode(LED_PIN, OUTPUT);
// Serial.println("hi");
// }
// void SYES() {
// if (Serial.available()) {
// while (Serial.available()) {
// char inChar = (char)Serial.read(); //read the input
// inputString += inChar; //make a string of the characters coming on serial
// }
// Serial.println(inputString);
// while (Serial.available() > 0) {
// junk = Serial.read(); // clear the serial buffer
// }
// if (inputString == "a") {
// onTime++;
// if(onTime > 23) {
// onTime = 0;
// }
// if(offTime < onTime + 1) {
// offTime = onTime + 1;
// }
// } else if (inputString == "b") {
// onTime--;
// if(onTime < 0) {
// onTime = 23;
// }
// if(offTime < onTime + 1) {
// offTime = onTime + 1;
// }
// } else if (inputString == "x") {
// offTime++;
// if(offTime > 23) {
// offTime = 0;
// }
// if(offTime < onTime + 1) {
// offTime = onTime + 1;
// }
// } else if (inputString == "y") {
// offTime--;
// if(offTime < 0) {
// offTime = 23;
// }
// if(offTime < onTime + 1) {
// offTime = onTime + 1;
// }
// } else if (inputString == "z") {
// durTime--;
// if(durTime < 0) {
// durTime = 0;
// }
// } else if (inputString == "q") {
// durTime++;
// } else if (inputString == "c") {
// lcd.setCursor(0,1);
// lcd.print(" ");
// while(true) {
// if(analogRead(YPin) == 0) {
// on = true;
// }
// if(analogRead(YPin) == 1023) {
// on = false;
// }
// if(on == true) {
// LCD();
// }
// }
// } else {
// int number = inputString.toInt();
// if (number > 0 && number <= 23) {
// tvac1 = number;
// }
// }
// inputString = "";
// lcd.print(" ");
// lcd.setCursor(0,0);
// lcd.print("On Time:");
// print_padded_number(onTime);
// lcd.setCursor(0,1);
// lcd.print("Off Time:");
// print_padded_number(offTime);
// lcd.setCursor(11,0);
// lcd.print("DT:");
// print_padded_number(durTime);
// }
// }
void JOY(){
if(analogRead(YPin) == 0) {
on = true;
}
if(analogRead(YPin) == 1023) {
on = false;
}
if(on == true) {
LCD();
}
}
void init_lcd() {
lcd.begin(16, 2); // sets the number of columns and rows
pinMode(LED_PIN, OUTPUT);
lcd.setCursor(0, 0);
lcd.print("On Time:1-7");
}
void increment_time() {
seconds++;
if (seconds > 30) {
seconds = 0;
minutes++;
}
if (minutes > 59) {
minutes = 0;
hours++;
}
if (hours > 23) {
hours = 0;
}
}
void print_padded_number(int number) {
if (number < 10) lcd.print("0");
lcd.print(number);
}
void print_time() {
// lcd.setCursor(12,1);
// lcd.print(tvac1);
lcd.setCursor(0,1);
// tvac2 = tvac1 + durTime;
digitalWrite(LED_PIN, hours >= 1 && hours < 7 ? HIGH:LOW);
print_padded_number(hours);
lcd.print(":");
print_padded_number(minutes);
lcd.print(":");
print_padded_number(seconds);
}
void LCDSET() {
init_lcd();
}
void LCD() {
increment_time();
print_time();
delay(TICK);
}
void JOYSET() {
pinMode(SWPin, INPUT);
}
void setup(){
//SSET();
LCDSET();
JOYSET();
}
void loop(){
// SYES();
JOY();
}