parse bytes to populate multiple variables over BLE

Everytime I try somthing it fails miserably. I have been reading but I’m just not getting it.

I have been trying to control a Arduino app over BLE using the Adafruit nRF8001 breakout board.

I need to have a total of 4 sliders to control Speed, 4 Switches for direction, 1 switch for Mode control, 1 Switch for Delay control 30 or 60 seconds, 1 switch to control lighting.

This is for a model train setup with 4 trains, the 4th can be a trolley so the mode control sets train/trolley mode. and in trolley mode the delay switch is read.

Attached is my current working code (arduino) that works with the hardwired switches and sliders.

I need this to work from either hardwired controls or over BLE from a android device.

Can anyone look at the working code and please help me get this working? I just keep failing at every attempt I make. Really frustrated and close to giving up.

I have read the serial pages a bunch of times but just am not getting how to do this.

Thanks in advance for your help.
Thanks again

TC_4Trains_in_Array_Trolly_Light_07101039A.ino (5.1 KB)

I have been trying to control a Arduino app over BLE using the Adafruit nRF8001 breakout board.

Makes no sense.

What Arduino app? Arduinos don't have apps.

A program written for Arduino needs populated by variables over ble. I have written the program to work with hardwired contols but need to have it receive variables to control the trains over ble as well as the hardwired controls. whichever is used last.

I misspoke when calling the arduino code an app.

Wazhere: A program written for Arduino needs populated by variables over ble. I have written the program to work with hardwired contols but need to have it receive variables to control the trains over ble as well as the hardwired controls. whichever is used last.

Are you expecting someone to re-write your program for you?

If someone can give me some example code to get me on the right track, it would be appreciated. I keep going down the wrong path.

How much would someone charge to just write it for me, if I can't get it figured out.

I would rather get it figured out as I really want to learn this part. PLus don't have much money.....

Have a look at the parse example in Serial Input Basics

...R

If I want to do this over BLE using the Adafruit nRF8001 breakout board. What would the best way be to read the data in to parse. Would I change the example code as follows....

Assuming I load the right libraries...... Is it that simple? or more complex when using BLE instead of serial console?

// Example 2 - Receive with an end-marker

const byte numChars = 32; char receivedChars[numChars]; // an array to store the received data

boolean newData = false;

void setup() { BTLESerial.begin(9600);

}

void loop() { recvWithEndMarker(); showNewData(); }

void recvWithEndMarker() { static byte ndx = 0; char endMarker = '\n'; char rc;

while (BTLESerial.available() > 0 && newData == false) { rc = BTLESerial.read();

if (rc != endMarker) { receivedChars[ndx] = rc; ndx++; if (ndx >= numChars) { ndx = numChars - 1; } } else { receivedChars[ndx] = '\0'; // terminate the string ndx = 0; newData = true; } } }

void showNewData() { if (newData == true) { BTLESerial.println(receivedChars); newData = false; }

I think what you have in Reply #6 should work - but it is not a complete program - BTLESerial is not defined. I assume you are using SoftwareSerial.

And this does not make sense

void showNewData() {
    if (newData == true) {
        BTLESerial.println(receivedChars);
        newData = false;
    }

as you are sending the data back to the bluetooth device. Just use Serial.println() there so that the data can be viewed on the Serial Monitor.

...R