Hi, I have tried to improve the Esplora TFT Horizon making it a little more sensitive to high inclination and adding also a line to represent vertical inclination. The angles are also printed to the serial port.

Quote

/* Created 25 August 2013 by Corrado Possieri*/

// first of all we need to include the libraries#include <Esplora.h>#include <TFT.h> // Arduino LCD library#include <SPI.h>

// some variables that the Esplora need to work correctly// we have to define the center of the screenconstfloat X0 = EsploraTFT.width()/2.0;constfloat Y0 = EsploraTFT.height()/2.0;

// we need also to save in a global variable the last anglefloat lastTanAngle;float lastZIncl;

// this function will be executed once at the beginningvoidsetup() {// we need to initialize the displayEsploraTFT.begin();

// and to select the color of the backgroundEsploraTFT.background(0,0,0); // black for an higher contrast

// begin the serial comunicationSerial.begin(9600);}

// this will run over and over voidloop() { // we need to read the Accelerometer values...int xAxis = Esplora.readAccelerometer(X_AXIS);int yAxis = Esplora.readAccelerometer(Y_AXIS);int zAxis = Esplora.readAccelerometer(Z_AXIS);

// no we can graph the values in the tft screen// this value represent the offset of the line // which represent the groundfloat zOffset = map(zAxis, zAccMin, zAccMax, Y0, -Y0);// this represent the inclination respect the horizonfloat tanAngle = xIncl/yIncl;

// first of all we have to delete the previous lines// drawing black lines over them// horizontal inclinationEsploraTFT.stroke(0,0,0); // we draw black over the previous linesEsploraTFT.line(0, -X0*lastTanAngle+Y0, 2*X0, X0*lastTanAngle+Y0);// vertical inclinationEsploraTFT.line(0, -X0*lastTanAngle+lastZIncl+Y0, 2*X0, X0*lastTanAngle+lastZIncl+Y0);

// now we can write the new lines // one for horizontal inclinationEsploraTFT.stroke(0,255,0); // this line would be greenEsploraTFT.line(0, -X0*tanAngle+Y0, 2*X0, X0*tanAngle+Y0);// this line would be red// and one for verticalEsploraTFT.stroke(255,0,0);EsploraTFT.line(0, -X0*tanAngle+zOffset+Y0, 2*X0, X0*tanAngle+zOffset+Y0);

// we will save the values for the next loop iteration lastTanAngle = tanAngle; lastZIncl = zOffset;

// this will run over and over voidloop() { // we need to read the Accelerometer values...int xAxis = Esplora.readAccelerometer(X_AXIS);int yAxis = Esplora.readAccelerometer(Y_AXIS);int zAxis = Esplora.readAccelerometer(Z_AXIS);

// print these values to the serial portsendFloat(horizontalAngle); sendFloat(verticalInclination);

// no we can graph the values in the tft screen// this value represent the offset of the line // which represent the groundfloat zOffset = map(zAxis, zAccMin, zAccMax, Y0, -Y0);// this represent the inclination respect the horizonfloat tanAngle = xIncl/yIncl;

// first of all we have to delete the previous lines// drawing black lines over them// horizontal inclinationEsploraTFT.stroke(0,0,0); // we draw black over the previous linesEsploraTFT.line(0, -X0*lastTanAngle+Y0, 2*X0, X0*lastTanAngle+Y0);// vertical inclinationEsploraTFT.line(0, -X0*lastTanAngle+lastZIncl+Y0, 2*X0, X0*lastTanAngle+lastZIncl+Y0);

// now we can write the new lines // one for horizontal inclinationEsploraTFT.stroke(0,255,0); // this line would be greenEsploraTFT.line(0, -X0*tanAngle+Y0, 2*X0, X0*tanAngle+Y0);// this line would be red// and one for verticalEsploraTFT.stroke(255,0,0);EsploraTFT.line(0, -X0*tanAngle+zOffset+Y0, 2*X0, X0*tanAngle+zOffset+Y0);

// we will save the values for the next loop iteration lastTanAngle = tanAngle; lastZIncl = zOffset;

void establishContact() {// save the start timeunsignedlong startTime = millis();// until we have a response from the pcwhile (Serial.available() <= 0) {Serial.print('A'); // send a capital A// if we are waiting from more than 10 seconds if(millis() - startTime > 10000) {// we will not comunicate with computerbreak; } delay(300); }}

// when datas are available on the serial portvoid serialEvent(Serial myPort) {// read the byte arrivedint inByte = myPort.read();// if this is the first byte clear the serial port, we have had // the first contact, and give this information to Arduinoif (firstContact == false) {if (inByte == 'A') { myPort.clear(); // clear the serial port firstContact = true; // connection done myPort.write('A'); // wait } } // if we have already had a connection...else {// ...add the last byte received to an array serialInArray[serialCount] = inByte; serialCount++;println(serialInArray);println();

Excuse me but i had to divide the message into tho halves because it was too long.In the previous message i also attached two screenshot of the Processing code.Always hoping this will helpHappy sketching