Hello all,
I 'am new with the arduino , but the examples in the getting started book is not the problem for me for first of this begin with the arduino,
Now i will do an experiment with more buttons and text ( display at serial or LCD ) , with one button it will works
But now i will make a sketch with more buttons,
So when i Push button one , the screen display as example button 1 is pressed
And when i push button two , the screen displays as example button 2 is pressed , and further and further,
Now i have make a simple sketch as example with one button (Door contact ) , but i like to make this sketch with more buttons:
/*
- Door alarm switch test
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int switchPin = 2; // switch is connected to pin 2
int val; // variable for reading the pin status
int buttonState; // variable to hold the last button state
void setup() {
lcd.init();
lcd.backlight();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(switchPin, INPUT); // Set the switch pin as input
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
Serial.begin(9600); // Set up serial communication at 9600bps
buttonState = digitalRead(switchPin); // read the initial state
}
void loop(){
val = digitalRead(switchPin); // read input value and store it in val
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is NOT pressed
lcd.clear();
Serial.println("Door contact 1 Restored "); // put at serial
lcd.println(" Door contact 1 "); // put text at row 1 lcd
lcd.setCursor(0, 1); // use row 2
lcd.print(" Restored ");// row 2 at lcd
} else { // the button is pressed...
lcd.clear();
Serial.println("Door contact 1 Activated ");// at serial
lcd.println(" Move Detection ");// row 1 at lcd
lcd.setCursor(0, 1);//row 2
lcd.print("** Activated **");//row 2 at lcd
}
}
buttonState = val; // save the new state in our variable
}
This sketch is working correct , for now ,
I hope someone can help me further !!!
smiley-mr-green