BASIC4PPC  COMPILER
PROGRAM  EXAMPLE:


MOUSE  STATUS
The Pocket PC used in this example is an HP IPAQ H2200 PDA with:

     64 MB of system RAM
     32 MB of system flash ROM  ( Dated: 5/22/2003 )
     OS Version:  Windows CE 4.20
     Display Resolution:  240 horizontal pixels  by  320 vertical pixels
     Processor Type:  Intel PXA255
     Bluetooth
     1 SDIO Card Slot
     1 Compact Flash Card Slot
     Headset / Microphone Jack

This HP H2200 PDA was manufactured in 2003.  Any of the newer Pocket PCs with
Bluetooth capability running the latest version of the Basic4ppc Compiler should be
able to run this simple program example.

The embedded bluetooth hardware module used in this example is a BlueSmiRF module.
You can search the Internet and find a variety of embedded bluetooth module boards and
fully packaged plug-and-go bluetooth dongles.

The microcontroller used in this example is the: Athena.  The Athena micro is a PIC
microcontroller that is pre-programmed with a BASIC Interpreter.  The Athena can
be programmed easily in BASIC using the IDE software written to run on a Windows
compatible desktop PC or laptop.
This program example will show
you how to send commands to a microcontroller across a wireless Bluetooth serial port link using the Mouse Down, Move and Up events when the PDA's Touch Screen is pressed using the
PDA's Stylus.
This Basic4ppc program example shows you how to use the Mouse Down, Mouse Move
and Mouse Up events.  We will use the PDA's Stylus to activate these events by touching
the PDA's Touch Screen.  When an event is triggered the program will send one ASCII
character to the microcontroller across the wireless Bluetooth serial port link.

This program example has the following features:

        *        Open the Bluetooth serial port connection.

        *        Close the Bluetooth serial port connection.

        *        Checkboxes allow you to Enabe or Disable the Mouse Down, Move and Up events.

        *        Transmit one ASCII character, "D", when the Mouse Down event is triggered.

        *        Transmit one ASCII character, "M", when the Mouse Move event is triggered.

        *        Transmit one ASCII character, "U",  when the Mouse Up event is triggered.

        *        Transmit one ASCII character or a string of ASCII characters using the PDA's
                  Soft Input Panel Keyboard and the "Send TX" button.

        *        Clear the contents of the TX and RX TextBox windows.

        *        The colorful "Cobblestone" graphic image at the bottom of the screen is
                  the area of the screen where the Stylus should be used to activate the
                  Mouse Down, Move and Up events.

The Pocket PC PDA will establish a wireless Bluetooth serial port link with the
BlueSmiRF Bluetooth hardware module.  The BlueSmiRF will be hardwired up to the
ATHENA microcontroller.  A single ASCII character transmitted by the PDA will be
received by the ATHENA microcontroller which will process the character as a "Command".
When a "Command" is received, the ATHENA microcontroller will execute the specific
software subroutine that is assigned to that particular "Command".
POCKET PC , BLUESMIRF AND ATHENA MICROCONTROLLER.
The first step is to "Open" the wireless Bluetooth Serial Port Link with the BlueSmiRF module.
To Enable the Mouse Down Event, tap on the Mouse Down
Checkbox with the Stylus until the "Check Mark" appears
in the box.

To trigger the Mouse Down Event, press down on the
colorful "Cobblestone" graphic image at the bottom of
the screen.  You will see the ASCII character "D" appear
in the TX TextBox window and the "RED" indicators on
both sides of the Mouse Down Checkbox will light up.
You can Enable or Disable any of the Mouse Down, Move
and Up Events in any combination that you choose by
tapping on the Checkboxes until the "Check Mark" appears
in them. 

Use the colorful "Cobblestone" graphic image area at the
bottom of the screen to trigger the Mouse Down, Move and
Up Events.
Press the "Clear" button to clear out any text characters
that currently appear in the TX and RX TextBox windows.
Use the PDA's Soft Input Panel Keyboard to enter a single
ASCII character or a string of ASCII characters that you
wish to transmit into the TX TextBox window.
Once you have entered the character(s) that you want
to transmit in the TX TextBox window, press the "Send TX"
button to transmit the character(s).
When you have finished, press the "Close" button to turn
off the wireless Bluetooth serial port connection between
the Pocket PC and the BlueSmiRF module.
To Enable the Mouse Move Event, tap on the Mouse Move
Checkbox with the Stylus until the "Check Mark" appears
in the box.

