who can help me solve my problem i want do a bluetooth door lock with arduino
but i want to ask user choose the way to go if user prompt 1 go for ask for password
if user prompt 2 go for change password
but when i keyin 1 and go for the ask password it wont getting any value
how who can help me pls
#include <SPI.h>
#include "Adafruit_BLE_UART.h"
#define LOCK_PIN 6
#define RED_LED_PIN 7
#define GREEN_LED_PIN 8
#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2
#define ADAFRUITBLE_RST 9
long secret = 12345;
long code;
long pass;
long openTime = 0;
boolean test = true;
boolean testt = false;
// Status from the Bluefruit LE driver
int lastStatus = ACI_EVT_DISCONNECTED;
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
void setup() {
Serial.begin(9600);
Serial.println(F("BLE Safe - Adafruit Bluefruit Low Energy Edition"));
BTLEserial.begin();
pinMode(LOCK_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
digitalWrite(LOCK_PIN, LOW);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
BTLEserial.println("Welcome");
}
void loop() {
// Tell the nRF8001 to do whatever it should be working on
BTLEserial.pollACI();
int status = BTLEserial.getState();
if (status != lastStatus) {
if (status == ACI_EVT_DEVICE_STARTED) {
Serial.println(F("* Advertising Started"));
}
else if (status == ACI_EVT_CONNECTED) {
Serial.println(F("* Connected!"));
}
else if (status == ACI_EVT_DISCONNECTED) {
Serial.println(F("* Disconnected or advertising timed out."));
}
// save for next loop
lastStatus = status;
}
if (status == ACI_EVT_CONNECTED) {
// see if there's any data from bluetooth
if (BTLEserial.available()) {
Serial.print("* ");
Serial.print(BTLEserial.available());
Serial.println(F(" bytes available from BTLE"));
}
// keeping u + code for compatibility with the serial api
int var = BTLEserial.parseInt();
switch (var) {
case 1:
openLock();
break;
case 2:
changePass();
break;
}
}
// close lock and reset lights after x seconds
if (openTime && millis() - openTime > 4000) {
resetLock();
}
}
void openLock()
{
BTLEserial.println("What is your password");
int code = BTLEserial.parseInt();
Serial.println(String(code));
if (code == secret)
{
openTime = millis(); // set even if bad code so we can reset the lights
// open the lock
Serial.println("Code matches, opening lock");
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(LOCK_PIN, HIGH); // open the lock
BTLEserial.println("unlocked");
}
else
{
openTime = millis(); // set even if bad code so we can reset the lights
// bad code, don't open
Serial.println("Invalid code " + code);
digitalWrite(RED_LED_PIN, HIGH);
BTLEserial.println("invalid code");
}
}
void changePass() {
BTLEserial.println("Passcode");
}
// closes the lock and resets the lights
void resetLock() {
// reset the lights
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(GREEN_LED_PIN, LOW);
digitalWrite(LOCK_PIN, LOW); // close the lock
BTLEserial.println("locked");
openTime = 0;
}