
![]()
Program Code
global [thumb-thresh index-thresh middle-thresh ring-thresh pinky-thresh prev-letter]
to convert-to-letter
when [switch 12] [clear-display]
loop[
waituntil [not (switch 15) ] waituntil [switch 15]
if (sensor-sum? = 0) [type "c]
if (sensor-sum? = 32) [type "e]
if (sensor-sum? = 1) [type "m]
if (sensor-sum? = 2) [type "n]
if (sensor-sum? = 16) [type "o]
if (sensor-sum? = 20) [type "s]
if (sensor-sum? = 8) [type "t]
if (sensor-sum? = 4) [type "x]
if (sensor-sum? = 2048) [type "a]
if (sensor-sum? = 1024) [type "z]
if (sensor-sum? = 1040) [type "d]
if (sensor-sum? = 3104) [type "g]
if (sensor-sum? = 3072) [type "l]
if (sensor-sum? = 3080) [type "q]
if (sensor-sum? = 1536) [type "h]
if (sensor-sum? = 1604) [type "r]
if (sensor-sum? = 1540) [type "u]
if (sensor-sum? = 1541) [type "v]
if (sensor-sum? = 3584) [type "k]
if (sensor-sum? = 1568) [type "p]
if (sensor-sum? = 1792) [type "w]
if (sensor-sum? = 208) [type "i]
if (sensor-sum? = 192) [type "j]
if (sensor-sum? = 2176) [type "y]
if (sensor-sum? = 960) [type "f]
if (sensor-sum? = 1920) [type "b]
]
end
to set-values
setthumb-thresh (sensor 0) + 25
setindex-thresh (sensor 1) + 25
setmiddle-thresh (sensor 2) + 18
setring-thresh (sensor 4) + 20
setpinky-thresh (sensor 6) + 20
end
to thumb-value?
ifelse (sensor 0) > thumb-thresh [output 0] [output 2048]
end
to index-value?
ifelse (sensor 1) > index-thresh [output 0] [output 1024]
end
to middle-value?
ifelse (sensor 2) > middle-thresh [output 0] [output 512]
end
to ring-value?
ifelse (sensor 4) > ring-thresh [output 0] [output 256]
end
to pinky-value?
ifelse (sensor 6) > pinky-thresh [output 0] [output 128]
end
to switch7-value?
ifelse (switch 7) [output 64] [output 0]
end
to switch8-value?
ifelse (switch 8) [output 32] [output 0]
end
to switch9-value?
ifelse (switch 9) [output 16] [output 0]
end
to switch10-value?
ifelse (switch 10) [output 8] [output 0]
end
to switch11-value?
ifelse (switch 11) [output 4] [output 0]
end
to switch13-value?
ifelse (switch 13) [output 2] [output 0]
end
to switch14-value?
ifelse (switch 14) [output 1] [output 0]
end
to clear-display
print "
end
to sensor-sum?
output (thumb-value? + index-value? + middle-value? + ring-value? + pinky-value? + switch7-value? +
switch8-value? + switch9-value? + switch10-value? + switch11-value? + switch13-value? + switch14-value? )
end
to control-wheel
when [switch 12] [clear-display]
loop[
waituntil [not (switch 15) ] waituntil [switch 15]
if (and (prev-letter = 1) (sensor-sum? = 2)) [a, setpower 4 a, on ]
if (sensor-sum? = 2) [type "n]
if (and (prev-letter = 1) (sensor-sum? = 960)) [a, off ]
if (sensor-sum? = 960) [type "f]
ifelse (sensor-sum? = 16) [setprev-letter 1 type "o ] [setprev-letter 0]
]
end
The following code is used in testing and debugging the program.
to convert2-to-letter
when [switch 12] [clear-display]
loop[
waituntil [not (switch 15) ] waituntil [switch 15]
print sensor-sum?
wait 10
if (sensor-sum? = 0) [print "c]
if (sensor-sum? = 32) [print "e]
if (sensor-sum? = 1) [print "m]
if (sensor-sum? = 2) [print "n]
if (sensor-sum? = 16) [print "o]
if (sensor-sum? = 20) [print "s]
if (sensor-sum? = 8) [print "t]
if (sensor-sum? = 4) [print "x]
if (sensor-sum? = 2048) [print "a]
if (sensor-sum? = 1024) [print "z]
if (sensor-sum? = 1040) [print "d]
if (sensor-sum? = 3104) [print "g]
if (sensor-sum? = 3072) [print "l]
if (sensor-sum? = 3080) [print "q]
if (sensor-sum? = 1536) [print "h]
if (sensor-sum? = 1604) [print "r]
if (sensor-sum? = 1540) [print "u]
if (sensor-sum? = 1541) [print "v]
if (sensor-sum? = 3584) [print "k]
if (sensor-sum? = 1568) [print "p]
if (sensor-sum? = 1792) [print "w]
if (sensor-sum? = 208) [print "i]
if (sensor-sum? = 192) [print "j]
if (sensor-sum? = 2176) [print "y]
if (sensor-sum? = 960) [print "f]
if (sensor-sum? = 1920) [print "b]
]
end
to print-thresh-value
loop[
print [starting thresh values]
wait 10
print thumb-thresh
wait 10
print index-thresh
wait 10
print middle-thresh
wait 10
print index-thresh
wait 10
print pinky-thresh
wait 10
]
end
to test-switch
loop[
if (switch-sum? = 64) [print "1000000]
if (switch-sum? = 32) [print "0100000]
if (switch-sum? = 16) [print "0010000]
if (switch-sum? = 8) [print "0001000]
if (switch-sum? = 4) [print "0000100]
if (switch-sum? = 2) [print "0000010]
if (switch-sum? = 1) [print "0000001]
if (switch-sum? = 0) [print "0000000]
]
end
to test-switch2
loop[
print "switch12
wait 10
print (switch 12)
wait 10
print "switch15
wait 10
print (switch 15)
wait 10
]
end
to switch-sum?
output (switch7-value? + switch8-value? + switch9-value? + switch10-value? + switch11-value? +
switch13-value? + switch14-value?)
end