The friendly arms mini6410 Android development and learning note source code is synchronously updated. Please use the GIT tool for synchronization. For more information about git tools, see: http://progit.org/book/zh/
git clone https://code.google.com/p/androiddemoformini6410/
Adcactivity. Java
Package COM. mini6410.adc; import Java. util. timer; import Java. util. timertask; import android. app. activity; import android. OS. bundle; import android. OS. handler; import android. OS. message; import android. util. log; import android. widget. textview; import COM. friendlyarm. android SDK. hardwarecontroler; import COM. mini6410.r;/***** classname: adcactivity * Reason: ADC demo ** @ author snowdream * @ version * @ since V Er 1.1 * @ date 20112012-03-1612: 04 ** @ see */public class adcactivity extends activity {Private Static final string tag = "adcactivity "; /* refresh the UI tag */public static final int update_ui = 0;/* timer */private timer mtimer = NULL; private timertask mtimertask = NULL; /* controls used to display ADC return values */private textview mtextview_adc = NULL;/* read ADC return values */private int result = 0; @ overrideprotected void oncreate (bundle savedinstance State) {super. oncreate (savedinstancestate); setcontentview (R. layout. adcdemo); initui (); initdata ();}/***** initui: Initialize the UI ** @ Param * @ return * @ throws */private void initui () {mtextview_adc = (textview) findviewbyid (R. id. textview_adcresult);}/*** initdata: Creates a timer, sends a message every ms, and notifies the activity to refresh the UI. ** @ Param * @ return * @ throws */private void initdata () {mtimer = new timer (); mtimertask = new timertask () {@ overridepublic void run () {/* call the underlying library API to read the ADC value. Normally, the ADC value is returned. Otherwise, an error occurs and-1 */result = hardwarecontroler is returned. readadc (); If (-1 = Result) {log. E (TAG, "Read ADC error! ");} Else {log. I (TAG, "readadc Result:" + result); mhandler. sendmessage (mhandler. obtainmessage (update_ui) ;}}; mtimer. schedule (mtimertask, 0,500);} private handler mhandler = new handler () {@ overridepublic void handlemessage (Message MSG) {int type = MSG. what; Switch (type) {Case update_ui: mtextview_adc.settext (string. valueof (result); break; default: Break ;}};@ overrideprotected void ondestroy () {If (mtimer! = NULL) {mtimer. Cancel (); mtimer = NULL;} super. ondestroy ();}}
Adcdemo. xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/TextView_adctitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="@string/adcreslt" android:textSize="25sp" /> <TextView android:id="@+id/TextView_adcresult" android:layout_width="fill_parent" android:layout_height="130dip" android:gravity="center" android:text="0" android:textColor="@drawable/mediumvioletred" android:textSize="80sp" /></LinearLayout>
Preview effect: