-1
* /
#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 lockPin = 2;
int ledRed = A5;
int ledGreen = A4;

/* A name for the switch led on pin D5. */
const int lampuPin = 5;
const int ledlampu = A0;

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int stateBefore = 0;
int i = 0;
int j = 0;

void setup() {
  /* Start communication. */
  OneSheeld.begin();
  /* Set the LED & LOCK as output. */
  pinMode(lockPin, OUTPUT);
  pinMode(ledRed, OUTPUT);
  pinMode(ledGreen, OUTPUT);
  /* Set the LampuPin pin as output. */
  pinMode(lampuPin, INPUT);
  /* Set the LED pin as output. */
  pinMode(ledlampu, OUTPUT);
}

void loop() {
  //======Lampu Rumah=======
  // read the state of the pushbutton value:
  buttonState = digitalRead(lampuPin);
  if (buttonState != stateBefore) {
    if (buttonState == HIGH and i == 0) {
      digitalWrite (ledlampu, HIGH);
      j = 1;
    } else if (buttonState == LOW and j == 1) {
      i = 1;
    } else if (buttonState == HIGH and i == 1) {
      digitalWrite (ledlampu, LOW);
      j = 0;
    } else if (buttonState == LOW and j == 0) {
      i = 0;
    }
  }
  stateBefore = buttonState;
}

//======Pintu Hadapan Rumah=======
/* Check if "1" is pressed, iterate one time. */
if (iterations == 0 && isOnePressed()) {
  iterations++;
} else if (iterations == 1 && isTwoPressed()) {
  /* Check if "2" is pressed, iterate one time. */
  iterations++;
} else if (iterations == 2 && isThreePressed()) {
  /* Check if "3" is pressed, iterate one time. */
  iterations++;
} else if (iterations == 3 && isFourPressed()) {
  /* Check if "4" is pressed, iterate one time. */
  iterations++;
} else if (isOtherButtonPressed()) {
  /* Check if any other button is pressed, reset iterations. */
  iterations = 0;
}
if (iterations == 4) {
  /* Check if the number of iterations is 4, blink the LED. */
  digitalWrite(lockPin, LOW);
  digitalWrite(ledGreen, HIGH);
  digitalWrite(ledRed, LOW);
  OneSheeld.delay(6000);
  digitalWrite(lockPin, HIGH);
  digitalWrite(ledRed, HIGH);
  digitalWrite(ledGreen, 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 isOtherButtonPressed() {
  return ((Keypad.isAnyColumnPressed() || Keypad.isAnyColumnPressed()) && !isOnePressed() && !isTwoPressed() && !isThreePressed() && !isFourPressed());
}
5

You got an extra closing brace after this line.

stateBefore = buttonState;
}

It ends the loop function so the next if is outside any function and illegal. Hit Control-T in the IDE to auto-format the code and it will line up the indention and that will help you spot these sorts of errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.