A Visual Programming Tool for your Smart Car
A Visual Programming Tool for your Smart Car
Creating a Visual Programming Tool in techBASIC
You saw a robotic car that can be controlled with techBASIC in a previous blog, Controlling a Smart Car with iOS. This blog builds on that, creating a visual programming language, written in techBASIC, to control the car.
This is another guest blog contributed by a techBASIC user. Drop me a note at our support line if you would like to showcase your own techBASIC projects on our web site.
Here’s the project in Leo’s words. Find out more at rekam1.blogspot.com.
Applying Neuroscience to your Applications
User Interfaces make the difference between an app that everyone loves and one that no one is aware of. One of the main reasons Apple products are successful is because they spend A LOT of time on getting the UI to their apps right. In this blog, we are going to walk you through a user interface that enables you to learn a new programming language using applied neuroscience.
The first principle of neuroscience we will use is to provide as few options as possible on a fully visible two dimensional surface. It's a lot easier to remember where something is (and what it does) if you can remember what it's beside and too many options make decisions slow and difficult. The second principle we'll cover is to group similar things together. For example, someone might expect to see things that they might use to cook food with in the kitchen (not in the bathroom). The third principle is to engage as many of the user's senses (and motors) as you can. For example, when you push a button with your finger, you should see something, hear something, read something, etc.
In the example we will cover in this blog, I will show you how I applied these three principles to enable users to quickly learn a new programming language. There are only 7 instructions in this programming language (called REKAM1). These 7 instructions enable you to interact directly with motors, servos, and sensors on a Bluetooth connected smart car platform (called REKAM-DR1). Everything else you might want to do with the platform (like record sensor data to a file/graph it/send emails/etc.) can be done in Basic with techBASIC.
This blog uses the hardware from the Controlling a Smart Car with iOS blog by adding a customized user interface that enables users to quickly learn how the 7 instructions of REKAM1 can be used to do interesting things with that smart car. In addition to the two wheels which are connected to pins 18 and 19 in this example, there is a servo connected to pin 2, a Bluetooth radio connected to pin 4, and a light sensor connected to pin 6.
In order to learn how these 7 instructions work together, I decided to make each button in the UI send 3 instructions that do something different and interesting with the smart car. Each button is labelled by the action those three lines of code perform and the three instructions sent to cause that action are shown at the top of the screen. In addition to interesting actions, I wanted to make it clear how changing the PIN number or value associated with an instruction would change how things worked.
For example, a button to spin right sets the energy to the right wheels to 0% and the energy to the left wheels to 100%. A button to turn right sets the energy to the right wheels to 50% and to the left wheels to 75%. A button to spin left or turn left sends similar commands but with left and right wheel pins (18 and 19) reversed. A button to go forward sets both wheels to the same energy level.
A button to flip the servo sets different values for pin 2 that effect the servo's orientation. A button to get the received signal strength when some condition is met will return the strength of the radio signal when that condition is met. A button to get the amount of light sensed by the photo resistor connected to pin 6 when some condition is met will in the same way return this value when that condition is met.
After deciding how many example instruction snippets I wanted to provide, I realized I also wanted a button to enable people to switch to texting mode where they could see the history of code generated by button presses and try their own combination of instructions in a program that started with "read" and ended with "do". I had nine buttons, so I decided to organize them in a 3X3 array and group them together in logical ways. (right turning stuff on right, left turning stuff on left, forward stuff in the center at the top, and that left four buttons. I decided to put the servo/mirror button between spin right and left since it was a visible action and the last three buttons (radio, light, and read/do) at the bottom.
The first thing I then did was to implement all these buttons with their action labels based on my thoughts above:
! Add a Read/Do button.
quit = Graphics.newButton(Graphics.width - 92, Graphics.height - 157, 100, 100)
quit.setTitle("read/do")
quit.setBackgroundColor(1, 1, 1)
quit.setGradientColor(0.6, 0.6, 0.6)
! Add a Right button.
rt = Graphics.newButton(Graphics.width - 92, Graphics.height - 557, 100, 100)
rt.setTitle("Right")
rt.setBackgroundColor(1, 1, 1)
rt.setGradientColor(0.6, 0.6, 0.6)
! Add a Left button.
lt = Graphics.newButton(Graphics.width - 692, Graphics.height - 557, 100, 100)
lt.setTitle("Left")
lt.setBackgroundColor(1, 1, 1)
lt.setGradientColor(0.6, 0.6, 0.6)
! Add a Right button.
ct = Graphics.newButton(Graphics.width - 392, Graphics.height - 357, 100, 100)
ct.setTitle("Mirror")
ct.setBackgroundColor(1, 1, 1)
ct.setGradientColor(0.6, 0.6, 0.6)
! Add a Forward button.
fw = Graphics.newButton(Graphics.width - 392, Graphics.height - 557, 100, 100)
fw.setTitle("Forward")
fw.setBackgroundColor(1, 1, 1)
fw.setGradientColor(0.6, 0.6, 0.6)
! Add a Spin Right button.
rspin = Graphics.newButton(Graphics.width - 92, Graphics.height - 357, 100, 100)
rspin.setTitle("Spin Right")
rspin.setBackgroundColor(1, 1, 1)
rspin.setGradientColor(0.6, 0.6, 0.6)
! Add a Spin Left button.
lspin = Graphics.newButton(Graphics.width - 692, Graphics.height - 357, 100, 100)
lspin.setTitle("Spin Left")
lspin.setBackgroundColor(1, 1, 1)
lspin.setGradientColor(0.6, 0.6, 0.6)
! Add a Light button.
light = Graphics.newButton(Graphics.width - 392, Graphics.height - 157, 100, 100)
light.setTitle("Light")
light.setBackgroundColor(1, 1, 1)
light.setGradientColor(0.6, 0.6, 0.6)
! Add a Radio button.
radio = Graphics.newButton(Graphics.width - 692, Graphics.height - 157, 100, 100)
radio.setTitle("Radio")
radio.setBackgroundColor(1, 1, 1)
radio.setGradientColor(0.6, 0.6, 0.6)
System.showGraphics
Once I implemented these buttons, I decided to implement the handlers for each button press. Each button press sets three lines of title text at the top of screen to three lines of code to be sent. In reality, we need only send two lines of code (line$ and line2$) since the third line is always corresponds to a half second delay before we are ready to send the next command.
! Handle a tap on a button.
!
! Parameters:
! ctrl - The button that was tapped.
! time - The time stamp when the button was tapped.
!
SUB touchUpInside (ctrl AS Button, time AS DOUBLE)
title.setText("sleep 22")
IF ctrl = quit THEN
move = 1
condition=0
tilt$=""
title.setText("do")
title2.setText("your text messages")
line$=""
line2$=""
title3.setText("read")
print "First text: read"
print "Then text/modify messages from above"
print "Finally text: do"
commandmode=1
END IF
IF ctrl = rt THEN
line$="put 19 0"
line2$="put 18 99"
title2.setText("put 19 0")
title3.setText("put 18 99")
END IF
IF ctrl = lt THEN
line$="put 19 99"
line2$="put 18 0"
title2.setText("put 19 99")
title3.setText("put 18 0")
END IF
IF ctrl = fw THEN
line$="put 19 99"
line2$="put 18 99"
title2.setText("put 19 99")
title3.setText("put 18 99")
END IF
IF ctrl = rspin THEN
line$="put 19 0"
line2$="put 18 55"
title2.setText("put 19 0")
title3.setText("put 18 55")
END IF
IF ctrl = lspin THEN
line$="put 19 55"
line2$="put 18 0"
title2.setText("put 19 55")
title3.setText("put 18 0")
END IF
IF ctrl = ct THEN
IF servotoggle = 1 THEN
servotoggle= 0
line$="put 2 2"
title3.setText("")
title2.setText("put 2 2")
ELSE IF servotoggle = 0 THEN
servotoggle = 1
line$="put 2 12"
title2.setText("put 2 12")
title3.setText("")
END IF
line2$=""
END IF
IF ctrl = light THEN
condition = 2
title3.setText("ifg 6 777")
line$="get 6"
line2$=""
title2.setText("get 6")
END IF
IF ctrl = radio THEN
condition = 2
title3.setText("ifl 4 -55")
line$="ifl 4 -55"
line2$=""
title2.setText("get 4")
END IF
print line$
print line2$
IF commandmode=0 THEN
print "sleep 22"
END IF
line$ = line$ & "\n"
line2$ = line2$ & "\n"
END SUB
The last piece of code we need to implement is the periodic subroutine that runs every half second. This subroutine simply sends whatever the values of line$ and line2$ are to the Smart Car every half second. If the read/do button has been pushed, commandmode is set to 1 and we input the command to be sent to the smart car through a prompt instead of through the graphical interface:
SUB nullEvent (time AS DOUBLE)
IF commandsAllowed AND (time > commandTime) THEN
IF commandmode = 1 THEN
input line$
END IF
DIM line%(LEN(line$) + 1)
FOR i = 1 TO LEN(line$)
line%(i) = ASC(MID(line$, i, 1))
NEXT
line%(UBOUND(line%, 1)) = 13
DIM ch AS BLECharacteristic
ch = findCharacteristic(rxUUID$)
blueRadiosPeripheral.writeCharacteristic(ch, line%, 1)
DIM line%(LEN(line2$) + 1)
FOR i = 1 TO LEN(line2$)
line%(i) = ASC(MID(line2$, i, 1))
NEXT
line%(UBOUND(line%, 1)) = 13
blueRadiosPeripheral.writeCharacteristic(ch, line%, 1)
IF line$ = "do" THEN
commandmode=2
END IF
! Don't allow additional commmands until this one is complete.
commandsAllowed = 0
IF commandmode = 0 THEN
line$="put 18 0\n"
line2$="put 19 0\n"
END IF
END IF
END SUB
With the code shown above, every time a button is pressed, the line$ and line2$ strings are set to the instructions we want to send to the smart car. After a half second delay, the subroutine that actually sends these strings over Bluetooth Low Energy is run. This is repeated until the user pushes the read/do button. This button puts the program into a different commandmode by setting commandmode to 1 instead of zero. In this mode, the user is prompted for input. When text is entered, it is immediately sent to the Bluetooth connected platform and the user is prompted again.
The third principle is called "multi-modal learning" in neuroscience. While the graphical UI enables users to see, hear, and read what specific instructions do, the text messaging mode (commandmode = 1) enables users to then WRITE combinations of these instructions to the platform. This last step is essential to actually learning and remembering the new programming language. Without the writing feature, the user would only learn how to do what the 9 buttons enable him/her to do.
The ability to see the history of instructions sent through buttons pushed and then reorganize and make slight modifications to the instructions previously sent is the key to being able to quickly learn this new language with this application.
Source
Here is the complete techBASIC source code.
! Define the various UUIDs
blueRadiosUUID$ = "DA2B84F1-6279-48DE-BDC0-AFBEA0226079"
infoUUID$ = "99564A02-DC01-4D3C-B04E-3BB1EF0571B2"
modeUUID$ = "A87988B9-694C-479C-900E-95DFA6C00A24"
rxUUID$ = "BF03260C-7205-4C25-AF43-93B1C299D159"
txUUID$ = "18CDA784-4BD3-4370-85BB-BFED91EC86AF"
! Set to 1 for verbose debug output.
debug% = 0
global$ = ""
line$ = "quiet\n"
line2$ = "put 19 0\n"
condition$="CENTER"
condition = 0
move=1
rd = 0
DIM forward(2) AS Integer
DIM backward(2) AS Integer
DIM rght(2) AS Integer
DIM lft(2) AS Integer
commandmode=0
! This is the device we've connected to, if any.
DIM blueRadiosPeripheral AS BLEPeripheral
! Used to create a pause before accepting commands.
DIM commandsAllowed AS INTEGER, commandTime AS DOUBLE, delay AS DOUBLE
delay = 0.5
servotoggle=0
! Print the version.
PRINT "Interactive Code Generator 1.0"
print "Enter the word do when ready to execute"
DIM quit AS Button
DIM rt AS Button
DIM lt AS Button
DIM ct AS Button
DIM fw AS Button
DIM rspin AS Button
DIM lspin AS Button
DIM light AS Button
DIM radio AS Button
Graphics.setPixelGraphics(0)
! Set up the GUI.
DIM title AS Label
DIM title2 AS Label
DIM title3 AS Label
title3 = Graphics.newLabel(20, 0, Graphics.width - 40, 50)
title3.setText("Interactive Code Generator")
title3.setAlignment(2)
title3.setFont("Arial", 36, 1)
title2 = Graphics.newLabel(20, 50, Graphics.width - 40, 50)
title2.setAlignment(2)
title2.setFont("Arial", 36, 1)
title = Graphics.newLabel(20, 100, Graphics.width - 40, 50)
title.setAlignment(2)
title.setFont("Arial", 36, 1)
! Add a Read/Do button.
quit = Graphics.newButton(Graphics.width - 92, Graphics.height - 157, 100, 100)
quit.setTitle("read/do")
quit.setBackgroundColor(1, 1, 1)
quit.setGradientColor(0.6, 0.6, 0.6)
! Add a Right button.
rt = Graphics.newButton(Graphics.width - 92, Graphics.height - 557, 100, 100)
rt.setTitle("Right")
rt.setBackgroundColor(1, 1, 1)
rt.setGradientColor(0.6, 0.6, 0.6)
! Add a Left button.
lt = Graphics.newButton(Graphics.width - 692, Graphics.height - 557, 100, 100)
lt.setTitle("Left")
lt.setBackgroundColor(1, 1, 1)
lt.setGradientColor(0.6, 0.6, 0.6)
! Add a Right button.
ct = Graphics.newButton(Graphics.width - 392, Graphics.height - 357, 100, 100)
ct.setTitle("Mirror")
ct.setBackgroundColor(1, 1, 1)
ct.setGradientColor(0.6, 0.6, 0.6)
! Add a Forward button.
fw = Graphics.newButton(Graphics.width - 392, Graphics.height - 557, 100, 100)
fw.setTitle("Forward")
fw.setBackgroundColor(1, 1, 1)
fw.setGradientColor(0.6, 0.6, 0.6)
! Add a Spin Right button.
rspin = Graphics.newButton(Graphics.width - 92, Graphics.height - 357, 100, 100)
rspin.setTitle("Spin Right")
rspin.setBackgroundColor(1, 1, 1)
rspin.setGradientColor(0.6, 0.6, 0.6)
! Add a Spin Left button.
lspin = Graphics.newButton(Graphics.width - 692, Graphics.height - 357, 100, 100)
lspin.setTitle("Spin Left")
lspin.setBackgroundColor(1, 1, 1)
lspin.setGradientColor(0.6, 0.6, 0.6)
! Add a Light button.
light = Graphics.newButton(Graphics.width - 392, Graphics.height - 157, 100, 100)
light.setTitle("Light")
light.setBackgroundColor(1, 1, 1)
light.setGradientColor(0.6, 0.6, 0.6)
! Add a Radio button.
radio = Graphics.newButton(Graphics.width - 692, Graphics.height - 157, 100, 100)
radio.setTitle("Radio")
radio.setBackgroundColor(1, 1, 1)
radio.setGradientColor(0.6, 0.6, 0.6)
System.showGraphics
! Start BLE processing and scan for a Blue Radios device.
BLE.startBLE
DIM uuid(1) AS STRING
uuid(1) = blueRadiosUUID$
BLE.startScan(uuid)
! Called to return information from a characteristic.
!
! Parameters:
! time - The time when the information was received.
! peripheral - The peripheral.
! characteristic - The characteristic whose information
! changed.
! kind - The kind of call. One of
! 1 - Called after a discoverDescriptors call.
! 2 - Called after a readCharacteristics call.
! 3 - Called to report status after a writeCharacteristics
! call.
! message - For errors, a human-readable error message.
! err - If there was an error, the Apple error number. If there
! was no error, this value is 0.
!
SUB BLECharacteristicInfo (time AS DOUBLE, peripheral AS BLEPeripheral, characteristic AS BLECharacteristic, kind AS INTEGER, message AS STRING, err AS LONG)
IF kind = 2 THEN
DIM ch AS BLECharacteristic
DIM value(1) AS INTEGER
value = characteristic.value
SELECT CASE characteristic.uuid
CASE infoUUID$
! The device returned the initial information.
DIM value(0) AS INTEGER
value = characteristic.value
IF debug% THEN
PRINT "Info: "
END IF
IF (value(1) BITAND $02) = $02 THEN
! Start watching for data from the device.
ch = findCharacteristic(txUUID$)
peripheral.setNotify(ch, 1)
! Set the mode to remote command mode.
! value = [2]
value = [1]
ch = findCharacteristic(modeUUID$)
peripheral.writeCharacteristic(ch, value, 1)
ELSE
PRINT "This device does not support terminal mode."
STOP
END IF
CASE txUUID$
! The device sent back information via TX.
data% = characteristic.value
data$ = ""
FOR i = 1 TO UBOUND(data%, 1)
IF data%(i) <> 13 THEN
data$ = data$ & CHR(data%(i))
END IF
NEXT
shared_value = 0
PRINT data$
CASE modeUUID$
! The device sent back the mode.
data% = characteristic.value
IF debug% THEN
PRINT "Mode: "; data%(1)
END IF
CASE ELSE
PRINT "Unexpected value from "; characteristic.uuid; ": "; valueToHex(characteristic.value)
END SELECT
ELSE IF kind = 3 THEN
! Write response recieved.
IF debug% THEN
r$ = "Response from characteristic " & characteristic.uuid
r$ = r$ & " with error code " & STR(err)
PRINT r$
END IF
! All write responses indicate we can accept a new command. Set the
! flag, but be sure and wait a short time for other response pieces to
! arrive.
IF characteristic.uuid = modeUUID$ THEN
! The mode has been set.
IF debug% THEN
peripheral.readCharacteristic(characteristic)
END IF
END IF
commandsAllowed = 1
commandTime = time + delay
END IF
END SUB
! Called when a peripheral is found. If it is a BlueRadios device, we
! initiate a connection to is and stop scanning for peripherals.
!
! Parameters:
! time - The time when the peripheral was discovered.
! peripheral - The peripheral that was discovered.
! services - List of services offered by the device.
! advertisements - Advertisements (information provided by the
! device without the need to read a service/characteristic)
! rssi - Received Signal Strength Indicator
SUB BLEDiscoveredPeripheral (time AS DOUBLE, peripheral AS BLEPeripheral, services() AS STRING, advertisements(,) AS STRING, rssi)
blueRadiosPeripheral = peripheral
IF debug% THEN
PRINT "Attempting to connect to "; blueRadiosPeripheral.bleName
END IF
IF blueRadiosPeripheral.bleName = "BlueRadios11588E" THEN
BLE.connect(blueRadiosPeripheral)
BLE.stopScan
PRINT "Platform Connected"
END IF
END SUB
! Called to report information about the connection status of the
! peripheral or to report that services have been discovered.
!
! Parameters:
! time - The time when the information was received.
! peripheral - The peripheral.
! kind - The kind of call. One of
! 1 - Connection completed
! 2 - Connection failed
! 3 - Connection lost
! 4 - Services discovered
! message - For errors, a human-readable error message.
! err - If there was an error, the Apple error number. If there
! was no error, this value is 0.
SUB BLEPeripheralInfo (time AS DOUBLE, peripheral AS BLEPeripheral, kind AS INTEGER, message AS STRING, err AS LONG)
DIM uuid(0) AS STRING
IF kind = 1 THEN
! The connection was established. Look for available services.
peripheral.discoverServices(uuid)
ELSE IF kind = 2 OR kind = 3 THEN
PRINT "The connection was lost."
ELSE IF kind = 4 THEN
! Services were found. If it is the main service, begin discovery
! of its characteristics.
DIM availableServices(1) AS BLEService
availableServices = peripheral.services
FOR a = 1 TO UBOUND(availableServices, 1)
IF debug% THEN
PRINT "Found service "; availableServices(a).UUID
END IF
IF availableServices(a).UUID = blueRadiosUUID$ THEN
peripheral.discoverCharacteristics(uuid, availableServices(a))
END IF
NEXT
END IF
END SUB
! Called to report information about a characteristic or included
! services for a service. If it is one we are interested in, start
! handling it.
!
! Parameters:
! time - The time when the information was received.
! peripheral - The peripheral.
! service - The service whose characteristic or included
! service was found.
! kind - The kind of call. One of
! 1 - Characteristics found
! 2 - Included services found
! message - For errors, a human-readable error message.
! err - If there was an error, the Apple error number. If there
! was no error, this value is 0.
SUB BLEServiceInfo (time AS DOUBLE, peripheral AS BLEPeripheral, service AS BLEService, kind AS INTEGER, message AS STRING, err AS LONG)
IF kind = 1 THEN
! Get the characteristics.
DIM characteristics(1) AS BLECharacteristic
characteristics = service.characteristics
FOR i = 1 TO UBOUND(characteristics, 1)
IF debug% THEN
PRINT "Found characteristic "; i; ": "; characteristics(i).uuid
END IF
IF characteristics(i).uuid = infoUUID$ THEN
peripheral.readCharacteristic(characteristics(i))
END IF
NEXT
END IF
END SUB
! Find a characteristic for the main blueRadiosUUID service by
! characteristic UUID. This cannot be done until after characteristics
! have been discovered.
!
! Parameters:
! uuid - The UUID of the characteristic to find.
!
! Returns: The characteristic.
FUNCTION findCharacteristic (uuid AS STRING) AS BLECharacteristic
! Find the main BlueRadios service.
DIM availableServices(1) AS BLEService
availableServices = blueRadiosPeripheral.services
FOR a = 1 TO UBOUND(availableServices, 1)
IF availableServices(a).UUID = blueRadiosUUID$ THEN
! Find the characteristic.
DIM availableCharacteristics(1) AS BLECharacteristic
availableCharacteristics = availableServices(a).characteristics
FOR c = 1 TO UBOUND(availableCharacteristics, 1)
IF availableCharacteristics(c).uuid = uuid THEN
findCharacteristic = availableCharacteristics(c)
GOTO 99
END IF
NEXT
END IF
NEXT
PRINT "An expected characteristic was not found."
STOP
99:
END FUNCTION
! Called when nothing else is happening.
!
! Check to see if commands can be accepted. If so, get a user command.
SUB nullEvent (time AS DOUBLE)
IF commandsAllowed AND (time > commandTime) THEN
IF commandmode = 1 THEN
input line$
ELSE
! Let the user type a command, sending it to RX.
sensors.setAccelRate(0.1)
ACCEL = sensors.accel
! IF ACCEL(2) > .4 THEN
! line$="put 18 50\n"
! line2$="put 19 50\n"
! PRINT "IF ACCEL(2) > .4 THEN"
! PRINT "line$= put 18 50\n"
! PRINT "line2$= put 19 50\n"
! ELSE IF ACCEL(2) < -.4 THEN
! PRINT "IF ACCEL(2) < -.4 THEN"
! IF servotoggle = 1 THEN
! PRINT "line$= put 2 2\n"
! line$="put 2 2\n"
! servotoggle = 0
! ELSE IF servotoggle = 0 THEN
! line$="put 2 12\n"
! PRINT "line$= put 2 12\n"
! servotoggle = 1
! END IF
! ELSE IF ACCEL(1) < -.4 THEN
! PRINT "IF ACCEL(1) < -.4 THEN"
! PRINT "line$= put 18 0\n"
! PRINT "line2$= put 19 50\n"
! line$ = "put 18 0\n"
! line2$ = "put 19 50\n"
! ELSE IF ACCEL(1) > .4 THEN
! PRINT "IF ACCEL(1) > .4 THEN"
! PRINT "line$= put 18 50\n"
! PRINT "line2$= put 19 0\n"
! line2$ = "put 19 0\n"
! line$ = "put 18 50\n"
! END IF
END IF
DIM line%(LEN(line$) + 1)
FOR i = 1 TO LEN(line$)
line%(i) = ASC(MID(line$, i, 1))
NEXT
line%(UBOUND(line%, 1)) = 13
DIM ch AS BLECharacteristic
ch = findCharacteristic(rxUUID$)
blueRadiosPeripheral.writeCharacteristic(ch, line%, 1)
DIM line%(LEN(line2$) + 1)
FOR i = 1 TO LEN(line2$)
line%(i) = ASC(MID(line2$, i, 1))
NEXT
line%(UBOUND(line%, 1)) = 13
blueRadiosPeripheral.writeCharacteristic(ch, line%, 1)
IF line$ = "do" THEN
commandmode=2
END IF
! Don't allow additional commmands until this one is complete.
commandsAllowed = 0
IF commandmode = 0 THEN
line$="put 18 0\n"
line2$="put 19 0\n"
END IF
END IF
END SUB
! Convert an array of byte values to a hexadecimal string.
!
! Parameters:
!value - The array of bytes.
!
! Returns: A string of hexadecimal digits representing the value.
FUNCTION valueToHex (value() AS INTEGER) AS STRING
s$ = ""
FOR i = 1 TO UBOUND(value, 1)
s$ = s$ & RIGHT(HEX(value(i)), 2)
NEXT
valueToHex = s$
END FUNCTION
! Handle a tap on a button.
!
! Parameters:
! ctrl - The button that was tapped.
! time - The time stamp when the button was tapped.
!
SUB touchUpInside (ctrl AS Button, time AS DOUBLE)
title.setText("sleep 22")
IF ctrl = quit THEN
move = 1
condition=0
tilt$=""
title.setText("do")
title2.setText("your text messages")
line$=""
line2$=""
title3.setText("read")
print "First text: read"
print "Then text/modify messages from above"
print "Finally text: do"
commandmode=1
END IF
IF ctrl = rt THEN
line$="put 19 0"
line2$="put 18 99"
title2.setText("put 19 0")
title3.setText("put 18 99")
END IF
IF ctrl = lt THEN
line$="put 19 99"
line2$="put 18 0"
title2.setText("put 19 99")
title3.setText("put 18 0")
END IF
IF ctrl = fw THEN
line$="put 19 99"
line2$="put 18 99"
title2.setText("put 19 99")
title3.setText("put 18 99")
END IF
IF ctrl = rspin THEN
line$="put 19 0"
line2$="put 18 55"
title2.setText("put 19 0")
title3.setText("put 18 55")
END IF
IF ctrl = lspin THEN
line$="put 19 55"
line2$="put 18 0"
title2.setText("put 19 55")
title3.setText("put 18 0")
END IF
IF ctrl = ct THEN
IF servotoggle = 1 THEN
servotoggle= 0
line$="put 2 2"
title3.setText("")
title2.setText("put 2 2")
ELSE IF servotoggle = 0 THEN
servotoggle = 1
line$="put 2 12"
title2.setText("put 2 12")
title3.setText("")
END IF
line2$=""
END IF
IF ctrl = light THEN
condition = 2
title3.setText("ifg 6 777")
line$="get 6"
line2$=""
title2.setText("get 6")
END IF
IF ctrl = radio THEN
condition = 2
title3.setText("ifl 4 -55")
line$="ifl 4 -55"
line2$=""
title2.setText("get 4")
END IF
print line$
print line2$
IF commandmode=0 THEN
print "sleep 22"
END IF
line$ = line$ & "\n"
line2$ = line2$ & "\n"
END SUB
Wednesday, June 4, 2014