• This is great for whipping up a quick GUI on your phone to control something on the Puck. Here are two very simple examples that don't need any special code on the Puck to work.

    app.LoadPlugin( "PuckJS" );
    
    function OnStart()
    {
      lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
      btn1 = app.CreateToggle( "LED1" );
      btn2 = app.CreateToggle( "LED2" );
      btn3 = app.CreateToggle( "LED3" );
      btn1.SetOnTouch( btn1_OnTouch );
      btn2.SetOnTouch( btn2_OnTouch );
      btn3.SetOnTouch( btn3_OnTouch );
      lay.AddChild( btn1 );
      lay.AddChild( btn2 );
      lay.AddChild( btn3 );
      app.AddLayout( lay );
    
      puck = app.CreatePuckJS();
     // puck.Scan( "Puck" );
     puck.Connect('AA:BB:CC:DD:EE:FF');
    }
    
    function btn1_OnTouch( isChecked )
    {
      puck.SetLED( 1, isChecked );
    }
    function btn2_OnTouch( isChecked )
    {
      puck.SetLED( 2, isChecked );
    }
    function btn3_OnTouch( isChecked )
    {
      puck.SetLED( 3, isChecked );
    }
    
    app.LoadPlugin( "PuckJS" );
    var on= false;
    var intr;
    function OnStart()
    {
      lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
      btn1 = app.CreateToggle( "LED1" );
      btn1.SetOnTouch( btn1_OnTouch );
      lay.AddChild( btn1 );
      app.AddLayout( lay );
      puck = app.CreatePuckJS();
      puck.Connect('AA:BB:CC:DD:EE:FF');
    }
    
    function btn1_OnTouch( isChecked )
    {
      if (isChecked) {
       intr= setInterval('on=!on;puck.SetLED(1, on)', 500);
      }
     else {
        clearInterval(intr);
        puck.SetLED(1, false);
      }
    }
    

    Andrew

About

Avatar for Andrewmk @Andrewmk started