# Programming with MicroPython: GPIO

### Import FutureBoard Library

Import the Library to make use of its functions.

```
from future import *
```

### 05: GPIO

#### 1. Initiate Pin Mode

```
MeowPin(pin,mode)
```

Initiates the GPIO with a mode, use P1\~P16 for parameter pin.

Possible values for parameter mode:

1. Digital Input: ‘IN’
2. Digital Output: ‘OUT’
3. Analog Input: ‘ANALOG’
4. Analog Output: ‘PWM’

#### 2. Read a Digital Value

```
getDigital() 
```

#### Sample Program

```
from future import *
# Digital Read Pins=['P0','P1','P2','P3','P8','P9','P12','P13','P14','P15','P16']
p0 = MeowPin('P0','IN')
print(p0.getDigital())
```

#### 3. Write a Digital Value

```
setDigital(val)
```

#### Sample Program

```
from future import *
import time
# Digital Write Pins=['P0','P1','P2','P6','P7','P8','P10','P13','P3','P9','P14','P15','P16']
p0 = MeowPin('P0','OUT')
while 1:
    p0.setDigital(1)
    time.sleep(1)
    p0.setDigital(0)
    time.sleep(1)
```

#### 4. Read an Analog Value

```
getAnalog(width)
```

FutureBoard has a 12-bit ADC, use 10 for 10-bit values and 12 for 12-bit values, default is 12.

#### Sample Program

```
from future import *
# Analog Read Pins=['P0','P1','P4','P12', 'P3', 'P14', 'P15', 'P16']

p0 = MeowPin('P0','ANALOG')
print(p0.getAnalog())
print(p0.getAnalog(width=10))
```

#### 5. Write an Analog Value

```
setAnalog(val)
```

#### Sample Program

```
from future import *
import time
# Analog Write Pins=['P0','P1','P2','P3','P8','P13','P14','P15','P16']

p0 = MeowPin('P0','PWM')
while 1:
    for i in range(1023): 
        p0.setAnalog(i)
        time.sleep_ms(1)
    for i in range(1023,0,-1): 
        p0.setAnalog(i)
        time.sleep_ms(1)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sharinghub-eng.kittenbot.hk/main-controllers/futureboard/futureboard-micropython-programming-tutorial/programming-with-micropython-gpio.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
