yeah i'm working with a similar program.... sending values to another arduino and setting pwm accordingly
#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(1200);
chuck.begin();
chuck.update();
chuck.calibrateJoy();
}
void loop() {
delay(500);
chuck.update();
// Serial.print(",jx ");
Serial.print((int)chuck.readJoyX()*-1+100);
// Serial.print(",jy ");
Serial.println((int)chuck.readJoyY()*-1+100);
}
this program simply reads joystick x y on wii nunchuck controller, makes it positive, and adds 100 to each (so that it's always 6 characters long)
example output: 233230
I searched the forum for atoi and found this example program
#include <stdlib.h> // needed for [shighlight]atoi[/shighlight]
char buffer[4];
int received;
int ledPin = 9;
void setup()
{
Serial.begin(9600);
received = 0;
buffer[received] = '\0';
}
void loop()
{
if (Serial.available())
{
buffer[received++] = Serial.read();
buffer[received] = '\0';
if (received >= (sizeof(buffer)-1))
{
Serial.print(buffer);
int myInt = [shighlight]atoi[/shighlight](buffer);
analogWrite(ledPin, myInt);
received = 0;
}
}
} }
}
when i did syntax check i had error:
In function 'void loop()':
error: expected primary-expression before '[' token At global scope:
[/color]
i don't have the library #include <stdlib.h>? where would i find this?