Back

CreateAnalogInput

The CreateAnalogInput function creates an object which manages analog input for a particular pin on the IOIO board.

 input = ioio.CreateAnalogInput( pinNum );

Put the number of the pin you wish to use in the pinNum parameter.

The IOIO board has 16 pins (pins 31-46) capable of Analog Input, which are able to measure voltage levels between 0V-3.3V, with a precision of about 3mV. (Be careful not to supply voltage levels outside this range, or else you might damage your IOIO board).

The following example makes use of the JavaScript setInterval function to repeatedly read the voltage on pin 40 every 3 seconds.

Example - Read voltage

function OnStart()
{
  ioio = app.CreateIOIO();
  ioio.SetOnConnect( ioio_OnConnect );
  ioio.CheckConnection();
}

function ioio_OnConnect()
{
  app.ShowPopup( "Connected!" );
  input = ioio.CreateAnalogInput( 40 );
  setInterval( "ReadVoltage()",3000 );
}

function ReadVoltage() {
  app.ShowPopup( input.GetVoltage(),"Short" );
}
  Copy   Copy All    Run