UKHeliBob:
Post the whole program not just a snippet
ok, here`s the entire function:
void Gyro() {
//#define GravityArraySize 2
// int GravityArray[GravityArraySize];
// int GravityArrayIndex = 0;
// unsigned long GravityTimer = 0; // time since last altitude display change. if it is less than BufferTimer we dont refresh the display
int iGforce;
int Gforce = 1.0;
int momentGforce=0;
int maxGforce = 0;
float maxPrintForce = 0;
int MAG = 0; // to int
int gRoll, gPitch, yStart, yEnd, xStart, xEnd, xZero = 96, yZero = 26;
int yBug, xBug, xBall ;
int xm60, ym60;
int xm30, ym30;
int xp60, yp60;
int xp30, yp30;
String s_tmp;
float ball;
sensors_event_t event;
bno.getEvent(&event);
MAG = event.orientation.x;
gRoll = event.orientation.y;
gPitch = event.orientation.z;
gPitch = gPitch - 20; // Horizon down
// gRoll = gRoll - 20;
if (abs(gPitch)>90) {
if (gRoll > 0 ) {
gRoll = 180-gRoll;
} else {
gRoll = -180-gRoll;
}
}
if (gPitch>90) {
gPitch = 180 - gPitch;
}
if (gPitch<-90) {
gPitch = -180 - gPitch;
}
textAreaMAG.ClearArea();
textAreaMAG.Printf("%03d", MAG); // print 3 digit HDG
/*
s_tmp = “”;
if (abs(gRoll)<10) {
s_tmp += " ";
}
s_tmp += abs(gRoll);
if (gRoll<0) {
s_tmp += “R”;
}
if (gRoll>0) {
s_tmp += “L”;
}
/*textAreaBottomL.ClearArea();
textAreaBottomL.print(s_tmp); // s-tmp == R or L print “R” or “L”
/
/
s_tmp = “”;
if (abs(gPitch)<10) {
s_tmp += " ";
}
s_tmp += abs(gPitch);
if (gPitch<0) {
s_tmp += “U”;
}
if (gPitch>0) {
s_tmp += “D”;
}
/*
textAreaBottomR.ClearArea();
textAreaBottomR.print(s_tmp); s-temp == U or D print “U” or “D”
*/
//top marker
//GLCD.DrawLine(xZero, 5, xZero, 5); // tip of triangle = point
GLCD.DrawLine(xZero-1, 6, xZero+1, 6); // 2nd row of tiangle static triangle= 2 wide
GLCD.DrawLine(xZero-2, 7, xZero+2, 7); // 3rd row = base of triangle = 4 wide
GLCD.DrawLine(xZero, 5, xZero, 4); // vertiklal pointer line on top 1 wide, 2 high, starts at 5 goes up to 3
//left and right markers
//Left
GLCD.DrawLine(66,yZero-2, 66, yZero+2);
GLCD.DrawLine(67,yZero-1, 67, yZero+1);
GLCD.DrawLine(68,yZero, 68, yZero);
//Right
GLCD.DrawLine(126,yZero-2, 126, yZero+2);
GLCD.DrawLine(125,yZero-1, 125, yZero+1);
GLCD.DrawLine(124,yZero, 124, yZero);
// Plane picture
//tail
GLCD.DrawLine(xZero-18, yZero, xZero+18, yZero);
// wings
GLCD.DrawLine(xZero, 12, xZero, 20);
// body
GLCD.DrawCircle(xZero, yZero, 5);
GLCD.DrawLine(xZero, yZero, xZero, yZero, PIXEL_OFF);
//Arc Bug
xBug = xZero + (yZero)sin(3.14gRoll/180);
if (abs(gRoll)<90) {
yBug = yZero-(yZero)cos(3.14gRoll/180);
} else {
yBug = yZero-(yZero-12)cos(3.14gRoll/180);
}
GLCD.DrawRect(xBugOld-1, yBugOld+1,3,3, PIXEL_OFF);
GLCD.DrawRect(xBug-1, yBug+1,3,3);
xBugOld = xBug;
yBugOld = yBug;
// marker -60
xm60 = xZero + (yZero)sin(3.14(gRoll-60)/180);
if (abs(gRoll-60)<90) {
ym60 = yZero-(yZero)cos(3.14(gRoll-60)/180);
} else {
ym60 = yZero-(yZero-11)cos(3.14(gRoll-60)/180);
}
GLCD.DrawRect(xm60_old, ym60_old+1, 2, 2, PIXEL_OFF);
GLCD.DrawRect(xm60, ym60+1, 2, 2);
xm60_old = xm60;
ym60_old = ym60;
// end of marker -60
// marker -30
xm30 = xZero + (yZero-1)sin(3.14(gRoll-30)/180);
if (abs(gRoll-30)<90) {
ym30 = yZero-(yZero-1)cos(3.14(gRoll-30)/180);
} else {
ym30 = yZero-(yZero-1-11)cos(3.14(gRoll-30)/180);
}
GLCD.DrawRect(xm30_old, ym30_old+1, 2, 2, PIXEL_OFF);
GLCD.DrawRect(xm30, ym30+1, 2, 2);
xm30_old = xm30;
ym30_old = ym30;
// end of marker -30
// marker +60
xp60 = xZero + (yZero)sin(3.14(gRoll+60)/180);
if (abs(gRoll+60)<90) {
yp60 = yZero-(yZero)cos(3.14(gRoll+60)/180);
} else {
yp60 = yZero-(yZero-11)cos(3.14(gRoll+60)/180);
}
GLCD.DrawRect(xp60_old, yp60_old+1, 2, 2, PIXEL_OFF);
GLCD.DrawRect(xp60, yp60+1, 2, 2);
xp60_old = xp60;
yp60_old = yp60;
// end of marker +60
// marker +30
xp30 = xZero + (yZero-1)sin(3.14(gRoll+30)/180);
if (abs(gRoll+30)<90) {
yp30 = yZero-(yZero-1)cos(3.14(gRoll+30)/180);
} else {
yp30 = yZero-(yZero-1-11)cos(3.14(gRoll+30)/180);
}
GLCD.DrawRect(xp30_old, yp30_old+1, 2, 2, PIXEL_OFF);
GLCD.DrawRect(xp30, yp30+1, 2, 2);
xp30_old = xp30;
yp30_old = yp30;
// end of marker +30
// draw the horizon line
xStart = 66;
xEnd = 126;
if (abs(gRoll) < 90) {
yStart = yZero - 30tan(3.14gRoll/180) - yZerosin(3.14gPitch/180);
yEnd = yZero + 30tan(3.14gRoll/180) - yZerosin(3.14gPitch/180);
} else {
yStart = yZero - 30tan(3.14gRoll/180) + yZerosin(3.14gPitch/180);
yEnd = yZero + 30tan(3.14gRoll/180) + yZerosin(3.14gPitch/180);
}
if (yStart < 1 ) {
xStart = xStart + (1-yStart)/tan(3.14*gRoll/180);
yStart = 1;
}
if (yStart > 42 ) {
xStart = xStart + (42-yStart)/tan(3.14*gRoll/180);
yStart = 42;
}
if (yEnd < 1) {
xEnd = xEnd + (1-yEnd)/tan(3.14*gRoll/180);
yEnd = 1;
}
if (yEnd > 42) {
xEnd = xEnd + (42-yEnd)/tan(3.14*gRoll/180);
yEnd = 42;
}
GLCD.DrawLine(xStartOld, yStartOld, xEndOld, yEndOld,PIXEL_OFF);
GLCD.DrawLine(xStart, yStart, xEnd, yEnd);
// end of horizon line
/*
// FillTriangle dont work properly in the current version of the GLCD
if (yStart < yEnd) {
//GLCD.FillTriangle(xStart, yStart, xEnd, yEnd, xStart, yEnd);
GLCD.DrawTriangle(xStart, yStart, xEnd, yEnd, xStart, yEnd); //below
GLCD.DrawTriangle(xStart, yStart-1, xEnd, yEnd-1, xEnd, yStart, PIXEL_OFF); //above
} else {
//GLCD.FillTriangle(xStart, yStart, xEnd, yEnd, xEnd, yStart);
GLCD.DrawTriangle(xStart, yStart, xEnd, yEnd, xEnd, yStart);
GLCD.DrawTriangle(xStart, yStart-1, xEnd, yEnd-1, xStart, yEnd, PIXEL_OFF);
}
*/
xStartOld = xStart;
yStartOld = yStart;
xEndOld = xEnd;
yEndOld = yEnd;
//************************ Slip ball **************************
/*
VECTOR_MAGNETOMETER (values in uT, micro Teslas)
VECTOR_GYROSCOPE (values in rps, radians per second)
VECTOR_EULER (values in Euler angles or ‘degrees’, from 0…359)
VECTOR_ACCELEROMETER (values in m/s^2)
VECTOR_LINEARACCEL (values in m/s^2)
VECTOR_GRAVITY (values in m/s^2)
/
imu::Vector<3> acc = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
/
Serial.print(“X: “);
Serial.print(acc.x());
Serial.print(” Y: “);
Serial.print(acc.y());
Serial.print(” Z: “);
Serial.print(acc.z());
Serial.println(””);
delay(500);
*/
ball = acc.x();
ball = ball * 4.0; // convert to number of pixels and set sensitivity
// set max deflection
if (ball > 26) {
ball = 26;
}
if (ball < -26) {
ball = -26;
}
xBall = xZero - ball;
GLCD.FillCircle(xBallOld, 58, 3, PIXEL_OFF);
GLCD.FillCircle(xBall, 58, 3);
xBallOld = xBall;
//GLCD.DrawVLine(96, 53, 10);
GLCD.DrawVLine(91, 53, 10);
GLCD.DrawVLine(101, 53, 10);
// ************************** END OF Slipball stuff *******************************
// ****************** G-Force meter ******************************
/*
Gforce = acc.z();
iGforce = round(Gforce*10/9.8);
textAreaGmeter.ClearArea();
textAreaGmeter.print(“G”);
textAreaGmeter.CursorTo(2);
textAreaGmeter.println(iGforce/10.0, 1);
*/
momentGforce = acc.z();
//maxGforce = 10;
//momentGforce = 9;
textAreaGmeter.ClearArea();
textAreaGmeter.print(“G”);
textAreaGmeter.CursorTo(2);
if ( momentGforce > maxGforce )
{
maxGforce = momentGforce;
textAreaGmeter.println(maxGforce, 1);
}
/* {
maxGforce = momentGforce; // only if momentG > than maxG, maxG gets new value
maxPrintForce = round(maxGforce*10/9.8);
textAreaGmeter.ClearArea();
textAreaGmeter.print(“G”);
textAreaGmeter.CursorTo(2);
textAreaGmeter.println(maxPrintForce/10.0, 1);
} */
}