Hello people (I assume that you are all people and that skynet is still in development stages)
Ok i've run into a issue converting some data and combined with this insufferable heat it's left me bereft of brain power. I am sure its a really simple fix but ive gone screen blind from staring at it too long.
char receivedChars[M,1,4]; // Char Array of received data
static byte ndx = 3; // index size of current array
int mode = 0; // Animation mode index
void setup() {
Serial.begin(9600);
HM10.begin(9600);
}
void loop() {
recvWithStartEndMarkers(); // Receive BT serial data
showNewData(); // Use BT serial Data
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
ndx = 0;
char startMarker = '<';
char endMarker = '>';
char IncomingChar;
while (HM10.available() > 0 && newData == false) {
IncomingChar = HM10.read();
if (recvInProgress == true) { // If receiving
if (IncomingChar != endMarker) { // if incoming is not line end marker
receivedChars[ndx] = IncomingChar; // index chars in array
ndx++; // increase index number
if (ndx >= numChars) { // if index exceeds byte limit
ndx = numChars - 1; // set index to re-write over last char in array
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
//ndx = 0; //reset index value
newData = true; // enable data release
}
}
else if (IncomingChar == startMarker) { /// if string start marker found
recvInProgress = true; // enable data copy proccess
// Serial.println(recvInProgress);
}
}
}
void showNewData() { /// Find values in received Data
if (newData == true) {
// char NewData = receivedChars ;
Serial.print("This just in ... ");
Serial.println(receivedChars);
if (receivedChars[0] == 77){ // if mode char found
// int what = atoi(&receivedChars[1]);
// what += atoi(&receivedChars[2]);
// Serial.print(what); // print mode result
mode = 0;
for (int i = 1; i < ndx; i++){ // from 1 to ndx length
mode += atoi(&(receivedChars[i]));
}
Serial.print("ndx:"); // print mode result
Serial.println(ndx); // print mode result
Serial.print("mode:"); // print mode result
Serial.println(mode); // print mode result
}
else if (receivedChars[0] == 'S'){ // if speed char found
}
else if (receivedChars[0] == 'V'){ // if brightness char found
}
else if (receivedChars[0] == 'R'){ // if red char found
}
else if (receivedChars[0] == 'G'){ // if green char found
}
else if (receivedChars[0] == 'B'){ // if blue char found
}
newData = false;
}
}
This script should be converting a "Char Array" of "ndx" size, Checking the character of 0 index. Then Ignoring the 0 index, Converting what is left from ASCII to a single Int from 0 to 100+.
I anyone has a better function instead of "atoi" for doing the conversion please could you leave some example code so i can see how it is meant to be used.
Kind regards,
Someguyfromtheinterwebs