Hardware Reference
In-Depth Information
The draw() method prints the
readings in the window, and calls
another method, drawArrow() , to draw
the arrow and circle.
8
void draw() {
// deep blue background:
background(#0D1133);
// pale slightly blue text:
fill(#A3B5CF);
// put all the text together in one big string:
// display the date and time from the GPS sentence
// as MM/DD/YYYY, HH:MM:SS GMT
// all numbers are formatted using nf() to make them 2- or 4-digit:
String displayString = nf(currentMonth, 2)+ "/"+ nf(currentDay, 2)
+ "/"+ nf(currentYear, 4) + ", " + nf(hrs, 2)+ ":"
+ nf(mins, 2)+ ":"+ nf(secs, 2) + " GMT\n";
// display the position from the GPS sentence:
displayString = displayString + latitude + " " + northSouth + ", "
+ longitude + " " + eastWest + "\n";
// display the heading:
displayString = displayString + "heading " + heading + " degrees\n";
// show some info about the satellites used:
displayString = displayString + "satellites in view: "
+ satellitesInView + "\n";
displayString = displayString + "satellites used to calculate position: "
+ satellitesToFix;
text(displayString, textX, textY);
// draw an arrow using the heading:
drawArrow(heading);
}
8
drawArrow() is called by the
draw() method. It draws the arrow
and the circle.
void drawArrow(float angle) {
// move whatever you draw next so that (0,0) is centered on the screen:
translate(width/2, height/2);
// draw a circle in light blue:
fill(80,200,230);
ellipse(0,0,50,50);
// make the arrow black:
fill(0);
// rotate using the heading:
rotate(radians(angle));
// draw the arrow. center of the arrow is at (0,0):
triangle(-10, 0, 0, -20, 10, 0);
rect(-2,0, 4,20);
}
 
Search WWH ::




Custom Search