Thanks, i am able to move the motor now, the next problem is i'm going to 
put 4 button to control the movement of the robot. My coding in eclipse 
didnt show any error, but it didn't move when i press on the button, can 
someone try to debug my coding? 

package com.example.button;

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 static Button UP;
private static Button DOWN;
private static Button LEFT;
private static Button RIGHT;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
 }
class Looper extends BaseIOIOLooper{
private DigitalOutput ain1_;
private DigitalOutput ain2_;
private DigitalOutput bin1_;
private DigitalOutput bin2_;
 @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);
 UPOnButton();
DOWNOnButton();
LEFTOnButton();
RIGHTOnButton();
}
 public void loop() throws ConnectionLostException, InterruptedException {}
public void UPOnButton()
{
UP = (Button) findViewById(R.id.UP);
final TextView display = (TextView)findViewById(R.id.Display);

    UP.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v) {

              try {
              display.setText("UP");
                    ain1_.write(false);
                    ain2_.write(true);
                    bin1_.write(true);
                    bin2_.write(false);
                   
              } 
              catch (ConnectionLostException e) 
              {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
        
              
              }

        });

}
public void DOWNOnButton()
{
DOWN = (Button) findViewById(R.id.DOWN);
final TextView display = (TextView)findViewById(R.id.Display);

    DOWN.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v) {

              try {
              display.setText("DOWN");
                    ain1_.write(true);
                    ain2_.write(false);
                    bin1_.write(false);
                    bin2_.write(true);
                   
              } 
              catch (ConnectionLostException e) 
              {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }

        });


}

public void LEFTOnButton()
{
LEFT = (Button) findViewById(R.id.LEFT);
final TextView display = (TextView)findViewById(R.id.Display);

    LEFT.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v) {

              try {
              display.setText("LEFT");
                    ain1_.write(true);
                    ain2_.write(false);
                    bin1_.write(false);
                    bin2_.write(true);
                   
              } 
              catch (ConnectionLostException e) 
              {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }

        });

}

public void RIGHTOnButton()
{
RIGHT = (Button) findViewById(R.id.RIGHT);
final TextView display = (TextView)findViewById(R.id.Display);

    RIGHT.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v) 
            {

              try {
              display.setText("RIGHT");
                    ain1_.write(true);
                    ain2_.write(false);
                    bin1_.write(false);
                    bin2_.write(true);
                   
              } 
              catch (ConnectionLostException e) 
              {
              e.printStackTrace();
              }
              }
              
              

        });
}


}
 protected IOIOLooper createIOIOLooper()
{
return new Looper();
}
}

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.

Reply via email to