ASCII talker/listener

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

ASCII talker/listener

Post by Henko »

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?

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

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: ASCII talker/listener

Post by Mr. Kibernetik »

Henko wrote:and will need SB 5.1 to detect microphone input
SB 5.1 will have no mike input functions.

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: ASCII talker/listener

Post by Henko »

You are right. I must have misinterpreted :
"Funtion to return system volume level will be implemented in version 5.1."

Post Reply