---
title: Control IO pins from any cog
description: "[SPIN](https://obex.parallax.com/code-language/spin/) ## Introduction The Propeller 1 has 32 I/O pins and 8 processor cores, known as cogs, that allow true real-time parallel processing. The I/O pins are available to all 8 cogs (cores). So how do you control them in…"
url: "https://obex.parallax.com/docs/chips-tips/propeller-1/control-io-pins-from-any-cog/"
updated: "2025-03-10"
category: Propeller 1
---

# Control IO pins from any cog

[SPIN](https://obex.parallax.com/code-language/spin/)

## Introduction

The Propeller 1 has 32 I/O pins and 8 processor cores, known as cogs, that allow true real-time parallel processing.

The I/O pins are available to all 8 cogs (cores).

So how do you control them in each cog, and what happens if two or more cogs operate on the same pins?

## Explanation

Each cog has its own set of output registers (DIRA and OUTA) which are combined in the hardware (logically OR'd together) to produce the actual state of the I/O pins.

Each cog also has an INA register, which allows any cog to read the current state of the 32 I/O pins, regardless of whether they're set as inputs or outputs.

##### Output State

In each cog that you want to have control over an I/O pin, you must set the DIRA and OUTA registers appropriately:

- Any cog with a 1 bit in its DIRA register forces that corresponding I/O pin into output mode.
- Any cog with a 1 bit in its OUTA register and a 1 bit in its DIRA register (same bit numbers) forces that output pin to be high.
- Any cog with a 0 bit in its OUTA register and a 1 bit in its DIRA register requests that output pin to be low. (Remembering that the outputs are OR'd together; the output will actually be low if no other cog has forced the output high).

```
dira[pin] := 1        ' Set output direction
outa[pin] := 1        ' Force pin to be high
outa[pin] := 0        ' Request pin to be low
```

##### Input State

In each cog that you want to read an I/O pin, you must set the DIRA register to 0, and then read the contents of the INA register.

```
dira[pin] := 0        ' Set input direction
value := ina[pin]     ' If pin is low, value = 0   If pin is high, value = 1
```

## Code Snippets

These SPIN code methods encapsulate the three basic I/O pin handling requirements:

```spin
PUB high(pin)
    ''' Makes pin output and high
    outa[pin] := 1
    dira[pin] := 1

PUB low(pin)
    ''' Makes pin output and low
    outa[pin] := 0
    dira[pin] := 1

PUB input(pin)
    ''' Makes pin input and returns current state (0..1)
    dira[pin] := 0
    return ina[pin]
```

## Code Example

This SPIN code example demonstrates using the three methods. When the code runs the first PUB method is always called, which means in this example the "main" method. The example will set I/O pin 7 to high state, I/O pin 8 to low state, and read the value of I/O pin 9 :

```spin
CON ' {System Clock Setup}
    _XINFREQ = 5_000_000
    _CLKMODE = XTAL1 + PLL16X

PUB main | value
    high(7)
    low (8)
    value := input(9)

PUB high(pin)
    ''' Makes pin output and high
    outa[pin] := 1
    dira[pin] := 1

PUB low(pin)
    ''' Makes pin output and low
    outa[pin] := 0
    dira[pin] := 1

PUB input(pin)
    ''' Makes pin input and returns current state (0..1)
    dira[pin] := 0
    return ina[pin]
```

---

## Resources

[Parallax Propeller 1 - Spin Language Documentation](https://www.parallax.com/package/propeller-manual)

---
