I’m trying to make a linear compass using a MPU(I2C) and Arduino. I was able to get a regular compass to function properly reading data from the Arduino. Now I’m trying this. I’m using the MouseX() to give me the 0-360 degrees. I’m a bit lost as to how to have it display “N” at 0 degrees and properly display the proper degrees moving the mouse. Any help would be greatly appreciated
// LINEAR COMPASS
PGraphics hdg;
float degree1;
int degree = 180;
//
// ---------------------------------------------------------------
//
void setup()
{
// init
size(800, 600);
hdg = createGraphics(360,40);
} // func
void draw()
{
degree1=map(mouseX, 0, width, 0, 360);
degree=int(degree1);
hdg.beginDraw();
hdg.background(255);
// black rect (the whole compass)
hdg.noFill();
hdg.stroke(0); //Black
hdg.rect(0, 0, 359, 39);
// yellow rect (the display)
hdg.fill(255,255,2);
hdg.rect(0, 20, 359, 19);
// yellow triangle
hdg.stroke(0);// black
hdg.fill(255, 255, 2); // yellow
hdg.triangle(180-5, 13, 180+5, 13, 180, 19);
// DISPLAY DEGREES
hdg.stroke(0);// black
hdg.fill(0); // black
hdg.textAlign(CENTER);
hdg.text(int(degree1),180, 11);
// DRAW BLACK DEGREE MARKS
hdg.stroke(0); // black
int lengthLine = 0;
for (int i=0; i < 360; i+=5)
{
if (i%20==0) {
lengthLine=8;
} else
{
lengthLine=4;
}
hdg.line(degree+i, 21, degree+i, 21+lengthLine);
hdg.fill(0);
hdg.text("N", degree, 38);
}
// red line in display
hdg.stroke(255, 2, 2); // red
hdg.line(180, 21, 180, 39);
hdg.endDraw();
image(hdg, 220, 280);
// print(" ",degree);
// println(" ",mouseX);
}
