# Limiting rotation

**URL:** <https://discourse.processing.org/t/limiting-rotation/23825>\
**Category:** Coding Questions\
**Created:** [September 12, 2020, 3:48pm UTC](https://discourse.processing.org/t/limiting-rotation/23825 "2020-09-12T15:48:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BACI821](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@BACI821](https://discourse.processing.org/u/BACI821)\
**Post date:** [September 12, 2020, 3:48pm UTC](https://discourse.processing.org/t/limiting-rotation/23825/1 "2020-09-12T15:48:11Z")

</div>

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.

```auto
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
   
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 12, 2020, 4:36pm UTC](https://discourse.processing.org/t/limiting-rotation/23825/2 "2020-09-12T16:36:47Z")

</div>

Hello,

Just to get you started…

```auto
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:

> **[map() / Reference](https://processing.org/reference/map_.html)**
>
> Re-maps a number from one range to another. In the first example above, the number 25 is converted from a value in the range of 0 to 100 into a value that ranges from the left edge of the w…

> **[constrain() / Reference](https://processing.org/reference/constrain_.html)**
>
> Constrains a value to not exceed a maximum and minimum value.

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:
> 
> - The Processing _website_ has references, examples, tutorials, links to resources, etc.  
> [https://processing.org/](https://processing.org/)
> 
> - The Processing PDE (IDE) has lots to offer!  
> An exploration of the menu bar will reveal what is available; libraries, tools, local examples, and other goodies are in there.
> 
> - The Coding Train \< Experience the unbridled enthusiasm of Daniel Shiffman  
> [https://shiffman.net/](https://shiffman.net/)  
> [https://www.youtube.com/user/shiffman](https://www.youtube.com/user/shiffman)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> 
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)
> 
> - The source code can give insight if you are adventurous:  
> [GitHub - processing/processing: Source code for the Processing Core and Development Environment (PDE)](https://github.com/processing/processing)
> 
> - Explore Processing on GitHub:  
> [Processing Foundation · GitHub](https://github.com/processing)  
> [processing/core/src/processing/core/PApplet.java at master · processing/processing · GitHub](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java) \< Many of the Processing functions are here!
> 
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the menu.  
> In the education menu, there is a reference to the Coding Train.
> 
> - And the Internet. `:)`

`:)`

---

<div class="post-metadata">

**Author:** ![BACI821](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@BACI821](https://discourse.processing.org/u/BACI821)\
**Post date:** [September 12, 2020, 5:58pm UTC](https://discourse.processing.org/t/limiting-rotation/23825/3 "2020-09-12T17:58:36Z")

</div>

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