CRTC Electronics

Click here to edit subtitle

Buttons and Pins


Make three buttons each turning on a different pin.

Video Tutorial

Control IOIO Pins with an App


1. Create and Link Buttons

  1. Create Buttons in Main.XML
  2. Create Variables to link to buttons
  3. Link variables to buttons

2. Create and Link Pins

  1. Create Variables to link to buttons
  2. Link variables to buttons

3. Actions Code

1. A. Creating Buttons in Main.xml

  • open main.xml  res>layout.main.xml
  • drag and drop button
  • change ID to something appropriate

-If you get red "x"s make sure you didn't duplicate the IDs and clean your project
-make sure you save this file now!

1. B.  Create Variables to link to buttons

declare your variables
public class MainActivity extends IOIOActivity
    private ToggleButton button1_;
    private ToggleButton button2_;
    private ToggleButton button3_;

1. C.  Link variables to buttons

link variables to the buttons

public void onCreate(Bundle savedInstanceState)
        button1_ = (ToggleButton) findViewById(;
        button2_ = (ToggleButton) findViewById(;
        button3_ = (ToggleButton) findViewById(;

2. A.  Create Variables to link to buttons

declare your variables

class Looper extends BaseIOIOLooper 

        /** The on-board LED. */
        private DigitalOutput pinR_;
        private DigitalOutput pinG_;
        private DigitalOutput pinB_;

2. B.  Link variables to buttons 

link your variables to pins

protected void setup() throws ConnectionLostException {
            showVersions(ioio_, "IOIO connected!");
            pinR_ = ioio_.openDigitalOutput(1, true);
            pinG_ = ioio_.openDigitalOutput(3, false);
            pinB_  = ioio_.openDigitalOutput(6, false);


3. Actions Code

set the pins equal to the state of the toggle buttons

public void loop() throws ConnectionLostException, InterruptedException