To trigger the Mouse Move Event, slide the Stylus across
the colorful "Cobblestone" graphic image at the bottom of
the screen.  You will see the ASCII character "M" appear
in the TX TextBox window and the "GREEN" indicators on
both sides of the Mouse Move Checkbox will light up.
To Enable the Mouse Up Event, tap on the Mouse Up
Checkbox with the Stylus until the "Check Mark" appears
in the box.

To trigger the Mouse Up Event, press down on the colorful "Cobblestone" graphic image at the bottom of the screen
then remove the Stylus from the screen.  You will see the ASCII character "U" appear in the TX TextBox window and the "BLUE" indicators on both sides of the Mouse Up Checkbox will light up.
BASIC4PPC CODE LISTING FOR THIS PROGRAM EXAMPLE.
Sub Globals
       portflag = 0
       strlabel0="COM 8: 9600,N,8,1"
       strlabel1=" [OFF]"
       strlabel2=" [ ON]"
       strlabeltemp=""
       m_down_flag=0
       m_move_flag=0
       m_up_flag=0
End Sub

Sub App_Start
       Form1.show

       textbox1.Text=""
       textbox2.Text=""
       label6.Text = strlabel0 & strlabel1
       strlabeltemp  = strlabel0 & strlabel1
     
       serial.New2 (8,9600,"N",8,1)

       textbox1.FontSize=13
       textbox2.FontSize=13

       image8.Image="sr.jpg"
       Sip=false
       Form1.Focus=true
End Sub

Sub ImageButtonClear_Click
       Textbox1.Text=""
       Textbox2.Text=""
       Form1.Focus=true
       label6.Text = strlabeltemp & ""
       clear_indicators
End Sub

Sub ImageButtonClear_ButtonDown
       image9.Image="sr.jpg"
End Sub

Sub ImageButtonClear_ButtonUp
       image9.Image="sw.jpg"
End Sub

Sub ImageButton1_Click
       image7.Image="sr.jpg"
       image8.Image="sw.jpg"

       If portflag = 0 Then
           serial.PortOpen=true
           portflag = 1
           label6.Text = strlabel0 & strlabel2
           strlabeltemp=label6.Text
           serial.enableoncomm=true
           serial.Output ("*")
       End If
End Sub

Sub ImageButton2_Click
       image7.Image="sw.jpg"
       image8.Image="sr.jpg"

       If portflag = 1 Then
          TextBox1.Text=""
          serial.Output ("^")
          serial.enableoncomm=false
          serial.PortOpen=false
          portflag = 0
          label6.Text = strlabel0 & strlabel1
          strlabeltemp=label6.Text
       End If
End Sub

Sub serial_OnCom
       TextBox2.Text=TextBox2.Text & serial.Inputstring
End Sub

Sub ImageButtonSendTX_Click
       serial.Output (Textbox1.Text)
       Form1.Focus=true
End Sub

Sub ImageButtonSendTX_ButtonDown
       image10.Image="sr.jpg"
End Sub

Sub ImageButtonSendTX_ButtonUp
       image10.Image="sw.jpg"
End Sub

Sub form1_mousedown(x1,y1)
       clear_indicators
       textbox1.Text=""
       textbox2.Text=""
       If m_down_flag=1 Then
           image1.Image="r50w35.jpg"
           image2.Image="r50w35.jpg"
           serial.Output ("D")
           textbox1.Text="D"
           label6.Text = strlabeltemp & " = D"
       End If
End Sub

Sub form1_mousemove(x1,y1)
       If m_move_flag=1 Then
           clear_indicators
           image3.Image="g50w35.jpg"
           image4.Image="g50w35.jpg"
           serial.Output ("M")
           textbox1.Text="M"
           label6.Text = strlabeltemp & " = M"
       End If
End Sub

Sub form1_mouseup(x1,y1)
       clear_indicators
       textbox1.Text=""
       textbox2.Text=""
       If m_up_flag=1 Then
           image5.Image="b50w35.jpg"
           image6.Image="b50w35.jpg"
           serial.Output ("U")
           textbox1.Text="U"
           label6.Text = strlabeltemp & " = U"
       End If
End Sub

