CRTC Electronics

Click here to edit subtitle

Digital 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 digital input

*you may need to import ioio.api.Digitallnput (if DigitalInput shows an error Eclipse will suggest solutions, try choosing import.


private DigitalOutput led_;

private DigitalInput motionSensor_;

Link Variable to a Pin

setup()

motionSensor_  is set as an instance of openDigitalInput(
first argument is the pin number (48 = pin 48)
second argument is the pull up mode. 
FLOATING
PULL_UP
PULL_DOWN

*you may need to import ioio.lib.api.DigitalInput.Spec.Mode;

motionSensor_ = ioio_.openDigitalInput(7, Mode. PULL_DOWN );

Read the veriable

loop()

read the pin and write it to the led


Use a Try/Catch statement

try

{

}


catch

{

}

try 

{

   led_.write( motionSensor_ .read());

                                                                     //*


catch (InterruptedException e1) 

{

   e1.printStackTrace();

}

* if you want to change something on the screen when you receive an input you will need additional code to keep from crashing.

See: https://www.youtube.com/watch?v=FsMsCqQ7rS4