Chiedo scusa...
#include <SoftwareSerial.h>
#include "Wire.h"
#include <glcd.h>
#include <fonts/allFonts.h>
void sendCommand(char);
char XReading[9]; // 0000.000\0 pos
char YReading[9];
char ZReading[9];
char AReading[9];
void zeroX() { for(int x = 0; x < 9; x++) XReading[x] = 0;}
void zeroY() { for(int x = 0; x < 9; x++) YReading[x] = 0;}
void zeroZ() { for(int x = 0; x < 9; x++) ZReading[x] = 0;}
void zeroA() { for(int x = 0; x < 9; x++) AReading[x] = 0;}
void setup() {
Serial.begin(9600);
GLCD.Init();
GLCD.SelectFont(Arial14);
GLCD.CursorTo(0, 0);
GLCD.print(" X ");
GLCD.CursorTo(0, 1);
GLCD.print(" Y ");
GLCD.CursorTo(0, 2);
GLCD.print(" Z ");
GLCD.CursorTo(0, 3);
GLCD.print(" A ");
zeroX();
zeroY();
zeroZ();
zeroA();
}
void loop()
{
int x;
char ch, ky;
if(Serial.available() >= 9)
{
ch = Serial.read();
switch(ch)
{
case 'X':
while(Serial.available() < 8)
delay(10);
for(x = 0; x < 8; x++)
XReading[x] = Serial.read();
GLCD.CursorTo(2, 0);
GLCD.print(XReading);
zeroX();
break;
case 'Y':
while(Serial.available() < 8)
delay(10);
for(x = 0; x < 8; x++)
YReading[x] = Serial.read();
GLCD.CursorTo(2, 1);
GLCD.print(YReading);
zeroY();
break;
case 'Z':
while(Serial.available() < 8)
delay(10);
for(x = 0; x < 8; x++)
ZReading[x] = Serial.read();
GLCD.CursorTo(2, 2);
GLCD.print(ZReading);
zeroZ();
break;
case 'A':
while(Serial.available() < 8)
delay(10);
for(x = 0; x < 8; x++)
XReading[x] = Serial.read();
GLCD.CursorTo(2, 3);
GLCD.print(AReading);
zeroA();
break;
default:
break;
}
}
}