BaroneRosso.it - Forum Modellismo - Visualizza messaggio singolo - Head track con Arduino e Nunchuk
Visualizza messaggio singolo
Vecchio 30 ottobre 12, 18:11   #6 (permalink)  Top
faustog_2
User
 
L'avatar di faustog_2
 
Data registr.: 19-07-2008
Residenza: catania
Messaggi: 978
il terzo:

ecco il terzo NunchuckDEmo.ino



include <Wire.h>
#include "nunchuk.h"

const unsigned int BAUD_RATE = 9600;
const unsigned int MIN = 304;
const unsigned int MAX = 712;

const unsigned int MIN_OUT = 0;
const unsigned int MAX_OUT = 255;

Nunchuk nunchuk;

int buffer_x = 0;
int buffer_y = 0;
int buffer_z = 0;


int out_x_value = 0;


void setup()
{
Serial.begin(BAUD_RATE);
nunchuk.initialize();

}

void loop()
{
analogWrite(3,out_x_value);


if(nunchuk.update())
{
buffer_x = map(nunchuk.x_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT);
buffer_y = map(nunchuk.y_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT);
buffer_z = map(nunchuk.z_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT);
}

if(nunchuk.update())
{
if( buffer_x != map(nunchuk.x_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT) || buffer_y != map(nunchuk.y_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT) || buffer_z != map(nunchuk.z_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT))
{

out_x_value = map(nunchuk.x_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT);
Serial.print(out_x_value);


Serial.print(",");

Serial.print(map(nunchuk.y_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT));
Serial.print(",");

Serial.print(map(nunchuk.z_acceleration(), MIN,MAX,MIN_OUT,MAX_OUT));
Serial.print("\n\r");

}
}
}
faustog_2 non è collegato   Rispondi citando