I'm sending numbers to my Arduino MEGA 2650 using an Android app via Bluetooth. I own the Bluetooth module HC-05. My app sends different numbers. But the Arduino only receives 3 different decimal numbers that look like this:
0
248
128
These numbers should actually be the 52 in the ASCII table.
How can I convert the numbers? The numbers are read out via Serial. I want depending on what is received for a number, say my program one direction. I realized it via switch-case
UKHeliBob:
Did you really have to attach a zip with multiple files in it ?
Please post a simple but complete program here that illustrates the problem. It should only take 20 lines of code, or less.
How sure are you that the Android app is sending what you think it is ?
I have in the app, the arrow keys occupied and the serial monitor will not display the numbers that I have defined for example
high = 1 on the serial screen comes 120,128
14 ino files and 3 header files before you discovered you had a problem? No, I do not believe for one second that you wrote all that code.
As UKHeliBob says, write a small program that illustrates the problem. I'm not going to guess which of the ino files contains setup() and loop(), and which one causes the problem you have.
PaulS:
14 ino files and 3 header files before you discovered you had a problem? No, I do not believe for one second that you wrote all that code.
Did I say a second that the code belongs to me?
As UKHeliBob says, write a small program that illustrates the problem. I'm not going to guess which of the ino files contains setup() and loop(), and which one causes the problem you have.
I gave you above the code but it was you to "green" and "little"...
/* LedTable
*
* Written by: Klaas De Craemer, Ing. David Hrbaty, Modified by: Mark Quinn
*
*
* 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 16
#define FIELD_HEIGHT 16
const int NUM_LEDS=FIELD_WIDTH*FIELD_HEIGHT;
#define ORIENTATION_HORIZONTAL //Rotation of table, uncomment to rotate field 90 degrees
#include <SPI.h>
#include <SD.h>
#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 WS2812B
#define FAST_LED_DATA_PIN 6
#define MAX_BRIGHTNESS 255 // Thats full on, watch the power!
#define MIN_BRIGHTNESS 10 // set to a minimum of 8%
const int brightnessInPin = A0;
#define NUM_PIXELS FIELD_WIDTH*FIELD_HEIGHT
/* *** LED color table *** */
#define GREEN 0x008000
#define RED 0xFF0000
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define LBLUE 0x00FFFF
#define PURPLE 0xFF00FF
#define WHITE 0XFFFFFF
#define AQUA 0x00FFFF
#define HOTPINK 0xFF69B4
unsigned int long colorLib[9] = {RED, GREEN, BLUE, YELLOW, LBLUE, PURPLE, WHITE, AQUA, HOTPINK};
/* *** 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;
// Serial1.begin(38400);
byte incomingByte;
void readInput(){
curControl = BTN_NONE;
if (Serial1.available() > 0) {
// read the incoming byte:
incomingByte = Serial1.read();
Serial.println(incomingByte);
switch(incomingByte){
case 51:
curControl = BTN_LEFT;
break;
case 52:
curControl = BTN_RIGHT;
break;
case 49:
curControl = BTN_UP;
break;
case 50:
curControl = BTN_DOWN;
break;
case 53:
curControl = BTN_START;
break;
case 54:
curControl = BTN_EXIT;
break;
}
}
}
/* *********************************** */
void setup(){
Serial.begin(115200);
//Wait for serial port to connect
Serial1.begin(BLUETOOTH_SPEED);
}
void loop(){
}