I am novice in Java, IOIO and Robotic.
This is my First Robot : A car RC with IOIO-OTG Board and L293d to drive Motors
Platform :
- IOIO-OTG
- Bridge H : L293D
- 2 motors DC 6V
- Charger Module LiPo Pro POW12059P
- Accu Li-Ion 3,7 V 2000 mAh
Schema
And the code : https://github.com/ailgorbot/AilgorRC
4 buttons (left, right, up, down) to create in MainActivity (see file AndroidManifest.xml in GitHub)
package fr.ailgor.ailgorrc; import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton; import ioio.lib.api.DigitalOutput;
import ioio.lib.api.PwmOutput;
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 {// super.setup();</span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">ToggleButton</span><span class="pln"> toggleButtonLedSTAT</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">protected</span><span class="pln"> </span><span class="typ" style="color: #660066;">Button</span><span class="pln"> buttonLeft</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">protected</span><span class="pln"> </span><span class="typ" style="color: #660066;">Button</span><span class="pln"> buttonRight</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">protected</span><span class="pln"> </span><span class="typ" style="color: #660066;">Button</span><span class="pln"> buttonUp</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">protected</span><span class="pln"> </span><span class="typ" style="color: #660066;">Button</span><span class="pln"> buttonDown</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> motorLeft</span><span class="pun" style="color: #666600;">=</span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> motorRight</span><span class="pun" style="color: #666600;">=</span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="kwd" style="color: #000088;">float</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">0</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">protected</span><span class="pln"> </span><span class="kwd" style="color: #000088;">void</span><span class="pln"> onCreate</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">Bundle</span><span class="pln"> savedInstanceState</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">super</span><span class="pun" style="color: #666600;">.</span><span class="pln">onCreate</span><span class="pun" style="color: #666600;">(</span><span class="pln">savedInstanceState</span><span class="pun" style="color: #666600;">);</span><span class="pln"> setContentView</span><span class="pun" style="color: #666600;">(</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="pln">layout</span><span class="pun" style="color: #666600;">.</span><span class="pln">activity_main</span><span class="pun" style="color: #666600;">);</span><span class="pln"> toggleButtonLedSTAT </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">ToggleButton</span><span class="pun" style="color: #666600;">)</span><span class="pln">findViewById</span><span class="pun" style="color: #666600;">(</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="pln">id</span><span class="pun" style="color: #666600;">.</span><span class="pln">toggleButtonLedSTAT</span><span class="pun" style="color: #666600;">);</span><span class="pln"> buttonLeft </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">Button</span><span class="pun" style="color: #666600;">)</span><span class="pln"> findViewById</span><span class="pun" style="color: #666600;">((</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="pln">id</span><span class="pun" style="color: #666600;">.</span><span class="pln">buttonLeft</span><span class="pun" style="color: #666600;">));</span><span class="pln"> buttonRight </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">Button</span><span class="pun" style="color: #666600;">)</span><span class="pln"> findViewById</span><span class="pun" style="color: #666600;">((</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="pln">id</span><span class="pun" style="color: #666600;">.</span><span class="pln">buttonRight</span><span class="pun" style="color: #666600;">));</span><span class="pln"> buttonUp </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">Button</span><span class="pun" style="color: #666600;">)</span><span class="pln"> findViewById</span><span class="pun" style="color: #666600;">((</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="pln">id</span><span class="pun" style="color: #666600;">.</span><span class="pln">buttonUp</span><span class="pun" style="color: #666600;">));</span><span class="pln"> buttonDown </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">Button</span><span class="pun" style="color: #666600;">)</span><span class="pln"> findViewById</span><span class="pun" style="color: #666600;">((</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="pln">id</span><span class="pun" style="color: #666600;">.</span><span class="pln">buttonDown</span><span class="pun" style="color: #666600;">));</span><span class="pln"> enableUi</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">);</span><span class="pln"> buttonLeft</span><span class="pun" style="color: #666600;">.</span><span class="pln">setOnTouchListener</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">View</span><span class="pun" style="color: #666600;">.</span><span class="typ" style="color: #660066;">OnTouchListener</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> onTouch</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">View</span><span class="pln"> v</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pln"> </span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">if</span><span class="pln"> </span><span class="pun" style="color: #666600;">((</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getAction</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">==</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_MOVE</span><span class="pun" style="color: #666600;">)||(</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getActionMasked</span><span class="pun" style="color: #666600;">()!=</span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_UP</span><span class="pun" style="color: #666600;">))</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> motorLeft </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> motorRight </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">float</span><span class="pun" style="color: #666600;">)</span><span class="lit" style="color: #006666;">0.5</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="kwd" style="color: #000088;">else</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">0</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="pun" style="color: #666600;">});</span><span class="pln"> buttonRight</span><span class="pun" style="color: #666600;">.</span><span class="pln">setOnTouchListener</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">View</span><span class="pun" style="color: #666600;">.</span><span class="typ" style="color: #660066;">OnTouchListener</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> onTouch</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">View</span><span class="pln"> v</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pln"> </span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">if</span><span class="pln"> </span><span class="pun" style="color: #666600;">((</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getAction</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">==</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_MOVE</span><span class="pun" style="color: #666600;">)||(</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getActionMasked</span><span class="pun" style="color: #666600;">()!=</span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_UP</span><span class="pun" style="color: #666600;">))</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> motorLeft </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">true</span><span class="pun" style="color: #666600;">;</span><span class="pln"> motorRight </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">true</span><span class="pun" style="color: #666600;">;</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">float</span><span class="pun" style="color: #666600;">)</span><span class="lit" style="color: #006666;">0.5</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="kwd" style="color: #000088;">else</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">0</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="pun" style="color: #666600;">});</span><span class="pln"> buttonUp</span><span class="pun" style="color: #666600;">.</span><span class="pln">setOnTouchListener</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">View</span><span class="pun" style="color: #666600;">.</span><span class="typ" style="color: #660066;">OnTouchListener</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> onTouch</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">View</span><span class="pln"> v</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pln"> </span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">if</span><span class="pln"> </span><span class="pun" style="color: #666600;">((</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getAction</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">==</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_MOVE</span><span class="pun" style="color: #666600;">)||(</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getActionMasked</span><span class="pun" style="color: #666600;">()!=</span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_UP</span><span class="pun" style="color: #666600;">))</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> motorLeft </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> motorRight </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">true</span><span class="pun" style="color: #666600;">;</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">1</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="kwd" style="color: #000088;">else</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">0</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="pun" style="color: #666600;">});</span><span class="pln"> buttonDown</span><span class="pun" style="color: #666600;">.</span><span class="pln">setOnTouchListener</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">View</span><span class="pun" style="color: #666600;">.</span><span class="typ" style="color: #660066;">OnTouchListener</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> onTouch</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">View</span><span class="pln"> v</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pln"> </span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">if</span><span class="pln"> </span><span class="pun" style="color: #666600;">((</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getAction</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">==</span><span class="pln"> </span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_MOVE</span><span class="pun" style="color: #666600;">)||(</span><span class="kwd" style="color: #000088;">event</span><span class="pun" style="color: #666600;">.</span><span class="pln">getActionMasked</span><span class="pun" style="color: #666600;">()!=</span><span class="typ" style="color: #660066;">MotionEvent</span><span class="pun" style="color: #666600;">.</span><span class="pln">ACTION_UP</span><span class="pun" style="color: #666600;">))</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> motorLeft </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">true</span><span class="pun" style="color: #666600;">;</span><span class="pln"> motorRight </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">float</span><span class="pun" style="color: #666600;">)</span><span class="lit" style="color: #006666;">0.5</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="kwd" style="color: #000088;">else</span><span class="pln"> speed </span><span class="pun" style="color: #666600;">=</span><span class="pln"> </span><span class="lit" style="color: #006666;">0</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">false</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="pun" style="color: #666600;">});</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End onCreate</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="kwd" style="color: #000088;">void</span><span class="pln"> enableUi</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">final</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> enable</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> runOnUiThread</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">Runnable</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">void</span><span class="pln"> run</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> toggleButtonLedSTAT</span><span class="pun" style="color: #666600;">.</span><span class="pln">setEnabled</span><span class="pun" style="color: #666600;">(</span><span class="pln">enable</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="com" style="color: #880000;">// the toggleButton is disable</span><span class="pln"> toggleButtonLedSTAT</span><span class="pun" style="color: #666600;">.</span><span class="pln">setChecked</span><span class="pun" style="color: #666600;">(</span><span class="pln">enable</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="com" style="color: #880000;">// switch on the toggleButton</span><span class="pln"> </span><span class="kwd" style="color: #000088;">if</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="pln">enable</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="typ" style="color: #660066;">Toast</span><span class="pun" style="color: #666600;">.</span><span class="pln">makeText</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">MainActivity</span><span class="pun" style="color: #666600;">.</span><span class="kwd" style="color: #000088;">this</span><span class="pun" style="color: #666600;">,</span><span class="pln"> getString</span><span class="pun" style="color: #666600;">(</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="kwd" style="color: #000088;">string</span><span class="pun" style="color: #666600;">.</span><span class="typ" style="color: #660066;">IOIOConnected</span><span class="pun" style="color: #666600;">),</span><span class="pln"> </span><span class="typ" style="color: #660066;">Toast</span><span class="pun" style="color: #666600;">.</span><span class="pln">LENGTH_LONG</span><span class="pun" style="color: #666600;">).</span><span class="pln">show</span><span class="pun" style="color: #666600;">();</span><span class="pln"> </span><span class="kwd" style="color: #000088;">else</span><span class="pln"> </span><span class="typ" style="color: #660066;">Toast</span><span class="pun" style="color: #666600;">.</span><span class="pln">makeText</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">MainActivity</span><span class="pun" style="color: #666600;">.</span><span class="kwd" style="color: #000088;">this</span><span class="pun" style="color: #666600;">,</span><span class="pln"> getString</span><span class="pun" style="color: #666600;">(</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="kwd" style="color: #000088;">string</span><span class="pun" style="color: #666600;">.</span><span class="typ" style="color: #660066;">IOIODisconnected</span><span class="pun" style="color: #666600;">),</span><span class="pln"> </span><span class="typ" style="color: #660066;">Toast</span><span class="pun" style="color: #666600;">.</span><span class="pln">LENGTH_LONG</span><span class="pun" style="color: #666600;">).</span><span class="pln">show</span><span class="pun" style="color: #666600;">();</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="pun" style="color: #666600;">});</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End enableUi</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">protected</span><span class="pln"> </span><span class="typ" style="color: #660066;">IOIOLooper</span><span class="pln"> createIOIOLooper</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">new</span><span class="pln"> </span><span class="typ" style="color: #660066;">Looper</span><span class="pun" style="color: #666600;">();</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End IOIOLooper</span><span class="pln"> </span><span class="kwd" style="color: #000088;">class</span><span class="pln"> </span><span class="typ" style="color: #660066;">Looper</span><span class="pln"> </span><span class="kwd" style="color: #000088;">extends</span><span class="pln"> </span><span class="typ" style="color: #660066;">BaseIOIOLooper</span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="com" style="color: #880000;">// Declare PIN</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">DigitalOutput</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDO0</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="com" style="color: #880000;">// LED STAT</span><span class="pln"> </span><span class="com" style="color: #880000;">// Motor DC : Right</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">DigitalOutput</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO36</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="com" style="color: #880000;">// L293D In 3</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">DigitalOutput</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO37</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="com" style="color: #880000;">// L293D In 4</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">PwmOutput</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinPWM38</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="com" style="color: #880000;">// L293D Enable 2</span><span class="pln"> </span><span class="com" style="color: #880000;">// Motor DC : Left</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">DigitalOutput</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO40</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="com" style="color: #880000;">// L293D In 2</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">DigitalOutput</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO41</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="com" style="color: #880000;">// L293D In 1</span><span class="pln"> </span><span class="kwd" style="color: #000088;">private</span><span class="pln"> </span><span class="typ" style="color: #660066;">PwmOutput</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinPWM39</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="com" style="color: #880000;">// L293D Enable 1</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">protected</span><span class="pln"> </span><span class="kwd" style="color: #000088;">void</span><span class="pln"> setup</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="kwd" style="color: #000088;">throws</span><span class="pln"> </span><span class="typ" style="color: #660066;">ConnectionLostException</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="typ" style="color: #660066;">InterruptedException</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln">
// Assign PIN
// LED STAT
PinDO0 = ioio_.openDigitalOutput(0, true);// super.loop();</span><span class="com" style="color: #880000;">// Motor DC : Right</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO36</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> ioio_</span><span class="pun" style="color: #666600;">.</span><span class="pln">openDigitalOutput</span><span class="pun" style="color: #666600;">(</span><span class="lit" style="color: #006666;">36</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO37</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> ioio_</span><span class="pun" style="color: #666600;">.</span><span class="pln">openDigitalOutput</span><span class="pun" style="color: #666600;">(</span><span class="lit" style="color: #006666;">37</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinPWM38</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> ioio_</span><span class="pun" style="color: #666600;">.</span><span class="pln">openPwmOutput</span><span class="pun" style="color: #666600;">(</span><span class="lit" style="color: #006666;">38</span><span class="pun" style="color: #666600;">,</span><span class="lit" style="color: #006666;">100</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="com" style="color: #880000;">// Motor DC : Left</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO40</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> ioio_</span><span class="pun" style="color: #666600;">.</span><span class="pln">openDigitalOutput</span><span class="pun" style="color: #666600;">(</span><span class="lit" style="color: #006666;">40</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO41</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> ioio_</span><span class="pun" style="color: #666600;">.</span><span class="pln">openDigitalOutput</span><span class="pun" style="color: #666600;">(</span><span class="lit" style="color: #006666;">41</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinPWM39</span><span class="pln"> </span><span class="pun" style="color: #666600;">=</span><span class="pln"> ioio_</span><span class="pun" style="color: #666600;">.</span><span class="pln">openPwmOutput</span><span class="pun" style="color: #666600;">(</span><span class="lit" style="color: #006666;">39</span><span class="pun" style="color: #666600;">,</span><span class="lit" style="color: #006666;">100</span><span class="pun" style="color: #666600;">);</span><span class="pln"> enableUi</span><span class="pun" style="color: #666600;">(</span><span class="kwd" style="color: #000088;">true</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="com" style="color: #880000;">// Start IOIO</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End setup</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">void</span><span class="pln"> loop</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="kwd" style="color: #000088;">throws</span><span class="pln"> </span><span class="typ" style="color: #660066;">ConnectionLostException</span><span class="pun" style="color: #666600;">,</span><span class="pln"> </span><span class="typ" style="color: #660066;">InterruptedException</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln">
// super.disconnected();</span><span class="typ" style="color: #660066;">PinDO0</span><span class="pun" style="color: #666600;">.</span><span class="pln">write</span><span class="pun" style="color: #666600;">(!</span><span class="pln">toggleButtonLedSTAT</span><span class="pun" style="color: #666600;">.</span><span class="pln">isChecked</span><span class="pun" style="color: #666600;">());</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinPWM39</span><span class="pun" style="color: #666600;">.</span><span class="pln">setDutyCycle</span><span class="pun" style="color: #666600;">(</span><span class="pln">speed</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO41</span><span class="pun" style="color: #666600;">.</span><span class="pln">write</span><span class="pun" style="color: #666600;">(</span><span class="pln">motorLeft</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO40</span><span class="pun" style="color: #666600;">.</span><span class="pln">write</span><span class="pun" style="color: #666600;">(!</span><span class="pln">motorLeft</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinPWM38</span><span class="pun" style="color: #666600;">.</span><span class="pln">setDutyCycle</span><span class="pun" style="color: #666600;">(</span><span class="pln">speed</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO37</span><span class="pun" style="color: #666600;">.</span><span class="pln">write</span><span class="pun" style="color: #666600;">(</span><span class="pln">motorRight</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="typ" style="color: #660066;">PinDIO36</span><span class="pun" style="color: #666600;">.</span><span class="pln">write</span><span class="pun" style="color: #666600;">(!</span><span class="pln">motorRight</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="kwd" style="color: #000088;">try</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="typ" style="color: #660066;">Thread</span><span class="pun" style="color: #666600;">.</span><span class="pln">sleep</span><span class="pun" style="color: #666600;">(</span><span class="lit" style="color: #006666;">10</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="kwd" style="color: #000088;">catch</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">InterruptedException</span><span class="pln"> e</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> e</span><span class="pun" style="color: #666600;">.</span><span class="pln">printStackTrace</span><span class="pun" style="color: #666600;">();</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End Loop</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">void</span><span class="pln"> disconnected</span><span class="pun" style="color: #666600;">()</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln">
enableUi(false);
toggleButtonLedSTAT.setEnabled(false); // the toggleButton is disable
toggleButtonLedSTAT.setChecked(false); // switch off the toggleButton
Toast.makeText(MainActivity.this,getString(R.string.IOIODisconnected),Toast.LENGTH_LONG).show();}</span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End disconnected</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">//End Looper</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> onCreateOptionsMenu</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">Menu</span><span class="pln"> menu</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> getMenuInflater</span><span class="pun" style="color: #666600;">().</span><span class="pln">inflate</span><span class="pun" style="color: #666600;">(</span><span class="pln">R</span><span class="pun" style="color: #666600;">.</span><span class="pln">menu</span><span class="pun" style="color: #666600;">.</span><span class="pln">menu_main</span><span class="pun" style="color: #666600;">,</span><span class="pln"> menu</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">true</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End onCreateOptionsMenu</span><span class="pln"> </span><span class="lit" style="color: #006666;">@Override</span><span class="pln"> </span><span class="kwd" style="color: #000088;">public</span><span class="pln"> </span><span class="kwd" style="color: #000088;">boolean</span><span class="pln"> onOptionsItemSelected</span><span class="pun" style="color: #666600;">(</span><span class="typ" style="color: #660066;">MenuItem</span><span class="pln"> item</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">int</span><span class="pln"> id </span><span class="pun" style="color: #666600;">=</span><span class="pln"> item</span><span class="pun" style="color: #666600;">.</span><span class="pln">getItemId</span><span class="pun" style="color: #666600;">();</span><span class="pln"> </span><span class="com" style="color: #880000;">//noinspection SimplifiableIfStatement</span><span class="pln"> </span><span class="kwd" style="color: #000088;">if</span><span class="pln"> </span><span class="pun" style="color: #666600;">(</span><span class="pln">id </span><span class="pun" style="color: #666600;">==</span><span class="pln"> R</span><span class="pun" style="color: #666600;">.</span><span class="pln">id</span><span class="pun" style="color: #666600;">.</span><span class="pln">action_settings</span><span class="pun" style="color: #666600;">)</span><span class="pln"> </span><span class="pun" style="color: #666600;">{</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">true</span><span class="pun" style="color: #666600;">;</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="kwd" style="color: #000088;">return</span><span class="pln"> </span><span class="kwd" style="color: #000088;">super</span><span class="pun" style="color: #666600;">.</span><span class="pln">onOptionsItemSelected</span><span class="pun" style="color: #666600;">(</span><span class="pln">item</span><span class="pun" style="color: #666600;">);</span><span class="pln"> </span><span class="pun" style="color: #666600;">}</span><span class="pln"> </span><span class="com" style="color: #880000;">// End onOptionsItemSelected</span><span class="pln">
This is a companion discussion topic for the original entry at https://community.robotshop.com/robots/show/ailgorrc-my-first-rc-car-with-ioio-l293d