Cookbook / Compare an Input with a Threshold

code

Flash

  1. import gainer.*;
  2.  
  3. var ioModule:Gainer = new Gainer("localhost", 2000, Gainer.MODE1, true);
  4. var threshold:Number = 120;
  5.  
  6. ioModule.onReady = function() {
  7.     this.beginAnalogInput();
  8.  
  9.     //set "loop" as the event handler for onEnterFrame (scope is "ioModule")
  10.     //onEnterFrameのイベントハンドラにloopをセット(スコープはioModule)
  11.     _root.onEnterFrame = mx.utils.Delegate.create(this, loop);
  12.  
  13.     //synchronized communication with the I/O module
  14.     //I/Oモジュールと同期した通信
  15.     this.onFinished = function() {
  16.         if (this.analogInput[0] < threshold) {
  17.             this.turnOnLED();
  18.         } else {
  19.             this.turnOffLED();
  20.         }
  21.     }
  22. }
  23.  
  24. //the scode of the following function is "ioModule"
  25. //以下はioModuleのスコープで実行される
  26. function loop():Void {
  27.     trace(this.analogInput[0]);
  28. }

Max/MSP

Img:examplePatch.jpg Δ

Processing

  1. //this is dummy
  2. import gainer.*;
  3.  
  4. void setup {
  5.     ...
  6. }
  7.  
  8. void draw {
  9.     ...
  10. }

Flash Handling

prev 1 - 2 - 3 - 4
Print