So for my project, I am making a button that turns on and off an LED, but also display the state of the led on an LCD and by Serial. But my issue is, I don't want it to just show a 0 or a 1, I want it to say On or Off.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int inPin = 22; // the number of the input pin
int outPin = 13; // the number of the output pin
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup(){
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("System Activated");
//
lcd.setCursor(0, 1);
lcd.print("Ready...");
pinMode(inPin, INPUT);
pinMode(outPin, OUTPUT);
Serial.begin(9600);
Serial.println("System Activated");
Serial.println("Made by Mateo Holguin");
Serial.println("0 = Light is Off | 1 = Light is On");
Serial.println("=======================================");
}
void loop(){
reading = digitalRead(inPin);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
Serial.println("Button Switch State Change:");
if (state == HIGH)
state = LOW;
else
state = HIGH;
Serial.println(state);
Serial.println("");
lcd.clear();
lcd.print("State: ");
lcd.print(state);
time = millis();
}
digitalWrite(outPin, state);
previous = reading;
}