|
Forum Index : Microcontroller and PC projects : serial output and aliases
| Author | Message | ||||
| gingpeakin Newbie Joined: 26/11/2021 Location: United KingdomPosts: 2 |
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 KingdomPosts: 8298 |
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 KingdomPosts: 10617 |
See the BIN2STR$ function in the manual |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4147 |
Also CHR$() John |
||||
| gingpeakin Newbie Joined: 26/11/2021 Location: United KingdomPosts: 2 |
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 KingdomPosts: 4147 |
Or Print #1;Chr$(iris); hmm, usually (other BASICs) a comma: Print #1, Chr$(iris); John Edited 2021-12-28 22:07 by JohnS |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |