ASCII talker/listener
Posted: Mon Jan 04, 2016 11:30 am
Following my morse program, i've made a (temporary) switch to ASCII code as a means to connect two computers in a real-time mode.
The functions translate a string of ascii caracters to a binary stream, then a binary stream to a binary sound sequence, which is played via the speaker.
This sound stream may be received bij a microphone unit of another computer, which can translate back to an ascii coded string, if provided with the same software functions.
The iPhone and iPad have the necessary hardware and will need SB 5.1 to detect microphone input (the function "bin2str$()" has to be adapted for that pupose, or an extra function "micro2bin$()" be coded).
Text files may be transferred, but between two iOS units there are other, better and much faster possibilities.
Another usage is a real-time connection, in which one unit can control the other unit and vice versa in the SB environment.
For this purpose the extended, 8-bit ASCII code is used. This set contains all textual characters, but also numerous link protocol codes.
It should also be possible to "wirelessly connect" an iPhone/iPad to another brand of computer, provided it has microphone input and can be programmed with likewise functionality as the functions hereafter. In this way, an iPhone could be used to control a single board like the "Arduino", or use it's specific I/O features (for instance A/D conversion) not present in an iPhone. Anyone here has (experience with) an Arduino or likewise?
The functions translate a string of ascii caracters to a binary stream, then a binary stream to a binary sound sequence, which is played via the speaker.
This sound stream may be received bij a microphone unit of another computer, which can translate back to an ascii coded string, if provided with the same software functions.
The iPhone and iPad have the necessary hardware and will need SB 5.1 to detect microphone input (the function "bin2str$()" has to be adapted for that pupose, or an extra function "micro2bin$()" be coded).
Text files may be transferred, but between two iOS units there are other, better and much faster possibilities.
Another usage is a real-time connection, in which one unit can control the other unit and vice versa in the SB environment.
For this purpose the extended, 8-bit ASCII code is used. This set contains all textual characters, but also numerous link protocol codes.
It should also be possible to "wirelessly connect" an iPhone/iPad to another brand of computer, provided it has microphone input and can be programmed with likewise functionality as the functions hereafter. In this way, an iPhone could be used to control a single board like the "Arduino", or use it's specific I/O features (for instance A/D conversion) not present in an iPhone. Anyone here has (experience with) an Arduino or likewise?
Code: Select all
txt$= "Smart Basic isn't too bad!" ' text to be transmitted
cpm = 60 ' speed in caracters/minute
'
m$=str2bin$(txt$) ! print txt$ ! print ! print m$
a$=bin2notes$(m$) ! print ! print a$
notes tempo 13*cpm ! notes set a$ ! notes play
go_on: if notes_time()<notes_length() then go_on
t$=bin2str$(m$) ! print ! print t$ ! print count;" characters"
end
def str2bin$(s$)
bin$="00000010 "
for i=0 to len(s$)-1 ! bin$&=char2bin$(mid$(s$,i,1))&" " ! next i
return bin$ & "00000100 "
end def
def char2bin$(a$)
bin$="" ! x=asc(a$)
for i=7 to 0 step -1 ! bin$&=bit(x,i) ! next i
return bin$
end def
def bin2notes$(bin$)
n$="B6" ! n3$="Q.B6I" ! not$="18:I"
for i=0 to len(bin$)-1
t$=mid$(bin$,i,1)
if t$="0" then not$ &= n$
if t$="1" then not$ &= n3$
if t$=" " then not$ &= "R"
not$ &= "R"
next i
return not$
end def
def bin2str$(b$)
dim val(8)
if b$="" then return ""
for i=0 to 7 ! val(i)=2^(7-i) ! next i
.count=0 ! sp=-2 ! t$=""
do ! .count+=1 ! value=0 ! sp+=1
for i=0 to 7
sp+=1 ! if mid$(b$,sp,1)="1" then value+=val(i)
next i
if .count=1 and value<>2 then return ""
t$&=chr$(value)
until value=4
return t$
end def