Hello, I'm working on a project that consists on creating a remote for a jukebox-like/musical station appliance. The station is communicating with a HM-10 module and a Arduino Leonardo, and the remote I'm planning to make will be communicating with a Arduino Nano and another HM-10 module. I have some questions about programming :
-
The two HM-10 modules are connected together, I put the remote on Master mode and the station on Slave mode, since I will be transmitting data from the remote to the station. Is that correct ?
-
Here's my code so far for the remote, I would appreciate that you would give me any advice on it :
// DĂ©claration fonction Bluetooth
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // (RX, TX)
// Déclaration des boutons utilisés pour la télécommande
const int btn1 = A0;
const int btn2 = A1;
const int btn3 = A2;
const int btn4 = A3;
const int btn5 = A4;
const int btn6 = A5;
void setup() {
// Affectation des boutons en entrée
pinMode(btn1, INPUT);
pinMode(btn2, INPUT);
pinMode(btn3, INPUT);
pinMode(btn4, INPUT);
pinMode(btn5, INPUT);
pinMode(btn6, INPUT);
// Lancement moniteur série pour visualisation sur logiciel
Serial.begin(9600);
// Vitesse du HM-10 par défaut
BTSerial.begin(9600);
}
void loop() {
// Fonction de lecture des différents boutons
bst1 = digitalRead(btn1);
bst2 = digitalRead(btn2);
bst3 = digitalRead(btn3);
bst4 = digitalRead(btn4);
bst5 = digitalRead(btn5);
bst6 = digitalRead(btn6);
if (buttonLastState != bst1){
if (bst1 == 1){
Bluetooth.write('1');
buttonLastState = bst1;
}
}
}
This code isn't finished, but I plan on writing the same "if" fonction for each button. I read about the pkt. function, but I don't understand how it works and if I can use it with my buttons. I also need to affect a decimal or a hexadecimal value to each button, how can I make it work ?