hello I have been working on a 15x 15 led game table and Bluetooth gamepad. My question is. Should I be going this route for the wireless controller? analog or digital?
Right now I am using on the controller, 8 push switches, an HC-05 in master, and a Arduino pro mini. 9v battery power
The game table is WS2812B led strips, Arduino Mega, and HC-06 as slave
Everything works for the most part, the problems are. It is hitting when not supposed to and returning to main menu I am getting double hits on one button. I changed buttons, pins on Arduino with the same results.
Any help will be appreciated.
Here is a link to the main code for the controller GitHub - batemanm/gamepad: Simple 10 button gamepad
Here is a link to the main code for the Game table https://github.com/davidhrbaty/IKEA-LED-Table/
also attached a zip file for the main led table, and a very poorly drawn picture of my game pad
also here is my edit for the gamepad to work on my table
[code]
#include <SoftwareSerial.h>
#define RXPIN 10
#define TXPIN 11
#define bluetooth_speed 19200
SoftwareSerial bluetooth (RXPIN, TXPIN);
#define RIGHT_RIGHT_PIN 9 //X
#define RIGHT_LEFT_PIN 8 //triangle
#define START_PIN 5
#define SELECT_PIN 4
#define LEFT_RIGHT_PIN 7
#define LEFT_UP_PIN 3
#define LEFT_LEFT_PIN 6
#define LEFT_DOWN_PIN A3
#define RIGHT_RIGHT 7
#define RIGHT_LEFT 8
#define LEFT_RIGHT 4
#define LEFT_UP 1
#define LEFT_LEFT 3
#define LEFT_DOWN 2
#define START 5
#define SELECT 6
#define DEBOUNCE 50
long lastButtonTime[16];
int buttonState = 0;
int lastButtonState = 0;
int lastSent = 0;
void setup() {
// bluetooth
pinMode (RXPIN, INPUT);
pinMode (TXPIN, OUTPUT);
bluetooth.begin(19200);
//button
//right 2
pinMode(RIGHT_RIGHT_PIN, INPUT_PULLUP);
pinMode(RIGHT_LEFT_PIN, INPUT_PULLUP);
// middle 2
pinMode(START_PIN, INPUT_PULLUP);
pinMode(SELECT_PIN, INPUT_PULLUP);
//left 4
pinMode(LEFT_RIGHT_PIN, INPUT_PULLUP);
pinMode(LEFT_UP_PIN, INPUT_PULLUP);
pinMode(LEFT_LEFT_PIN, INPUT_PULLUP);
pinMode(LEFT_DOWN_PIN, INPUT_PULLUP);
}
void setButtonOn (int BUTTON, long time) {
if (((lastButtonState & (1<<(BUTTON-1))) != (1<<(BUTTON - 1)))) {
lastButtonTime[BUTTON] = time;
}
if ((time - lastButtonTime[BUTTON]) > DEBOUNCE) {
if (((buttonState & (1<<(BUTTON-1))) != (1 << (BUTTON - 1)))){
buttonState = buttonState | (1 << (BUTTON - 1));
}
}
lastButtonState = lastButtonState | (1 << (BUTTON - 1));
}
void setButtonOff (int BUTTON, long time) {
if (((lastButtonState & (1<<(BUTTON-1))) != !(1<<(BUTTON - 1)))) {
lastButtonTime[BUTTON] = time;
}
if ((time - lastButtonTime[BUTTON]) > DEBOUNCE) {
if (((lastButtonState & (1<<(BUTTON-1))) != (1 << (BUTTON - 1)))){
buttonState = buttonState & ~(1 << (BUTTON - 1));
}
}
lastButtonState = lastButtonState & ~(1 << (BUTTON - 1));
}
void getButtonStateToSend (int buttonState) {
int toSend = 0;
int toSend2 = 0;
byte send1 = 0;
byte send2 = 0;
boolean changed = 0;
for (int i = 0; i < sizeof (buttonState) *8; i ++) {
if ((lastSent & (1 << i)) != (buttonState & (1 << i))) {
changed = 1;
}
}
if (changed == 1) {
toSend = buttonState;
send1 = byte (toSend);
toSend2 = toSend >> 8;
send2 = byte (toSend2);
bluetooth.write (send1);
bluetooth.write (send2);
lastSent = toSend;
}
}
void loop(){
long time = millis ();
if (digitalRead (RIGHT_RIGHT_PIN) == LOW) {
setButtonOn (RIGHT_RIGHT, time);
} else {
setButtonOff (RIGHT_RIGHT, time);
}
if (digitalRead (RIGHT_LEFT_PIN) == LOW) {
setButtonOn (RIGHT_LEFT, time);
} else {
setButtonOff (RIGHT_LEFT, time);
}
if (digitalRead(SELECT_PIN) == LOW) {
setButtonOn (SELECT, time);
} else {
setButtonOff (SELECT, time);
}
if (digitalRead (START_PIN) == LOW) {
setButtonOn (START, time);
} else {
setButtonOff (START, time);
}
if (digitalRead (LEFT_RIGHT_PIN) == LOW) {
setButtonOn (LEFT_RIGHT, time);
} else {
setButtonOff (LEFT_RIGHT, time);
}
if (digitalRead (LEFT_UP_PIN) == LOW) {
setButtonOn (LEFT_UP, time);
} else {
setButtonOff (LEFT_UP, time);
}
if (digitalRead(LEFT_LEFT_PIN) == LOW) {
setButtonOn (LEFT_LEFT, time);
} else {
setButtonOff (LEFT_LEFT, time);
}
if (digitalRead (LEFT_DOWN_PIN) == LOW) {
setButtonOn (LEFT_DOWN, time);
} else {
setButtonOff (LEFT_DOWN, time);
}
getButtonStateToSend (buttonState);
}
[/code]
gamepad-master.zip (6.05 KB)
working_led_table.zip (19.9 KB)