// abot_bt_01.BAS // Use with abot_rbasic_bt_01.c // Load c program into abot eeprom (F11). When abot beeps start this program (arrow above) Port = 4 //change this as per your system main: setcommport Port,br115200 //set serial comms, baud rate depends on receiving BT device s = " " w = 38 // button size flag = 1 zlft = 0 zrgt = 0 chgflg = "" // Addbutton "name", x position, y position, button width, button height AddButton "fwd", 400, 250,w,w addbutton "rev", 400,350, w,w addbutton "rgt", 450, 300,w,w addbutton "lft", 350, 300,w,w addbutton "stp", 400, 300,w,w addbutton "end", 380, 450, 2*w,w addbutton "cvr", 475, 260,w,w addbutton "cvl", 325, 260,w,w addbutton "+spd", 500, 130, w,w addbutton "-spd", 500, 180,w,w // addslider "name", x pos, y pos, length, min value, max value, True = vertical // when vertical minimum is at top, max at bottom addslider "left_wheel", 365, 120, 120, -120, 20 , 1 addslider "right_wheel", 435, 120, 120, -120, 20 , 1 xytext 275, 100, "left wheel" xytext 450, 100, "right wheel" setsliderpos "left_wheel", 0 setsliderpos "right_wheel", 0 while flag // loop until end program command y = lastbutton() // if nothing since last time will = "" if y == chgflg // if y is same as last read, ignore it (debounce) y = "nochg" else chgflg = y // if y was different set chgflg to current value endif if y != "nochg" then xytext 400, 200, " " + y delay 20 // ** This section defines the command values to be sent to the ActivityBot program // Use the values of "z" in the ABot program command alias defines if y == "fwd" z = 1 //zlft += 10 // these are only for testing, comment out when using with bot //zrgt += 10 // the bot will send back wheel speed settings for the gauge elseif y == "rgt" z = 2 // zlft += 10 //zrgt -= 10 elseif y == "rev" z = 4 //zlft -= 10 //zrgt -= 10 elseif y == "lft" z = 8 //zlft -= 10 //zrgt += 10 elseif y == "stp" z = 16 //zlft = 0 //zrgt = 0 elseif y == "cvr" z = 32 elseif y == "cvl" z = 64 elseif y == "+spd" z = 34 elseif y == "-spd" z = 35 elseif y == "nochg" z = 0 elseif y == "end" flag = 0 else z = 0 endif // Only send command if 'z" greater than zero if z > 0 xytext 410, 220, " " // erase old value and display new xytext 410, 220, z serialout z // send command serbytesin 2,s,n //receive the wheel speed bytes if n < 2 then print n // did not receive correct number of bytes if n == 2 zlft = getstrbyte(s,1) // extraxt byte 1 -- left wheel speed zrgt = getstrbyte(s,2) // extract byte 2 zlft = zlft - 120 // decode bytes (-120 to +120) zrgt = zrgt - 120 // print n; zrgt // for debugging print in left margin setsliderpos "left_wheel", -zlft // negate value to display higher = up setsliderpos "right_wheel", -zrgt xytext 375, 100, " " // erase old text xytext 575, 100, " " xytext 375, 100, zlft // display wheel speed settings xytext 580, 100, zrgt endif endif if flag == 0 // end program serialout 255 // send end program command xytext 380, 400, "program over" delay(200) endif wend end