Android 使用IOIO-OTG实时切换引脚类型
因此,熟悉IOIO-OTG的人都知道,可以将电路板上的引脚设置为输入或输出 因此,我有以下代码:Android 使用IOIO-OTG实时切换引脚类型,android,loops,ioio,Android,Loops,Ioio,因此,熟悉IOIO-OTG的人都知道,可以将电路板上的引脚设置为输入或输出 因此,我有以下代码: package ioio.examples.hello; import ioio.lib.api.DigitalInput; import ioio.lib.api.DigitalOutput; import ioio.lib.api.exception.ConnectionLostException; import ioio.lib.util.BaseIOIOLooper; import ioi
package ioio.examples.hello;
import ioio.lib.api.DigitalInput;
import ioio.lib.api.DigitalOutput;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.ToggleButton;
/**
* This is the main activity of the HelloIOIO example application.
*
* It displays a toggle button on the screen, which enables control of the
* on-board LED. This example shows a very simple usage of the IOIO, by using
* the {@link IOIOActivity} class. For a more advanced use case, see the
* HelloIOIOPower example.
*/
@SuppressLint("NewApi")
public class MainActivity extends IOIOActivity {
private NumberPicker chosePin1;
private ToggleButton button_;
private ToggleButton modeButton_;
private TextView testerReader;
/**
* Called when the activity is first created. Here we normally initialize
* our GUI.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testerReader = (TextView) findViewById(R.id.testRead);
button_ = (ToggleButton) findViewById(R.id.button);
modeButton_ = (ToggleButton) findViewById(R.id.toggleMode);
chosePin1 = (NumberPicker) findViewById(R.id.chosePin1);
chosePin1.setMaxValue(46);
chosePin1.setMinValue(1);
}
/**
* This is the thread on which all the IOIO activity happens. It will be run
* every time the application is resumed and aborted when it is paused. The
* method setup() will be called right after a connection with the IOIO has
* been established (which might happen several times!). Then, loop() will
* be called repetitively until the IOIO gets disconnected.
*/
class Looper extends BaseIOIOLooper {
/** The on-board LED. */
private DigitalOutput led_;
boolean initial;
boolean changed;
private DigitalOutput pinO9
private DigitalInput pinI9;
/**
* Called every time a connection with IOIO has been established.
* Typically used to open pins.
*
* @throws ConnectionLostException
* When IOIO connection is lost.
*
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
*/
@Override
protected void setup() throws ConnectionLostException {
led_ = ioio_.openDigitalOutput(0, true);
}
/**
* Called repetitively while the IOIO is connected.
*
* @throws ConnectionLostException
* When IOIO connection is lost.
*
* @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
*/
@Override
public void loop() throws ConnectionLostException {
led_.write(!button_.isChecked());
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
pinO9 = ioio_.openDigitalOutput(9, false);
pinO9.write(modeButton_.isActivated());
if (!modeButton_.isActivated()) {
pinI9.close();
pinO9 = ioio_.openDigitalOutput(9,false);
pinO9.write(true);
} else if (modeButton_.isActivated()) {
pinO9.close();
pinI9 = ioio_.openDigitalInput(9);
try {
if (pinI9.read()) {
testerReader.setText("ON");
} else {
testerReader.setText("OFF");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
* A method to create our IOIO thread.
*
* @see ioio.lib.util.AbstractIOIOActivity#createIOIOThread()
*/
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
}
我的问题在于,;我很好奇是否有一种方法可以将引脚从引脚9切换到引脚9;基本上,根据main_layout.xml文件上的开关状态,将其从输入切换到输出,反之亦然
你可以看到,在我的looper调用中,我有一个方法,可以比较开关的状态与打开和关闭引脚;这和我想的不一样
对于那些不熟悉IOIO板的人来说,它是一个类似于Arduino的控制器板。关于如何更好地解释这个问题,我可以得到一个评论而不是随机的否决票吗?