Felipe Araujo
/
Bluetooth_HC-06
Fork of Bluetooth_HC-06 by
main.cpp
- Committer:
- phelps
- Date:
- 2018-06-24
- Revision:
- 1:8b636701917b
- Parent:
- 0:feba469f2cf1
File content as of revision 1:8b636701917b:
// Bluetooth HC-06 may work for HC-05 (I didn't try - check https://mbed.org/users/edodm85/notebook/HC-05-bluetooth/) // Use pins (RXD - PTC4, TXD - PTC3) on FRDM-KL25Z // Use both USBs to power the HC-06 (J9_12 - GND, J9_10 - 5V usb(VCC)) #define NUM_PASS 11 #include "mbed.h" // Protótipos de funções bool verificaSenha(char password[], char password_digitado[]); void cadastrarSenha(char password_repeat1[], char password_repeat2[], char password[]); void cadastrarRfid(); Serial blue(p9, p10); int main() { bool a; char password[NUM_PASS] = "thomazlixo"; char key,key2,password_digitado[NUM_PASS], password_repeat1[NUM_PASS], password_repeat2[NUM_PASS]; blue.baud(9600); while (1) { do { blue.printf("E - Entrar C - Cadastrar Senha R - Cadastrar RFID P - Sair \n"); key = blue.getc(); switch (key) { case 'E': a = verificaSenha(password, password_digitado); if(a){ // Verificar se a trava está fechada } //TODO trava e sensor prox break; case 'C': cadastrarSenha(password_repeat1,password_repeat2,password); break; case 'R': cadastrarRfid(); } } while (key != 'P' || key2 != 'P'); } } bool verificaSenha(char password[], char password_digitado[]) { bool a; blue.printf("Digite a senha:\n"); blue.scanf("%s", password_digitado); if (strcmp(password, password_digitado) == 0) { blue.printf("Senha Correta! :D\n"); a = true; } else { blue.printf("Senha incorreta! Tente Novamente... \n"); a = false; } return a; } void cadastrarSenha(char password_repeat1[], char password_repeat2[], char password[]) { blue.printf("Informe a nova senha: \n"); blue.scanf("%s", password_repeat1); blue.printf("Repita a senha: \n"); blue.scanf("%s", password_repeat2); if (strcmp(password_repeat2, password_repeat1) == 0) { strcpy(password, password_repeat1); blue.printf("Senha cadastrada com sucesso!!"); } }