Skip to content

Instantly share code, notes, and snippets.

@hotpaw2
Created December 9, 2017 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotpaw2/f93eab09d44fed63841b0cb0c0b64671 to your computer and use it in GitHub Desktop.
Save hotpaw2/f93eab09d44fed63841b0cb0c0b64671 to your computer and use it in GitHub Desktop.
100 rem SensorTag button press counter
102 rem This program will connect to and count TI SensorTag button presses.
104 rem It can count even in the background or with the iPhone display off.
106 rem Select a Sensor in the List and wait for connection success.
108 rem Tap the display to exit.
110 rem for HotPaw Basic 1.7.7 , rhn@hotpaw.com , 2017-12-08
112 rem
120 fn btle.init()
125 print "Initializing BLE ..."
130 fn sleep(5)
135 print "Pull down on list to rescan"
140 status = fn btle.list()
142 rem status = fn btle.list("","FFE0")
144 print status
146 if status < 0 then print "BTLE is off!" : stop
150 print "Waiting 4 seconds for a connection"
151 fn sleep(4)
160 uuid$ = fn btle.selected()
170 if uuid$ = "" then goto 200
180 print uuid$," device selected"
182 print fn btle.info(-2,2)
190 goto 400
200 for i = 0 to 19
210 uuid$ = fn btle.info(i,1)
220 if len(uuid$) < 2 then exit for
230 print i,uuid$
240 name$ = fn btle.info(i,2)
250 print name$
300 rem
360 if instr(name$,"SensorTag") > 0 then goto 400
362 if instr(name$,"Sensor Tag") > 0 then goto 400
364 rem Hunt for TI SensorTag 1.0 or 2.0
370 next i
380 print "finished scan, no SensorTag found"
390 end
400 rem
402 print "Button Service Found!"
410 servic$ = "FFE0"
420 charac$ = "FFE1"
440 fn btle.connect(1,uuid$,servic$,charac$)
450 fn sleep(1)
460 print fn btle.connect(2)
500 dim r%(256)
520 while (1)
530 fn sleep(0.5)
540 n = fn btle.responsedata(1,1,r%(0))
550 if (n > 0)
552 if r%(0) > 0 then count = count+1
560 print n,r%(0),count
570 endif
582 rem if fn touch(0) > 0 then exit while
584 if inkey$ <> "" then exit while
590 wend
950 fn btle.connect(-1)
960 print "Done"
990 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment