0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Processing / ControlP5 > sliderの試用 > ControlEvent / " controller() has been deprecated (and is still available in the ControlP5 class) ...

Last updated at Posted at 2016-07-13
動作環境
Processing 3.1.1
ControlP5ライブラリ
Windows 8.1 pro (64bit)

参考 http://qiita.com/akspect/items/6a574e12181c00125d40
参考 http://www.kasperkamperman.com/blog/processing-code/controlp5-library-example1/

code

import processing.serial.*;
import controlP5.*;

Serial myPort;

ControlP5 slider;
int sliderValue;
int numSerial = 5;
int curSerial = -1;

void setup() {
  size(500,500);
  slider = new ControlP5(this);
  slider.addSlider("COM")
    .setRange(-1, numSerial - 1)
    .setValue(-1)
    .setPosition(50,40)
    .setSize(200, 20)
    .setNumberOfTickMarks(numSerial + 1);
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isController()) {
//     if (theEvent.controller().name() == "COM") {
     if (theEvent.getName() == "COM") {
       if (curSerial != slider.getValue("COM")) {
         curSerial = (int)slider.getValue("COM");
         print("Serial=");
         println(curSerial);
       }
     }
  }
}

void draw() {
  background(0);  
}
//     if (theEvent.controller().name() == "COM") {

の行は古いとのこと(下記)。getName()を見つけて対応した。

" controller() has been deprecated (and is still available in the ControlP5 class) in favor of getter/setters methods, controller(String) is now available as getController(String)"

参考 http://www.sojamo.de/libraries/controlP5/reference/controlP5/ControlEvent.html#getController--

動作

スライダーを動かすとCOMの値を変更する。
変更した時にコンソールに「Serial=-1」のような表示がされる。

これにより、複数のCOM接続の切替えをもくろんでいる。

qiita.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?