Back to the Apple BASIC page or the IBM Basic page
It was a good idea for Lego to give children variables and then have subroutines convert the variables into binary code. It easy to teach a child that a variable equals a port number from 0-5 and that the computer magically turns the selected ports on/off. At that age, kids are being introduced to programming and computational reasoning. They don’t need to understand what happens at the bit level.
But if you’re adult and a semi-experienced programmer, then you can skip the variables and do your own decimal-binary conversion. It saves a step and saves computer memory too. Plus it’s always fun to tell your computer to directly enable to disable specific bits! (Well... as "directly" as BASIC can. To be truly direct you’d need to use assembly programming.)
You already know there are eight ports on the interface box labeled 0 through 7 and addressed from right to left -- just like how you count binary numbers. The first six ports (bits 0-5) are port 0 = decimal 1 = binary 1; port 1 = decimal 2 = binary 10; port 2 = decimal 4 = binary 11; port 3 = decimal 8 = binary 100; port 4 = decimal 16 = binary 101; and port 5 = decimal 32 = binary 110. It’s summarized in the chart:
So if you want to turn on port 3, then POKE its decimal value (8) to the address of the interface card. If you want to turn on ports 4 and 5, then add them up in binary (4=10000 and 5=100000, so 4+5=110000), flip the answer to decimal (it’s 32+16, so that is 48), and POKE it. On the Apple it would be POKE L,48 and on the IBM it would be OUT P,48. Use the same method in any combination you desire! To turn off a port, POKE it back to 0. To turn off one port and leave others on, POKE back the necessary amount. For example if you want to turn off port 5 but leave 4 on then poke (or "out") back L/P,16 and that would reset the value being sent to the interface box.
Home - History - Universal Buggy - Computers - Interface A - Connections - Peripherals - Code - Analog - Beyond - Lego Chevy V8
Copyright: Evan Koblentz, 2018-2024