exklibur
06/09/2024, 4:38 PMfloitsch
06/09/2024, 4:43 PMVirtualPin yet, but I think your approach should work.floitsch
06/09/2024, 4:43 PMfloitsch
06/09/2024, 4:44 PMvalue parameter that is given to them. (At least I assume they get one)floitsch
06/09/2024, 4:46 PMEN-PIN gpio.VirtualPin ::
if it:
pcf.set --pin=1
else:
pcf.clear --pin=1exklibur
06/09/2024, 5:04 PMfloitsch
06/09/2024, 5:08 PMexklibur
06/14/2024, 5:38 PMfloitsch
06/14/2024, 5:39 PMexklibur
06/14/2024, 6:05 PMfloitsch
06/14/2024, 6:15 PMexklibur
06/14/2024, 8:23 PMmport .hd44780
import gpio
import i2c
import pcf8574 show *
main:
sda := gpio.Pin 21
scl := gpio.Pin 22
bus := i2c.Bus --sda=sda --scl=scl --frequency=100_000
device := bus.device 0x27
pcf ::= PCF8574 device
devices := bus.scan
devices.do: print "0x$(%02x it)"
print pcf.read
test-pin := gpio.VirtualPin ::
if it:
pcf.set --pin=2
else:
pcf.clear --pin=2
test-pin.set 1
sleep --ms=500
EN-PIN := gpio.VirtualPin ::
print "enable $it"
if it:
pcf.clear --pin=2
else:
pcf.set --pin=2
sleep --ms=200
RS-PIN ::= gpio.VirtualPin ::
print "register $it"
if it:
pcf.set --pin=0
else:
pcf.clear --pin=0
D4-PIN ::= gpio.VirtualPin ::
if it:
pcf.set --pin=4
else:
pcf.clear --pin=4
D5-PIN ::= gpio.VirtualPin ::
if it:
pcf.set --pin=5
else:
pcf.clear --pin=5
D6-PIN ::= gpio.VirtualPin ::
if it:
pcf.set --pin=6
else:
pcf.clear --pin=6
D7-PIN ::= gpio.VirtualPin ::
if it:
pcf.set --pin=7
else:
pcf.clear --pin=7
display := Hd44780
--type = Hd44780.LCD-20x4
--en = EN-PIN
--rs = RS-PIN
--d4 = D4-PIN
--d5 = D5-PIN
--d6 = D6-PIN
--d7 = D7-PIN
// Write text on third line, 6th column.
display.write --row=2 --column=1 "like a toiger"
sleep --ms=2000exklibur
06/14/2024, 8:25 PMfloitsch
06/14/2024, 8:25 PMif it == 1:floitsch
06/14/2024, 8:29 PMpcf-pin pcf/PCF8574 n/int -> Lambda:
return ::
if it == 1: pcf.set n
else: PCF.clear n
and then in your code:
D4-PIN ::= pcf-pin pcf 4
D5-PIN :: = ...exklibur
06/14/2024, 8:33 PMfloitsch
06/14/2024, 8:37 PMfloitsch
06/14/2024, 8:38 PMexklibur
06/14/2024, 8:39 PMexklibur
06/14/2024, 8:39 PMfloitsch
06/14/2024, 8:39 PMexklibur
06/14/2024, 8:40 PMexklibur
06/14/2024, 8:40 PMfloitsch
06/14/2024, 8:40 PMexklibur
06/14/2024, 9:12 PMimport gpio
import i2c
import hd44780 show *
import pcf8574 show *
pcf-pin pcf/PCF8574 n/int -> Lambda:
return ::
if it == 1:
pcf.clear --pin=n
else:
pcf.set --pin=n
main:
sda := gpio.Pin 21
scl := gpio.Pin 22
bus := i2c.Bus --sda=sda --scl=scl --frequency=100_000
device := bus.device 0x27
pcf ::= PCF8574 device
EN-PIN ::= gpio.VirtualPin (pcf-pin pcf 2)
RS-PIN ::= gpio.VirtualPin (pcf-pin pcf 0)
D4-PIN ::= gpio.VirtualPin (pcf-pin pcf 4)
D5-PIN ::= gpio.VirtualPin (pcf-pin pcf 5)
D6-PIN ::= gpio.VirtualPin (pcf-pin pcf 6)
D7-PIN ::= gpio.VirtualPin (pcf-pin pcf 7)
display := Hd44780
--type = Hd44780.LCD-20x4
--en = EN-PIN
--rs = RS-PIN
--d4 = D4-PIN
--d5 = D5-PIN
--d6 = D6-PIN
--d7 = D7-PIN
display.write --row=0 --column=1 "Test line"
sleep --ms=2000floitsch
06/14/2024, 9:14 PMfloitsch
06/14/2024, 9:15 PMexklibur
06/14/2024, 9:16 PMfloitsch
06/14/2024, 9:17 PMexklibur
06/14/2024, 9:19 PMexklibur
06/14/2024, 9:20 PMfloitsch
06/14/2024, 9:20 PMfloitsch
06/14/2024, 9:21 PMexklibur
06/14/2024, 9:22 PM