Limiting rotation

Hello Alll,
Newbie programmer here (just learning the ropes). I’m trying to create a dash for a boat which runs off arduino. I’m trying to make the UI right now.I need to limit the rotation of my indicator. The indicator is a circle that rotates around the center. Below is the code I have so far. eventually the gauge will be controlled by a crankshaft sensor via the arduino.

PImage needle;                                     // to store meter needle image
PImage meter;                                     // to store meter image 
PImage multi;                                     //multigauge
float counter;                                   //for roatation of needle

void setup()                                     
{
    counter=0.0;                                 //Controls rotation
    size(1366,768);                               //output window size 1366 x 768 pixel
    needle=loadImage("semicircleindicator.png"); //loading ndl.png image to needle
    meter=loadImage("gauge2.png");               //loading meter.jpg image to meter
    multi=loadImage("MULTIGUAGE.png");           //multiguage
    multi.resize(500,400);                       //resize the multiguage
}
void draw()                                       
{
      background(0);                               //making background color as black
        pushMatrix();                                  //sets an independent opject from the rest of the group
          counter++;
          translate(width/2, height/2);
          rotate(counter*TWO_PI/360);
          translate(-needle.width/2, -needle.height/2);
          image(needle,0,0);
        popMatrix();
   image(meter, (width/4)+25, (height/2)-499); //drawing meter image 
   image(multi, (width/2)+180, (height/2)-290);//draws mutiguage
   
}

Hello,

Just to get you started…

PImage needle;                                 // to store meter needle image
PImage meter;                                  // to store meter image 
PImage multi;                                  //multigauge
float counter;                                 //for roatation of needle

void setup()                                     
  {
  counter=0.0;                                   //Controls rotation
  size(1366, 768);                               //output window size 1366 x 768 pixel
  //needle=loadImage("semicircleindicator.png"); //loading ndl.png image to needle
  //meter=loadImage("gauge2.png");               //loading meter.jpg image to meter
  //multi=loadImage("MULTIGUAGE.png");           //multiguage
  //multi.resize(500,400);                       //resize the multiguage
  }
void draw()                                       
  {
  background(0);                                   //making background color as black
  pushMatrix();                                    //sets an independent opject from the rest of the group
  
  counter = map(mouseX, 0, width, -360/2, 360/2);  // mouse control
  
  translate(width/2, height/2);
  rotate(counter*TWO_PI/360);         
  //translate(-needle.width/2, -needle.height/2);
  //translate(100/2, 100/2);
  stroke(255);
  line(0, 0, 100, 0);
  //image(needle,0,0);
  popMatrix();
  //image(meter, (width/4)+25, (height/2)-499); //drawing meter image 
  //image(multi, (width/2)+180, (height/2)-290);//draws mutiguage
  }

Useful functions:

One of the best tools in a programmer’s tool chest is knowing the resources available to you and learning to navigate, filter, and use them.

A short list of resources to peruse:

Resources < Click here to expand !

Explore the resources available here:

:)

Awesome thank you so much for the resources.I’m teaching myself so sometimes I get stuck.

1 Like