Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 05:57 20 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : serial output and aliases

Author Message
gingpeakin
Newbie

Joined: 26/11/2021
Location: United Kingdom
Posts: 2
Posted: 03:57pm 27 Dec 2021
Copy link to clipboard 
Print this post

Apologies if I've missed something but I am new to MMbasic.  I am very familiar with PIC Basic (Proton).
I have 2 question - can I name a pin with an alias? Rather than pin(gp21) = 1 I would rather write either pin(LED) = 1 or better still LED = 1.
Also how can I write to a serial port single bytes or collections of bytes or variables as bytes rather that ASCII characters as seems to be the case with print #1, <stuff>

Thanks

Ging
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8298
Posted: 06:03pm 27 Dec 2021
Copy link to clipboard 
Print this post

First:

const REDLED = 4, GRNLED = 8
pin(REDLED) = 1
pin(GRNLED) = 0


Second:

AFAIK when you use PRINT # it always converts your variable to text.

nbr1 = 123, nbr2 = 456
open "numbers.txt" for output as #1
print #1, nbr1
print #1, nbr2
close #1

will produce the file numbers.txt

open "numbers.txt" for input as #1
line input #1, a$
line input #1, b$
close #1
x = VAL(a$): y = VAL(b$)

will make x=123 and y=456
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10617
Posted: 06:15pm 27 Dec 2021
Copy link to clipboard 
Print this post

  Quote  Also how can I write to a serial port single bytes or collections of bytes or variables as bytes rather that ASCII characters as seems to be the case with print #1, <stuff>


See the BIN2STR$ function in the manual
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 06:36pm 27 Dec 2021
Copy link to clipboard 
Print this post

Also CHR$()

John
 
gingpeakin
Newbie

Joined: 26/11/2021
Location: United Kingdom
Posts: 2
Posted: 11:53am 28 Dec 2021
Copy link to clipboard 
Print this post

Thanks everyone.  I've now got

Const IrisPin = 31  'GP26_A0
SetPin Irispin,ain  
SetPin gp0,gp1,Com1
Open "Com1:9600" As #1
Iris = pin(Irispin)      'variable Iris has the value of A0
Iris - Int(Iris * 30.2)  'turns value into 0 to 100
Print #1;Bin2str$(int8,iris);

and it does what I need - a single byte decimal value 0 to 100.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4147
Posted: 12:06pm 28 Dec 2021
Copy link to clipboard 
Print this post

Or

Print #1;Chr$(iris);

hmm, usually (other BASICs) a comma:

Print #1, Chr$(iris);

John
Edited 2021-12-28 22:07 by JohnS
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025