//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
#include "JC_Button.h"
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int modepin = 9;
int parapin = 8;
int modesta = LOW;
int parasta = LOW;
int pin100 = 12;
int pin010 = 11;
int pin001 = 10;
int sta100 = HIGH;
int sta010 = HIGH;
int sta001 = HIGH;
Button my100(pin100);
Button my010(pin010);
Button my001(pin001);
uint8_t backslash[8] = {
0b00000,
0b10000,
0b01000,
0b00100,
0b00010,
0b00001,
0b00000,
0b00000,
};
const char *loopChars = "-\x03|/";
int i;
int imax;
unsigned long curTime;
unsigned long myTime;
const long myInterval = 80;
int i001=0;
int i010=0;
int i100=0;
int curval=0;
void clrIndicator()
{
lcd.setCursor(0, 0);
lcd.print("\xFF");
lcd.setCursor(0, 1);
lcd.print("\xFF");
}
void setup()
{
pinMode(modepin, INPUT_PULLUP);
pinMode(parapin, INPUT_PULLUP);
Serial.begin(115200);
lcd.init(); // initialize the lcd
lcd.createChar(3, backslash);
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(4, 3);
lcd.print("Hello, world!");
imax = strlen(loopChars);
clrIndicator();
pinMode(pin100, INPUT_PULLUP);
pinMode(pin010, INPUT_PULLUP);
pinMode(pin001, INPUT_PULLUP);
my100.begin();
my010.begin();
my001.begin();
}
void loop()
{
int imodesta = digitalRead(modepin);
int iparasta = digitalRead(parapin);
int ichk;
curTime = millis();
bool refresh = (imodesta != modesta);
if (refresh) {
modesta = imodesta;
if (modesta == LOW) {
clrIndicator();
}
Serial.print(modesta);
Serial.print(" | ");
Serial.println(parasta);
}
else {
if (modesta == HIGH || refresh) {
if (modesta == HIGH){
chkTime();
//curval = chk100Up();
ichk = chkXXXup();
if(ichk != curval){
curval = ichk;
lcd.setCursor(0,2);
lcd.print(curval);
Serial.println(curval);
}
}
if (iparasta != parasta) {
lcd.setCursor(0, 1);
parasta = iparasta;
lcd.print(parasta);
Serial.print(modesta);
Serial.print(" | ");
Serial.println(parasta);
}
//Serial.println(curval);
}
}
}
int chkXXXup()
{
my100.read();
my010.read();
my001.read();
if(my001.wasReleased()){
i001++;
if (i001 >= 10) i001 = 0;
}
if(my010.wasReleased()){
i010++;
if (i010 >= 10) i010 = 0;
}
if(my100.wasReleased()){
i100++;
if (i100 >= 10) i100 = 0;
}
return (100*i100+10*i010+i001);
}
/*
int chk100Up()
{
int value;
value = digitalRead(pin001);
if (sta001 != value) {
sta001 = value;
if(sta001 == HIGH){
i001++;
if (i001 >= 10) i001 = 0;
}
}
value = digitalRead(pin010);
if (sta010 != value) {
sta010 = value;
if(sta010 == HIGH){
i010++;
if (i010 >= 10) i010 = 0;
}
}
value = digitalRead(pin100);
if (sta100 != value) {
sta100 = value;
if(sta100 == HIGH){
i100++;
if (i100 >= 10) i100 = 0;
}
}
return (100*i100+10*i010+i001);
}
*/
void chkTime()
{
if (curTime - myTime >= myInterval) {
myTime = curTime;
lcd.setCursor(0, 0); lcd.print(loopChars[i]);
i++;
if (i == imax)
i = 0;
}
}