Sub clear_indicators
       image1.Image="w50w35.jpg"
       image2.Image="w50w35.jpg"
       image3.Image="w50w35.jpg"
       image4.Image="w50w35.jpg"
       image5.Image="w50w35.jpg"
       image6.Image="w50w35.jpg"
End Sub

Sub CheckBox1_Click
       image1.Image="w50w35.jpg"
       image2.Image="w50w35.jpg"
       If checkbox1.Checked=true Then
          m_down_flag=1
       End If
       If checkbox1.Checked=false Then
          m_down_flag=0
       End If
End Sub

Sub CheckBox2_Click
       image3.Image="w50w35.jpg"
       image4.Image="w50w35.jpg"
       If checkbox2.Checked=true Then
           m_move_flag=1
       End If
       If checkbox2.Checked=false Then
           m_move_flag=0
       End If
End Sub

Sub CheckBox3_Click
       image5.Image="w50w35.jpg"
       image6.Image="w50w35.jpg"
       If checkbox3.Checked=true Then
           m_up_flag=1
       End If
       If checkbox3.Checked=false Then
           m_up_flag=0
       End If
End Sub
The Pocket PC Mouse Status program written
'for the ATHENA microcontroller receives ASCII command
'characters that are transmitted by the BASIC4PPC application
'which runs on the Pocket PC.

'The ATHENA will process the ASCII command characters that
'it has received and perform the programmed function.

'The KRONOS ROBOTICS ATHENA EDITOR Version 2.0.9 was
'used to Write the program code, Test, Debug and Program
'the compiled code into the ATHENA microcontroller.

'Dimension the variables used by the program.


dim a,s2cpu

'Initialize the Send to Cpu Flag equal to Zero.
'When this Flag = 0 No data will be processed
'by the ATHENA microcontroller.  When this
'Flag = 1 data will be processed by the ATHENA
'microcontroller.


s2cpu=0

'Initialize Port Pin 0 as an Input.  Serial data
'received by the BLUESMIRF module from the POCKET
'PC PDA across the Bluetooth connection will be
'received by the ATHENA microcontroller at its
'Port Pin 0.  The TX line of the BLUESMIRF module
'is physically wired to Port Pin 0 of the ATHENA.


input 0

'Set the Baud rate on the ATHENA to 9600:N:8:1

setbaud SBAUD9600

'The following line of code will read the serial data
'being sent to Port Pin 0 of the ATHENA.  If no data
'is currently being received at Port Pin 0 then program
'control will jump back to the label ( loop1 ).  This
'program statement will continually jump back to label
'( loop1 ) until an 8-bit byte is received at Port Pin 0.

'When an 8-bit byte is received at Port Pin 0, the
'received character byte will be stored in the program
'variable ( a ) and program execution will fall through
'to the next line of program code.


loop1:  serin loop1,0,a

'If the application running on the POCKET PC PDA sends
'special character ( * ),  then set the ( s2cpu ) flag = 1.
'This will tell the ATHENA to go ahead and process the
'8-bit character bytes that it receives.  Once the ( s2cpu )
'flag has been set equal to 1, program control will jump
'back to program label ( loop1 ) to receive the next byte.


        if a=42 then
           s2cpu=1
           goto loop1
        endif


'If the application running on the POCKET PC PDA sends
'the special character ( ^ ) then set the ( s2cpu ) flag = 0.
'This will tell the ATHENA not to process any of the 8-bit
'character bytes.   Once the ( s2cpu ) flag has been set
'equal to 0, program control will jump back to ( loop1 )
'to receive the next byte.


        if  a=94 then
           s2cpu=0
        endif


'When the (s2cpu) flag is set equal to 1, then go ahead and process the received
'8-bit chararacter byte.

      
       if s2cpu=1 then

           if a=68 then
              ' The POCKET PC has transmitted the ASCII character D which is 68 decimal.                
              ' Put the software code that you want to run when the
              ' Mouse Down Event is triggered here.
           endif

           if a=77 then
              ' The POCKET PC has transmitted the ASCII character M which is 77 decimal.                
              ' Put the software code that you want to run when the
              ' Mouse Move Event is triggered here.
           endif

          if a=85 then
              ' The POCKET PC has transmitted the ASCII character U which is 85 decimal.
              ' Put the software code that you want to run when the
              ' Mouse Up Event is triggered here.
           endif

        endif

        goto loop1
Program Code Listing for the ATHENA Microcontroller.