<script>
var droid = new Android();
var fetch_data = function(sendda) {
// fire the event that the python script is waiting for.
droid.eventPost('fetch_data', sendda);
}
// this function gets called from the python script when it receives new sensor data.
droid.registerCallback('display_data', function(data) {
document.getElementById('output').innerHTML = 'Sensor value: ' + data.data;
});
</script>
droid.webViewShow('file:///sdcard/sl4a/scripts/androino1.html')
while True:
result = droid.eventWaitFor('fetch_data').result
droid.bluetoothWrite(result['data']) # send a space to your arduino to signal it to read a value from the sensor.
sensor_data = droid.bluetoothReadLine().result # read the line with the sensor value from arduino.
droid.eventClearBuffer() # workaround for a bug in SL4A r4.
droid.eventPost('display_data', sensor_data) # send an event with the sensor data back to the html page.
============================
余下arduino 部分,根据接收到的 AU L R D 字符进行处理即可