could i get a pointer in the right direction?
i'm trying to send variables in one long serial message:
#include <math.h>
#include "Wire.h"
#include "WiiChuck.h"
//#include "nunchuck_funcs.h"
#define MAXANGLE 90
#define MINANGLE -90
WiiChuck chuck = WiiChuck();
int angleStart, currentAngle;
int tillerStart = 0;
double angle;
void setup() {
//nunchuck_init();
Serial.begin(57600);
chuck.begin();
chuck.update();
chuck.calibrateJoy();
}
void loop() {
delay(1000);
chuck.update();
//Serial.print((int)9);
// Serial.print(",jx ");
Serial.print((int)chuck.readJoyX()*-1+100);
// Serial.print(",jy ");
Serial.println((int)chuck.readJoyY()*-1+100);
}
this sends for example 222232 (222 = joyX, 232=joyY)
how would i isolate the variables and be able to work with them in the program below?
#include <stdlib.h> // needed for [shighlight]atoi[/shighlight]
char buffer[9];
int received;
void setup()
{
Serial.begin(57600);
received = 0;
buffer[received] = '\0';
Serial.print("setup");
}
void loop()
{
if (Serial.available())
{
buffer[received++] = Serial.read();
buffer[received] = '\0';
if (received >= (sizeof(buffer)-1))
{
int myInt = atoi(buffer);
Serial.println(buffer);
Serial.print("1: ");
Serial.println(myInt/10);
Serial.print("2: ");
Serial.println(myInt/100);
Serial.print("3: ");
Serial.println(myInt%10);
Serial.print("4: ");
Serial.println(myInt%100);
received = 0;
}
}
}