Using Rotary Potentiometer and Arduino to Visualize Data

edited December 2013 in Arduino

Hi there!

Im working on a project using an arduino pro mini, and a rotarty potentiometer. Fairly basic hardware. Im familiar with the arduino programming language but new to processing.

What I am trying to accomplish is some data visualization based on the position of the potentiometer.

There are a few parameters/goals that I have set for this.

1.) Range of motion - I'm visualizing this as a pie or doughnut chart. I would like for this to show me where the potentiometer is on a 360 degree diagram.

2.) Counter - I would like to have a number value, starting a 0, increase every time a function has been preformed. Specifically if the potentiometer knob moves from 0 degrees to 90 degrees and back that would mean an increase of 1.

3.) Elapsed time - Just looking to add a timer function to measure the counter function. How long did it take for the user to preform the function.

4.) (Stretch goal) Range field/gamification - The best way I can explain this is that old helicopter game This would use all of the previous functions (angle, counter, time). For example, can you turn the know the right amount at the right speed and back.

I'm hoping that I can build this with your help.

I'm going to build the code using button press initially then when I have the structure down I'll add the Hardware and switch to the hardware integration section.

From there I'm hoping you can send me in the right direction by sending links to how to build this. I've searched the forums but I don't really know what I'm looking for. I have the raw data coming into the serial port in Arduino but I believe the first step is to upload standard firmata onto my arduino.

Thanks for your help!

Answers

  • I'm starting with the button click and the timer.

    I have the counter displayed and i have a print in with the time.

    I'd like to have it setup so that if I hold the button for 5 seconds it will register as 1 and increase the number displayed. I would also like to have the time displayed in the frame and see it running rather than have it print in.

    here is the code.

        int state = 0;
         int start;
    
    
        void setup()
        {
          size(600, 400);
          textSize(64);
    
            // Probably near zero...
          int start = millis();
        }
    
        void draw()
        {
          background(0);
          fill(#115577);
          switch (state)
          {
            case 0:
              break;
            case 1:
              break;
            case 2:
              break;
            case 3:
              break;
            case 4:
              break;
            case 5:
              break;
            case 6:
              break;
            case 7:
              break;
            case 8:
              break;
            case 9:
              break;
            case 10:
              break;
    
          }
          //{  background(frameCount);
          //}
          fill(255, 100, 0);  //lynxio orange
          text(state, width / 2, height / 2);
        }
    
        void keyPressed()
        {
          state++;
          if (state > 10) state = 0;
    
          {
          int end = millis();
          int timeSpent = (end - start) / 1000; // Seconds spent
          int h = timeSpent / 3600;
          timeSpent -= h * 3600; 
          int m = timeSpent / 60;
          timeSpent -= m * 60;
          println("Spent: " +
            h + " hours, " +
            m + " minutes, " +
            timeSpent + " seconds");
        } 
        }
    
  • Answer ✓

    Have a global string variable holding the string you format for the println(), initialize it to "", display it in draw() with text().

    Also add start = millis(); at the end of keyPressed(), to reset it for the next key.

  • edited December 2013

    Ok I seem to have been able to get the time to show up but it is only flashing momentarily and its very large. It is also showing up on the left of the case number.

    Any thoughts on how to make it stay until the button is pressed again or how to create a cascading list? here is the code.

    // Click on the image to give it focus,
    // and then press any key.
     int start;
    int value = 0;
    int state = 0;
    
    void setup(){
      size(600, 400);
      textSize(64);
    }  
    
    void draw() {
      fill(value);
      rect(25, 25, 50, 50);
      background(0);
       switch (state)
      {
        case 0:
          break;
        case 1:
          break;
        case 2:
          break;
        case 3:
          break;
        case 4:
          break;
        case 5:
          break;
        case 6:
          break;
        case 7:
          break;
        case 8:
          break;
        case 9:
          break;
        case 10:
          break;
    
      }
        fill(255, 100, 0);  //lynxio orange
      text(state, width / 2, height / 2);
    }
    
    
    
    void keyReleased() {
        state++;
      if (state > 10) state = 0;
    
      if (value == 0) {
        value = 255;
      } else {
        value = 0;
      }
       {
      int end = millis();
      int timeSpent = (end - start) / 1000; // Seconds spent
      int h = timeSpent / 3600;
      timeSpent -= h * 3600;
      int m = timeSpent / 60;
      timeSpent -= m * 60;
    
    
      println("Spent: " +
        h + " hours, " +
        m + " minutes, " +
        timeSpent + " seconds");
    
    text("Spent: " +
        h + " hours, " +
        m + " minutes, " +
        timeSpent + " seconds");
    
    }  
      start = millis();
    }
    
Sign In or Register to comment.