CRTC Electronics

Click here to edit subtitle

Analog Input

Mainactivity.java

 

Three steps

  1. declare an input variable
  2. link the variable to a pin
  3. read the variable

Declare A Variable 

Looper

declare a variable as a analog input

*you may need to import ioio.api.Analoglnput 


private DigitalOutput led_;

private AnalogInput waterLevelSensor_;

Link Variable to a Pin

setup()

waterLevelSensor_ is set as an analog input to pin 33
the argument is the pin number (48 = pin 48)

waterLevelSensor_ = ioio.openAnalogInput(33);

Read the veriable

loop()

read the pin and write it to the screen


Use a Try/Catch statement

try

{

}


catch

{

}

try 

{

   waterLevelSensor_.getVoltage();

   textOnScreen_.setText("" + waterLevelSensor_ + " " + units);


catch (InterruptedException e1) 

{

   e1.printStackTrace();

}