i tried to set the handlers in Oncreate and the apps keep on not
responding. Can someone check my coding?
package com.example.onebutton;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
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;
public class MainActivity extends IOIOActivity {
private static final int AIN1_PIN = 1;
private static final int AIN2_PIN = 2;
private static final int BIN1_PIN = 3;
private static final int BIN2_PIN = 4;
private DigitalOutput ain1_;
private DigitalOutput ain2_;
private DigitalOutput bin1_;
private DigitalOutput bin2_;
private Button UP;
private TextView Display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
UP = (Button) findViewById(R.id.UP);
Display = (TextView) findViewById(R.id.Display);
UP.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
try {
push();
Display.setText("UP");
} catch (ConnectionLostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
class Looper extends BaseIOIOLooper {
@Override
protected void setup()throws ConnectionLostException,
InterruptedException{
ain1_ = ioio_.openDigitalOutput(AIN1_PIN);
ain2_ = ioio_.openDigitalOutput(AIN2_PIN);
bin1_ = ioio_.openDigitalOutput(BIN1_PIN);
bin2_ = ioio_.openDigitalOutput(BIN2_PIN);
}
}
public void push() throws ConnectionLostException
{
ain1_.write(false);
ain2_.write(true);
bin1_.write(false);
bin2_.write(true);
}
@Override
protected IOIOLooper createIOIOLooper(){
return new Looper();
}
}
On Saturday, April 12, 2014 1:53:35 PM UTC+8, Chia Waicheong wrote:
>
> ok thanks, ill try
>
> On Saturday, April 12, 2014 1:02:47 PM UTC+8, Ytai wrote:
>>
>> Your functions that get called when the buttons are pressed.
>> On Apr 11, 2014 8:48 PM, "Chia Waicheong" <[email protected]> wrote:
>>
>>> Sorry, what is handler?
>>>
>>> On Friday, April 11, 2014 1:48:07 AM UTC+8, Chia Waicheong wrote:
>>>>
>>>> im trying to connect 2DC motor driver using arduino motor shield,
>>>> tested all the ioio output using led and it seems providing the desired
>>>> output. However, the 2 motor didnt move when i try to connect the ioio to
>>>> the motor driver. Im using a 9V battery for the motor. Is the motor driver
>>>> not compatible with ioio or it is other problem? my coding:
>>>>
>>>> package ioio.examples.hello;
>>>>
>>>> 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.os.Bundle;
>>>> import android.widget.ToggleButton;
>>>> import ioio.lib.api.Sequencer;
>>>> import ioio.lib.api.Sequencer.ChannelConfig;
>>>> import ioio.lib.api.Sequencer.ChannelConfigPwmSpeed;
>>>> import ioio.lib.api.Sequencer.ChannelCuePwmSpeed;
>>>>
>>>>
>>>>
>>>> /**
>>>> * 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.
>>>> */
>>>> public class MainActivity extends IOIOActivity {
>>>>
>>>> /**
>>>> * 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);
>>>> }
>>>>
>>>> /**
>>>> * 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 {
>>>> private Sequencer.ChannelCuePwmSpeed dcMotorACue_ = new
>>>> ChannelCuePwmSpeed();
>>>> private Sequencer.ChannelCuePwmSpeed dcMotorBCue_ = new
>>>> ChannelCuePwmSpeed();
>>>> private Sequencer.ChannelCue[] cue_ = new Sequencer.ChannelCue[]
>>>> {dcMotorACue_, dcMotorBCue_ };
>>>> private Sequencer sequencer_;
>>>>
>>>> /**
>>>> * Called every time a connection with IOIO has
>>>>
>>>> been established.
>>>> * Typically used to open pins.
>>>> *
>>>> * @throws ConnectionLostException
>>>> * When IOIO connection is lost.
>>>> * @throws InterruptedException
>>>> *
>>>> * @see
>>>>
>>>> ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
>>>> */
>>>> @Override
>>>> protected void setup() throws ConnectionLostException,
>>>> InterruptedException {
>>>> DigitalOutput enable1 = ioio_.openDigitalOutput(3);
>>>> DigitalOutput enable2 = ioio_.openDigitalOutput(4);
>>>> enable1.write(true);
>>>> enable2.write(true);
>>>> final ChannelConfigPwmSpeed dcMotorAConfig = new Sequencer.
>>>> ChannelConfigPwmSpeed(Sequencer.Clock.CLK_2M, 2000, 0, new
>>>> DigitalOutput.Spec(1));
>>>> final ChannelConfigPwmSpeed dcMotorBConfig = new Sequencer.
>>>> ChannelConfigPwmSpeed(Sequencer.Clock.CLK_2M, 2000, 0, new
>>>> DigitalOutput.Spec(2));
>>>> final ChannelConfig[] config = new ChannelConfig[] {dcMotorAConfig,
>>>> dcMotorBConfig };
>>>>
>>>> sequencer_ = ioio_.openSequencer(config);
>>>>
>>>> // Pre-fill.
>>>> sequencer_.waitEventType
>>>>
>>>> (Sequencer.Event.Type.STOPPED);
>>>>
>>>> sequencer_.start();
>>>> }
>>>>
>>>> /**
>>>> * Called repetitively while the IOIO is
>>>>
>>>> connected.
>>>> *
>>>> * @throws ConnectionLostException
>>>> * When IOIO connection is lost.
>>>> * @throws InterruptedException
>>>> *
>>>> * @see
>>>>
>>>> ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
>>>>
>>>> */
>>>> @Override
>>>> public void loop() throws ConnectionLostException, InterruptedException
>>>> {
>>>> push();
>>>> }
>>>>
>>>> private void push() throws
>>>>
>>>> ConnectionLostException, InterruptedException {
>>>> dcMotorACue_.pulseWidth = 1000;
>>>> dcMotorBCue_.pulseWidth = 1000;
>>>> sequencer_.push(cue_, 62500);
>>>> }
>>>>
>>>> /**
>>>> * A method to create our IOIO thread.
>>>> *
>>>> * @see
>>>>
>>>> ioio.lib.util.AbstractIOIOActivity#createIOIOThread()
>>>> */
>>>> }
>>>> protected IOIOLooper createIOIOLooper() {
>>>> return new Looper();
>>>> }}
>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "ioio-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/ioio-users.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.