I want to use 4 tact switches to mimic the WASD keys on my keyboard and then send that over bluetooth to my robot. Here is my code which is a huge work in progress. The bluetooth will connect but the buttons wont do anything.
const int button = 4;
const int button1 = 5;
const int button2 = 2;
const int button3 = 3;
int buttonState;
int buttonState1;
int buttonState2;
int buttonState3;
int lastButtonState = LOW;
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
int lastButtonState3 = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED 1
String retSymb = "+RTINQ=";//start symble when there's any return
String slaveName = ";Bluetooth_Bee_V2";// caution that ';'must be included, and make sure the slave name is right.
int nameIndex = 0;
int addrIndex = 0;
String recvBuf;
String slaveAddr;
String connectCmd = "\r\n+CONN=";
SoftwareSerial blueToothSerial(RxD,TxD);
void setup(){
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
//wait 1s and flush the serial buffer
delay(1000);
Serial.flush();
blueToothSerial.flush();
pinMode(button, INPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
}
void loop(){
int reading = digitalRead(button);
int reading1 = digitalRead(button1);
int reading2 = digitalRead(button2);
int reading3 = digitalRead(button3);
char recvChar;
while(1){
if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
}
if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
recvChar = Serial.read();
blueToothSerial.print(recvChar);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if (reading1 != lastButtonState1) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if (reading2 != lastButtonState2) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if (reading3 != lastButtonState3) {
// reset the debouncing timer
lastDebounceTime = millis();
}