I think this forum hates me but I have to try... (P.S. I am a fellow nerd and I love you guys btw)
As an Arduino noob, I have somehow created an LED Coffee table which powers on, the Arduino sketch runs as expected displaying the menu options and everything with the configuration of the table seems to be in order. The one issue I am now having is that I cannot control the table using the bluetooth controller (my smartphone). At first, I thought it was a problem with the HC-05 unit not sending serial data to the Arduino but I used this code to test it I found after hours of research. Basically, the simple code turns the LED at pin 13 on when an "a" command is entered via the Bluetooth terminal android app, and turns the LED off with a "b" command.
/*
Arduino Turn LED On/Off using Serial Commands
Created April 22, 2015
Hammad Tariq, Incubator (Pakistan)
It's a simple sketch which waits for a character on serial
and in case of a desirable character, it turns an LED on/off.
Possible string values:
a (to turn the LED on)
b (tor turn the LED off)
*/
char junk;
String inputString="";
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set the baud rate to 9600, same should be of your Serial Monitor
pinMode(13, OUTPUT);
}
void loop()
{
if(Serial.available()){
while(Serial.available())
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ junk = Serial.read() ; } // clear the serial buffer
if(inputString == "a"){ //in case of 'a' turn the LED on
digitalWrite(13, HIGH);
}else if(inputString == "b"){ //incase of 'b' turn the LED off
digitalWrite(13, LOW);
}
inputString = "";
}
}
To my surprise, this code works and my smartphone is able to toggle the LED at pin 13 on and off with these commands. So the HC-05 is getting some form of serial data so it can't be that the HC-05 is burned out or not communicating with the Arduino - now I figured its time to start looking into the LED table code for a problem. Unfortunately, I'm learning about Arduino coding as I go and I'm not sure what the problem could be. Here is the main LED Table code being used, which contains the bluetooth controller info:
/* LedTable
*
* Written by: Klaas De Craemer, Ing. David Hrbaty
*
*
* Main file with common methods and defines, such as button reading from Bluetooth controller
* or setting pixels on the LED area
*/
#include <SoftwareSerial.h>
//LED field size
#define FIELD_WIDTH 14
#define FIELD_HEIGHT 14
#define ORIENTATION_HORIZONTAL //Rotation of table, uncomment to rotate field 90 degrees
#define USE_FAST_LED // FAST_LED as library to control the LED strips
#define BLUETOOTH_SPEED 38400
/*
* Some defines used by the FAST_LED library
*/
#define FAST_LED_CHIPSET WS2811
#define FAST_LED_DATA_PIN 6
#if defined(USE_OCTOWS2811) && defined(USE_FAST_LED)
#error "Only one of USE_OCTOWS2811 and USE_FAST_LED can be defined"
#endif
#define NUM_PIXELS FIELD_WIDTH*FIELD_HEIGHT
/* *** LED color table *** */
#define GREEN 0x00FF00
#define RED 0xFF00FF
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define LBLUE 0x00FFFF
#define PURPLE 0xFF00FF
#define WHITE 0XFFFFFF
unsigned int colorLib[3] = {YELLOW, BLUE, WHITE};
/* *** Game commonly used defines ** */
#define DIR_UP 1
#define DIR_DOWN 2
#define DIR_LEFT 3
#define DIR_RIGHT 4
/* *** Bluetooth controller button defines and input method *** */
#define BTN_NONE 0
#define BTN_UP 1
#define BTN_DOWN 2
#define BTN_LEFT 3
#define BTN_RIGHT 4
#define BTN_START 5
#define BTN_EXIT 6
uint8_t curControl = BTN_NONE;
SoftwareSerial bluetooth(11, 10);
void readInput(){
curControl = BTN_NONE;
if (bluetooth.available() > 0) {
// read the incoming byte:
uint8_t incomingByte = bluetooth.read();
Serial.println(incomingByte);
switch(incomingByte){
case 238:
curControl = BTN_LEFT;
break;
case 239:
curControl = BTN_RIGHT;
break;
case 236:
curControl = BTN_UP;
break;
case 237:
curControl = BTN_DOWN;
break;
case 224:
curControl = BTN_START;
break;
case 225:
curControl = BTN_EXIT;
break;
}
}
}
I have tried multiple bluetooth apps, including the Arduino Bluetooth Controller and I cannot seem to get the table to respond to any commands. Does anyone have any idea what I can be doing wrong here..? If there is any further information i can provide, please let me know. This is literally the last phase of this project and i am breaking my brain trying to figure out what is happening here.
Thanks!