#GPIO in Python on Terra board

On the [TERRA Board](/terra) the GPIO lines are available on the Daisy connectors ([see the Terra pinout](/terra_pinout)). 

It is possible to access directly the GPIO lines using for example the [DAISY-12 protoboard](/DAISY-12) and set the GPIO line using the **on()** and **off()** methods of **Pin** class:

<pre class="prettyprint">
from ablib import Pin

led = Pin('D11.2','OUTPUT')
led.on()
led.off()
</pre>

to read the line state it is possible to follow two methods:

* Polling mode
* Event mode

##Polling mode

This mode consists to check the actual state of the line calling the get_value() method.

<pre class="prettyprint">
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        
</pre>

##Event mode

This mode consists to register a callback function with the set_edge() method that will call when the GPIO lines changes its state.

<pre class="prettyprint">
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)
</pre>

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](/DAISY-11):

<pre class="prettyprint">
from ablib import Daisy11

led = Daisy11('D11','L1')
led.on()
led.off()
</pre>

This is an example with a [Daisy-8 relay board](/DAISY-8) plugged on D12 connector

<pre class="prettyprint">
from ablib import Daisy8

relay = Daisy8('D12','first','RL0')
relay.on()
relay.off()
</pre>

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'. 
