This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
1.SPI-Blink.ino

1.SPI-Blink

This example demonstrates the use of shift registers as if they were just normal IO pins. The SPI interface is used because it's easy and fast.

Boards:
AVR, AVR USB, Teensy 3.x, ESP32

Connections

Connect an LED (and series resistor) between the first output of the shift register and ground.

Remember to connect the enable pin of the shift register to ground and the master reset pin to Vcc in order to enable it.

Behavior

This sketch will just blink the LED once a second.

Mapping

None.

Written by PieterP, 2018-09-01 https://github.com/tttapa/Control-Surface

#include <Control_Surface.h> // Include the Control Surface library.
using namespace ExtIO; // Bring the ExtIO pin functions into your sketch
// Instantiate a shift register with the SPI slave select pin as latch pin, most
// significant bit first, and a total of 8 outputs.
SPIShiftRegisterOut<8> sreg = {SS, MSBFIRST};
const pin_t ledPin = sreg.pin(0); // first pin of the shift register
void setup() {
sreg.begin(); // Initialize the shift registers
pinMode(ledPin, OUTPUT); // You don't even need this line, since
// shift registers are always outputs
}
void loop() {
// Toggle the state of the LED every 1/2 second
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
ExtIO::pinMode
void pinMode(pin_t pin, uint8_t mode)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:34
SPIShiftRegisterOut
A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bu...
Definition: SPIShiftRegisterOut.hpp:23
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
HIGH
const uint8_t HIGH
Definition: ExtendedInputOutput.hpp:34
Control_Surface.h
The main header file that includes all Control-Surface header files.
ExtIO::digitalWrite
void digitalWrite(pin_t pin, uint8_t val)
An ExtIO version of the Arduino function.
Definition: ExtendedInputOutput.cpp:45
ExtendedIOElement::pin
pin_t pin(pin_t pin) const
Get the extended IO pin number of a given physical pin of this extended IO element.
Definition: ExtendedIOElement.cpp:26
LOW
const uint8_t LOW
Definition: ExtendedInputOutput.hpp:35
ExtIO
A namespace with alternatives to the standard Arduino IO functions that can be used with extended IO ...
Definition: ExtendedInputOutput.cpp:8
SPIShiftRegisterOut::begin
void begin() override
Initialize the shift register.
Definition: SPIShiftRegisterOut.ipp:14
OUTPUT
const uint8_t OUTPUT
Definition: ExtendedInputOutput.hpp:38