It is possible to access directly the GPIO lines using for example the DAISY-12 protoboard and set the GPIO line using the on() and off() methods of Pin class:
from ablib import Pin led = Pin('D11.2','OUTPUT') led.on() led.off()
to read the line state it is possible to follow two methods:
This mode consists to check the actual state of the line calling the get_value() method.
from ablib import Pin PB=Pin('D11.3','INPUT') #Never ending loop while True: if (PB.digitalRead()==0): print "Pressed" while PB.digitalRead()==0: pass
This mode consists to register a callback function with the set_edge() method that will call when the GPIO lines changes its state.
from ablib import Pin from time import sleep def pressed(): print "Pressed" PB=Pin('D11.3','INPUT') PB.set_edge("falling",pressed) #Never ending loop i=0 while True: print i i=i+1 sleep(0.5)
If you are using a Daisy module with leds, relays or other output devices you can use directly the name of the devices written on the PCB silk screen.
Following is an example to turn on a led on the DAISY-11 eight leds module:
from ablib import Daisy11 led = Daisy11('D11','L1') led.on() led.off()
This is an example with a Daisy-8 relay board plugged on D12 connector
from ablib import Daisy8 relay = Daisy8('D12','first','RL0') relay.on() relay.off()
The 'first' parms indicated that the Daisy8 used is plugged as first board on the flat cable. Up to board can be wired on the same daisy cable: 'first' and 'second'.