I'm finishing a project for a customer. Basically it's a interactive menu where he can send AT commands for a bluetooth module in a easier way.
The code is working at the first function ("padrao"). It sends the AT command properly. (also, ignore the missing part of the code)
The problem is: The only function able to be called by IF statement is "padrao". Any other function wont work. What can i change to solve the problem? Thanks in advance!
Tried to use SWITCH and CASE instead, but couldn't call any function like this...
(i left only one of the remaining functions for comparison. tell me if any of you guys need the rest of the code)
/* Menu interativo para comandos dos módulos Bluetooth HC-05, HC-06, HC-08, HM-10, etc.
* Nathan - 29/04/2019
*
#include <SoftwareSerial.h>
#define rx 3
#define tx 4
SoftwareSerial Seria1(rx, tx); // Declara os pinos utilizados para a comunicação serial
int entrada = 0 ;
int echo;
void setup () {
Serial.begin(9600); // Inicia a comunicação serial a 9600 bauds
Seria1.begin(9600); // Inicia a interface serial de software a 9600 bauds
Serial.println("Interface de testes Bluetooth ver. 0.1");
Serial.println("Escolha uma opção pelo terminal serial");
Serial.println("1. Redefinir o módulo para as configurações de fábrica");
Serial.println("2. Reset");
Serial.println("3. Verificar o endereço do módulo");
Serial.println("4. Verificar o nome do módulo [como será reconhecido]");
Serial.println("5. Mudar o nome do módulo");
//Teste da variável "entrada". Debug apenas.
//Serial.println(entrada);
pinMode (LED_BUILTIN, OUTPUT);
}
void loop () {
if (Serial.available()){
entrada = Serial.parseInt();
delay(100);
if (entrada == 1)
{
echo == entrada;
padrao();
}
if (entrada == 2) {
Seria1.write("AT+RST");
entrada = 0;
}
if (entrada == 3) {
Seria1.write("AT+ADDR?");
entrada = 0;
if (entrada == 9) {
nome();
}
if (entrada == 4) {
char comando[] = "AT+NAME=";
Serial.println ("Digite o nome do dispositivo desejado");
while(!Serial.available() ){
}
int nome = Serial.read();
Seria1.write (comando + nome);
entrada = 0;
}
}
if (entrada == 5) {
Seria1.write ("AT+ROLE=0");
entrada = 0;
}
if (entrada == 6) {
Seria1.write ("AT+ROLE=1");
entrada = 0;
}
if (entrada == 7) {
Seria1.write ("AT+PSWD?");
entrada = 0;
}
if (entrada == 8) {
Seria1.write ("AT+STATE?");
entrada = 0;
}
}
}
void padrao() {
digitalWrite(LED_BUILTIN,LOW);
Serial.println("Deseja resetar o dispositivo para as configurações padrão?");
Serial.println("Digite '1' para prosseguir");
int resposta = Serial.parseInt();
while (resposta != 1) {
if (resposta == 1) {
break;
}
}
{
delay(1000);
Seria1.write("AT+ORGL");
Serial.print("Comando enviado!");
entrada = 0;
}
}
void nome() {
delay(100);
Serial.write("O nome do dispositivo é:");
Seria1.write("AT+NAME?");
//debug
Serial.print("teste");
entrada = 0;
}
Aucun commentaire:
Enregistrer un commentaire