Skip to content

sstaub/Seesaw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adafruit Seesaw library for Arduino

Arduino library for Adafruit Seesaw with a small footprint and easy to use.

Supported Hardware:

Example for the rotary encoder

#include "Arduino.h"
#include "Seesaw.h"

SeesawEncoder enc;

int32_t position;
int32_t positionLast;
bool buttonLast;

void setup() {
	Serial.begin(9600);
	delay(2000);
	enc.begin();
	enc.position(0);
	enc.pixel(0, 32, 0); // green
	}

void loop() {
	position = enc.position();
	if (position != positionLast) {
    Serial.print("Encoder: ");
    Serial.println(position);
		if (position > 0) enc.pixel(32, 0, 0); // red
		if (position < 0) enc.pixel(0, 0, 32); // blue
		if (position == 0) enc.pixel(0, 32, 0); // green
		positionLast = position;
		}
	if (enc.button() != buttonLast) {
		if (buttonLast == false) {
			buttonLast = true;
			Serial.println("Encoder: Button pressed!");
			}
		else {
			buttonLast = false;
			}
		}
	}

Documentation Encoder

Constructor

SeesawEncoder(uint8_t i2cAddr = ENCODER_I2C_ADDRESS, TwoWire &i2cPort = WIRE);
  • i2caddr optional I2C Address of the encoder, default is 0x36, [0x36 ... 0x3F]
  • i2cPort optional I2C Port, this is only needed if you another interface than the standard Wire like Wire1 ...

Create an Encoder object with a given address of the I2C interface and port.

Example

const uint8_t i2caddr = 0x37;
SeesawEncoder enc(i2caddr, Wire1); // use Wire1
SeesawEncoder enc; // use default port and address

Methods

begin()

void begin();

Initialize the Encoder module, this must done in setup().

Example

enc.begin();

interruptEncoder()

void interruptEncoder(bool interrupt);
  • interrupt true for interrupt set, false to disable interrupt

Set the interrupt pin (INT) of the Encoder module, this should done in setup().

Example

enc.interruptEncoder(true);

interruptButton()

void interruptButton(bool interrupt);
  • interrupt true for interrupt set, false to disable interrupt

Set the interrupt pin (INT) of the Encoder module, this should done in setup(). Beware that you get an interrupt for press and release the button!

Example

enc.interruptButton(true);

position()

int32_t position();
void position(int32_t pos);
  • pos optional for set a position

Get the position of the encoder, this should done in loop(). You can also set a position.

Example

int32_t pos = enc.position(); // get the encoder position
enc.position(0); // set the encoder position to 0

button()

bool button();

Get the state of the button, this should done in loop().

Example

bool btn = enc.button(); // get the button state

pixel()

void pixel(uint8_t red, uint8_t green, uint8_t blue);
  • red value for red
  • green value for green
  • blue value for blue

Set the Neopixel values.

Example

enc.pixel(32, 32, 32);

Documentation NeoKey4

Constructor

SeesawNeoKey4(uint8_t i2cAddr = ENCODER_I2C_ADDRESS, TwoWire &i2cPort = WIRE);
  • i2caddr optional I2C Address of the encoder, default is 0x36, [0x36 ... 0x3F]
  • i2cPort optional I2C Port, this is only needed if you another interface than the standard Wire like Wire1 ...

Create an Encoder object with a given address of the I2C interface and port.

Example

const uint8_t i2caddr = 0x37;
SeesawNeoKey4 key4(i2caddr, Wire1); // use Wire1
SeesawNeoKey4 key4; // use default port and address

Methods

begin()

void begin();

Initialize the NeoKey4 module, this must done in setup().

Example

key4.begin();

interruptButton()

void interruptButton(bool interrupt);
  • interrupt true for interrupt set, false to disable interrupt

Set the interrupt pin (INT) of the NeoKey4 module, this should done in setup(). Beware that you get an interrupt for press and release the button!

Example

key4.interruptButton(true);

button()

bool button(uint8_t num);
  • num button number [1 ... 4]

Get the state of the buttons, this should done in loop().

Example

bool btn1 = key4.button(1); // get the state of button 1

pixel()

void pixel(uint8_t num, uint8_t red, uint8_t green, uint8_t blue);
  • num pixel number [1 ... 4]
  • red value for red
  • green value for green
  • blue value for blue

Set the Neopixel color values.

Example

enc.pixel(1, 32, 32, 32); // set the colors of pixel 1

About

Library for Adafruit I2C Stemma QT Rotary Encoder, NeoKey and NeoSlider

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors