/*
This code use for open two magnetic door and 1 led on/off using Arduino UNO and 1Sheeld(Keypad Shield)
*/
#define CUSTOM_SETTINGS
#define INCLUDE_KEYPAD_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* Define an iterator. */
int iterations = 0;
/* A name for the LockPin on pin D2. */
int lockPin1 = 2;
int ledRed1 = A5;
int ledGreen1 = A4;
/* A name for the LockPin on pin D3. */
int lockPin2 = 3;
int ledRed2 = A3;
int ledGreen2 = A2;
/* A name for the SwitchPin on pin D5. and LED on pin A0*/
int SuisPinA = 5;
int ledlampuA = A0;
void setup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the LED & LOCK as output. */
pinMode(lockPin1, OUTPUT);
pinMode(ledRed1, OUTPUT);
pinMode(ledGreen1, OUTPUT);
pinMode(lockPin2, OUTPUT);
pinMode(ledRed2, OUTPUT);
pinMode(ledGreen2, OUTPUT);
/* Set the SuisPin pin as output. */
pinMode(SuisPinA, INPUT);
/* Set the LED pin as output. */
pinMode(ledlampuA, OUTPUT);
}
void loop()
{
//======LED=======
/* If keypad's button A is pressed. */
if (Keypad.isRowPressed(0) && Keypad.isColumnPressed(3))
{
/* Turn on the LED A. */
digitalWrite(ledlampuA, HIGH);
}
/* If keypad's button D is pressed. */
else if (Keypad.isRowPressed(3) && Keypad.isColumnPressed(3))
{
/* Turn on the LED A. */
digitalWrite(ledlampuA, LOW);
}
//======Front Door=======
/* Check if "1" is pressed, iterate one time. */
if (iterations == 0 && isOnePressed())
{
iterations++;
}
/* Check if "2" is pressed, iterate one time. */
else if (iterations == 1 && isTwoPressed())
{
iterations++;
}
/* Check if "3" is pressed, iterate one time. */
else if (iterations == 2 && isThreePressed())
{
iterations++;
}
/* Check if "4" is pressed, iterate one time. */
else if (iterations == 3 && isFourPressed())
{
iterations++;
}
/* Check if any other button is pressed, reset iterations. */
else if (isOtherButtonPressed())
{
iterations = 0;
}
/* Check if the number of iterations is 4. */
if (iterations == 4)
{
digitalWrite(lockPin1, LOW);
digitalWrite(ledGreen1, HIGH);
digitalWrite(ledRed1, LOW);
OneSheeld.delay(6000);
digitalWrite(lockPin1, HIGH);
digitalWrite(ledRed1, HIGH);
digitalWrite(ledGreen1, LOW);
OneSheeld.delay(1000);
/* Reset the iterator. */
iterations = 0;
}
//======Garage Door=======
/* Check if "5" is pressed, iterate one time. */
if (iterations == 5 && isFivePressed())
{
iterations++;
}
/* Check if "6" is pressed, iterate one time. */
else if (iterations == 6 && isSixPressed())
{
iterations++;
}
/* Check if "7" is pressed, iterate one time. */
else if (iterations == 7 && isSevenPressed())
{
iterations++;
}
/* Check if "8" is pressed, iterate one time. */
else if (iterations == 8 && isEightPressed())
{
iterations++;
}
/* Check if any other button is pressed, reset iterations. */
else if (isOtherButtonPressed())
{
iterations = 0;
}
/* Check if the number of iterations is 4. */
if (iterations == 4)
{
digitalWrite(lockPin2, LOW);
digitalWrite(ledGreen2, HIGH);
digitalWrite(ledRed2, LOW);
OneSheeld.delay(6000);
digitalWrite(lockPin2, HIGH);
digitalWrite(ledRed2, HIGH);
digitalWrite(ledGreen2, LOW);
OneSheeld.delay(1000);
/* Reset the iterator. */
iterations = 0;
}
/* Helper functions check if a certain button is pressed by checking its row and column. */
boolean isOnePressed() {
return Keypad.isRowPressed(0) && Keypad.isColumnPressed(0);
}
boolean isTwoPressed() {
return Keypad.isRowPressed(0) && Keypad.isColumnPressed(1);
}
boolean isThreePressed() {
return Keypad.isRowPressed(0) && Keypad.isColumnPressed(2);
}
boolean isFourPressed() {
return Keypad.isRowPressed(1) && Keypad.isColumnPressed(0);
}
boolean isFivePressed() {
return Keypad.isRowPressed(1) && Keypad.isColumnPressed(0);
}
boolean isSixPressed() {
return Keypad.isRowPressed(1) && Keypad.isColumnPressed(0);
}
boolean isSevenPressed() {
return Keypad.isRowPressed(1) && Keypad.isColumnPressed(0);
}
boolean isEightPressed() {
return Keypad.isRowPressed(1) && Keypad.isColumnPressed(0);
}
boolean isOtherButtonPressed() {
return ((Keypad.isAnyColumnPressed() || Keypad.isAnyColumnPressed()) && !isOnePressed() && !isTwoPressed() && !isThreePressed() && !isFourPressed());
}
}
//======Front Door=======
{ <------<<<< Why
. . .
} <------<<<<
//======Garage Door=======
Get rid of them.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.
[code] Paste sketch here. [/code]
.
Thank you for the tips
Where does the loop() function end in your program ?