From d33248a307c2178efc4dbcc9119af2b30599fc85 Mon Sep 17 00:00:00 2001
From: Dery Rahman Ahaddienata <13515097@std.stei.itb.ac.id>
Date: Fri, 24 Nov 2017 16:51:37 +0700
Subject: [PATCH] Edit lcd on/off
---
earthquake/earthquake.ino | 48 ++++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 13 deletions(-)
diff --git a/earthquake/earthquake.ino b/earthquake/earthquake.ino
index 33ff706..e46d12d 100644
--- a/earthquake/earthquake.ino
+++ b/earthquake/earthquake.ino
@@ -10,6 +10,10 @@
--------------------*/
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
+const int stateOn = 1;
+const int stateOff = 2;
+const int stateConnect = 3;
+
/*--------------------
* Pin const
@@ -29,6 +33,10 @@ const int seismicPin = A0;
/*--------------------
* Global variable
* --------------------*/
+//
+int stateLED = 1;
+
+int valGlobal = 0;
// Toggle button
int state = HIGH; // the current state of the output pin
@@ -37,8 +45,6 @@ int previous = LOW; // the previous reading from the input pin
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
-// LCD
-// LiquidCrystal lcd(0, 1, 8, 9, 10, 11); /// REGISTER SELECT PIN,ENABLE PIN,D4 PIN,D5 PIN, D6 PIN, D7 PIN
// Seven Segment
const byte digit[] = {64, 121, 36, 48, 25, 18, 2, 120, 0, 16};
@@ -91,13 +97,11 @@ void gyroOn();
void gyroOff();
void printLCD(int,int,String);
void clearLCD();
+bool isState(int);
void setup() {
Serial.begin(115200);
-
- lcd.begin(16,2);
- lcd.backlight();
// Toggle button
toggleButtonInit();
@@ -127,13 +131,19 @@ void loop() {
previous = reading;
if(state == HIGH){
+ if(!isState(stateOn)){
+ clearLCD();
+ printLCD(0,0,"Arduino ON");
+ delay(1000);
+ }
gyroOn();
- clearLCD();
- printLCD(0,0,"Arduino ON");
} else {
gyroOff();
- clearLCD();
- printLCD(0,0,"Arduino OFF");
+ if(!isState(stateOff)){
+ clearLCD();
+ printLCD(0,0,"Arduino OFF");
+ delay(1000);
+ }
}
}
@@ -159,7 +169,10 @@ void sevenSegmentInit(){
magnitude = 0;
}
-void lcdInit(){}
+void lcdInit(){
+ lcd.begin(16,2);
+ lcd.backlight();
+}
void gyroInit(){
@@ -240,9 +253,12 @@ double magnitudeConvert() {
}
void displaySevenSegment(int val){
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, MSBFIRST, digit[val]);
- digitalWrite(latchPin, HIGH);
+ if(val!=valGlobal){
+ digitalWrite(latchPin, LOW);
+ shiftOut(dataPin, clockPin, MSBFIRST, digit[val]);
+ digitalWrite(latchPin, HIGH);
+ valGlobal=val;
+ }
}
void ledActive(){
@@ -317,3 +333,9 @@ void clearLCD(){
lcd.clear();
}
+bool isState(int state){
+ int temp = stateLED;
+ stateLED = state;
+ return temp==state;
+}
+
--
GitLab