ControlP5 linking sliders and buttons

edited October 2013 in Library Questions

Hi all, I am working on trying to get a start and a stop button to begin an automated count on a slider using the ControlP5 library. I have the slider as a 'timeline' between the years of 1900 and 2013 with 1013 ticks. I would like it so that you can select a year on the slider with the mouse and then hit the 'run' button and the years on the slider will begin to count up one year every second or so and then stop again when the 'stop' button is pushed.

I've set up the GUI with the buttons and slider, everything is great. Except for the syntax for using the buttons to automate the incremental increase of the timeline slider.

Any help would be so appreciated.

THanks!

Answers

  • import controlP5.*;
    
    int sliderValue;
    
    ControlP5 timeline, buttonRun, buttonStop, switchButton;
    Button populate;
    
    void setup() {
      size(1280, 800);
      noStroke();
      smooth();
      //slider:
      timeline = new ControlP5(this);
      timeline.addSlider("Year")
        .setPosition(50, 700)
          .setSize(400, 20)
            .setRange(1885, 2013)
              .setValue(1942)
                .setNumberOfTickMarks(128)
                  .setSliderMode(Slider.FLEXIBLE)
                    .setDecimalPrecision(0);
      // end of slider setup
    
      //button setup:
      buttonRun = new ControlP5(this);
      buttonRun.addButton("Run Timeline")
        .setPosition(50, 675)
          .setSize(100, 20);
    
      buttonStop = new ControlP5(this);
      buttonStop.addButton("Stop Timeline")
        .setValue(100)
          .setPosition(170, 675)
            .setSize(100, 20);
    
      switchButton = new ControlP5(this);
      populate = switchButton.addButton("Populate Map")
        .setPosition(290, 675)
          .setSize(100, 20)
            .setSwitch(true)
              .setOff();
    }
    
    void draw() {
      background(#22313B);
      if (populate.booleanValue() == true) {
        fill(255);
        noStroke();
        ellipse(700, 700, 20, 20);
      }
    
      //slider functions -------------------------------------
      sliderValue = int(timeline.getController("Year").getValue());
    }
    
Sign In or Register to comment.