Control LEDs
Codi AXE-092
TxD BT a pin 4
symbol comanda = b27
inici:
serin C.4, T2400_4, #comanda
on comanda gosub rh, rl, yh, yl, gh, gl
goto inici
rh:
high C.0
return
rl:
low C.0
return
yh:
high C.1
return
yl:
low C.1
return
gh:
high C.2
return
gl:
low C.2
return
Codi DroidScript
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a button 1/3 of screen width and 1/4 screen height.
btn = app.CreateButton( "Connect", 0.4, 0.15 );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
//Create R toggle button.
tglR = app.CreateToggle( "Vermell", 0.4 );
tglR.SetMargins( 0, 0.02, 0, 0 );
tglR.SetOnTouch( tglR_OnTouch );
lay.AddChild( tglR );
//Create Y toggle button.
tglY = app.CreateToggle( "Groc", 0.4 );
tglY.SetMargins( 0, 0.02, 0, 0 );
tglY.SetOnTouch( tglY_OnTouch );
lay.AddChild( tglY );
//Create G toggle button.
tglG = app.CreateToggle( "Verd", 0.4 );
tglG.SetMargins( 0, 0.02, 0, 0 );
tglG.SetOnTouch( tglG_OnTouch );
lay.AddChild( tglG );
//Create Bluetooth serial object.
bt = app.CreateBluetoothSerial();
bt.SetOnConnect( bt_OnConnect )
bt.SetOnReceive( bt_OnReceive );
bt.SetSplitMode( "End", "\n" );
//Add layout to app.
app.AddLayout( lay );
}
//Called when user touches the button.
function btn_OnTouch()
{
bt.Connect( "taula1" );
}
//Called when we are connected.
function bt_OnConnect( ok )
{
if( ok ) app.ShowPopup( "Connected succesfully!" );
else app.ShowPopup( "Failed to connect!" );
}
//Called when we get data from device.
function bt_OnReceive( data )
{
app.ShowPopup( data );
}
//Called when user touches R toggle button.
function tglR_OnTouch( isChecked )
{
app.ShowPopup( "Vermell = " + isChecked );
if ( isChecked ) bt.Write( "0\n" );
else bt.Write( "1\n" );
}
//Called when user touches Y toggle button.
function tglY_OnTouch( isChecked )
{
app.ShowPopup( "Groc = " + isChecked );
if ( isChecked ) bt.Write( "2\n" );
else bt.Write( "3\n" );
}
//Called when user touches G toggle button.
function tglG_OnTouch( isChecked )
{
app.ShowPopup( "Verd = " + isChecked );
if ( isChecked ) bt.Write( "4\n" );
else bt.Write( "5\n" );
}
Mesura llum
Codi AXE-092
RxD BT a pin 1
symbol llum = b27 inici: readadc 4,llum serout C.1, T2400_4, (#llum,13,10) wait 1 goto inici
Codi DroidScript
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a button 1/3 of screen width and 1/4 screen height.
btn = app.CreateButton( "Connect", 0.4, 0.15 );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
app.AddLayout( lay );
//Create Bluetooth serial object.
bt = app.CreateBluetoothSerial();
bt.SetOnConnect( bt_OnConnect )
bt.SetOnReceive( bt_OnReceive );
bt.SetSplitMode( "End", "\n" );
}
//Called when user touches the button.
function btn_OnTouch()
{
bt.Connect( "taula2" );
}
//Called when we are connected.
function bt_OnConnect( ok )
{
if( ok ) bt.Write( "digitalWrite(LED1,1);\n" );
else app.ShowPopup( "Failed to connect!" );
}
//Called when we get data from device.
function bt_OnReceive( data )
{
app.ShowPopup( data );
}