初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
#include "Adafruit_Crickit.h"
Adafruit_Crickit crickit;
void setup() {
Serial.begin(9600);
if(!crickit.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
//set the PWM freq for all the servo pins
crickit.setPWMFreq(CRICKIT_SERVO1, 50);
}
void loop() {
//set some PWMS
crickit.analogWrite(CRICKIT_SERVO1, 10000);
crickit.analogWrite(CRICKIT_SERVO2, 5000);
crickit.analogWrite(CRICKIT_SERVO3, 20000);
crickit.analogWrite(CRICKIT_SERVO4, 45000);
// read an ADC
Serial.print(crickit.analogRead(CRICKIT_SIGNAL4));
Serial.print(",");
// read a captouch
Serial.println(crickit.touchRead(CRICKIT_TOUCH2));
delay(1);
}

View File

@@ -0,0 +1,37 @@
// Adafruit Crickit Capacitive Touch Demo for Arduino
//
// Displays the value of Adafruit Crickit touchpad values when touched
//
// Tested with the Crickit + micro:bit, all good
#include "Adafruit_Crickit.h"
Adafruit_Crickit crickit;
#define CRICKIT_NUM_TOUCH 4
#define CAPTOUCH_THRESH 500
void setup() {
Serial.begin(9600); // Set up serial monitor - be sure it is set to 9600
Serial.println("Cap Touch Demo");
if(!crickit.begin()) { // Check if Crickit is attached
Serial.println("ERROR Starting crickit"); // If an error, print and
while(1) ; // go to a infinite loop to stop
}
else Serial.println("seesaw started"); // success, we have a Crickit
}
void loop() {
for(int i=0; i<CRICKIT_NUM_TOUCH; i++){ // check each touch input
uint16_t val = crickit.touchRead(i); // read the touch input
if(val > CAPTOUCH_THRESH){ // if the value read is > the threshold
Serial.print("CT"); // print info to serial monitor
Serial.print(i + 1);
Serial.print(" touched! value: ");
Serial.println(val);
}
}
delay(100); // wait tiny bit between checks
}

View File

@@ -0,0 +1,34 @@
#include "Adafruit_Crickit.h"
Adafruit_Crickit crickit;
#define NUM_DRIVES 4
int drives[] = {CRICKIT_DRIVE1, CRICKIT_DRIVE2, CRICKIT_DRIVE3, CRICKIT_DRIVE4};
void setup() {
Serial.begin(115200);
Serial.println("4 Drive demo!");
if(!crickit.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("Crickit started");
//our default frequency is 1khz
for(int i=0; i<NUM_DRIVES; i++)
crickit.setPWMFreq(drives[i], 1000);
}
void loop() {
for(int i=0; i<NUM_DRIVES; i++){
//turn all the way on
crickit.analogWrite(drives[i], CRICKIT_DUTY_CYCLE_OFF);
delay(100);
//turn all the way off
crickit.analogWrite(drives[i], CRICKIT_DUTY_CYCLE_MAX);
delay(100);
}
}

View File

@@ -0,0 +1,27 @@
#include "Adafruit_Crickit.h"
Adafruit_Crickit crickit;
void setup() {
Serial.begin(115200);
Serial.println("1 Drive demo!");
if(!crickit.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("Crickit started");
//our default frequency is 1khz
crickit.setPWMFreq(CRICKIT_DRIVE1, 1000);
}
void loop() {
//turn all the way on
crickit.analogWrite(CRICKIT_DRIVE1, CRICKIT_DUTY_CYCLE_OFF);
delay(500);
//turn all the way off
crickit.analogWrite(CRICKIT_DRIVE1, CRICKIT_DUTY_CYCLE_MAX);
delay(500);
}

View File

@@ -0,0 +1,108 @@
#include "Adafruit_Crickit.h"
#include "seesaw_neopixel.h"
#include "seesaw_servo.h"
#define NEOPIX_PIN 20
#define USE_NEOPIX
seesaw_NeoPixel strip = seesaw_NeoPixel(24, NEOPIX_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_Crickit crickit;
seesaw_Servo s1(&crickit);
seesaw_Servo s2(&crickit);
seesaw_Servo s3(&crickit);
seesaw_Servo s4(&crickit);
#define NUM_SERVOS 4
seesaw_Servo *servos[NUM_SERVOS] = {&s1, &s2, &s3, &s4};
#define COLOR_MAX 150
#define RED strip.Color(COLOR_MAX, 0, 0)
#define YELLOW strip.Color(COLOR_MAX, 150, 0)
#define GREEN strip.Color(0, COLOR_MAX, 0)
#define CYAN strip.Color(0, COLOR_MAX, 255)
#define BLUE strip.Color(0, 0, COLOR_MAX)
#define PURPLE strip.Color(180, 0, COLOR_MAX)
#define CRICKIT_NUM_ADC 8
static const uint8_t crickit_adc[CRICKIT_NUM_ADC] = { CRICKIT_SIGNAL1, CRICKIT_SIGNAL2, CRICKIT_SIGNAL3, CRICKIT_SIGNAL4,
CRICKIT_SIGNAL5, CRICKIT_SIGNAL6, CRICKIT_SIGNAL7, CRICKIT_SIGNAL8 };
#define CRICKIT_NUM_TOUCH 4
static const uint8_t crickit_drive[CRICKIT_NUM_TOUCH] = {CRICKIT_DRIVE1, CRICKIT_DRIVE2, CRICKIT_DRIVE3, CRICKIT_DRIVE4};
#define CAPTOUCH_THRESH 500
void setup() {
Serial.begin(9600);
while(!Serial);
if(!crickit.begin(0x49, A0)){
Serial.println("ERROR Starting crickit");
while(1);
}
else Serial.println("seesaw started");
if(!strip.begin(0x49, A0)){
Serial.println("ERROR Starting neopix");
while(1);
}
Serial.println("neopix started!");
s1.attach(CRICKIT_SERVO1);
s2.attach(CRICKIT_SERVO2);
s3.attach(CRICKIT_SERVO3);
s4.attach(CRICKIT_SERVO4);
}
void loop() {
#ifdef USE_NEOPIX
for(uint16_t i=0; i<strip.numPixels(); i++)
strip.setPixelColor(i, RED);
strip.show();
#endif
for(int i=0; i<CRICKIT_NUM_ADC; i++){
Serial.print(crickit.analogRead(crickit_adc[i]));
Serial.print("\t");
}
Serial.println("");
//TODO: fix drive3 and drive4
for(int i=0; i<4; i++){
uint16_t val = crickit.touchRead(i);
if(val > CAPTOUCH_THRESH){
crickit.analogWrite(crickit_drive[i], (1UL << 16) - 1);
Serial.print("CT");
Serial.print(i + 1);
Serial.print(" touched! value: ");
Serial.println(val);
}
else
crickit.analogWrite(crickit_drive[i], 0);
}
#ifdef USE_NEOPIX
for(uint16_t i=0; i<strip.numPixels(); i++)
strip.setPixelColor(i, GREEN);
strip.show();
#endif
for(int i=0; i<NUM_SERVOS; i++){
seesaw_Servo *s = servos[i];
s->write(1000);
}
delay(500);
#ifdef USE_NEOPIX
for(uint16_t i=0; i<strip.numPixels(); i++)
strip.setPixelColor(i, BLUE);
strip.show();
#endif
for(int i=0; i<NUM_SERVOS; i++){
seesaw_Servo *s = servos[i];
s->write(2000);
}
delay(500);
}

View File

@@ -0,0 +1,51 @@
#include "Adafruit_Crickit.h"
#include "seesaw_motor.h"
Adafruit_Crickit crickit;
seesaw_Motor motor_a(&crickit);
seesaw_Motor motor_b(&crickit);
void setup() {
Serial.begin(115200);
Serial.println("Dual motor demo!");
if(!crickit.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("Crickit started");
//attach motor a
motor_a.attach(CRICKIT_MOTOR_A1, CRICKIT_MOTOR_A2);
//attach motor b
motor_b.attach(CRICKIT_MOTOR_B1, CRICKIT_MOTOR_B2);
}
void loop() {
motor_a.throttle(1);
motor_b.throttle(-1);
delay(1000);
motor_a.throttle(.5);
motor_b.throttle(-.5);
delay(1000);
motor_a.throttle(0);
motor_b.throttle(0);
delay(1000);
motor_a.throttle(-.5);
motor_b.throttle(.5);
delay(1000);
motor_a.throttle(-1);
motor_b.throttle(1);
delay(1000);
motor_a.throttle(0);
motor_b.throttle(0);
delay(500);
}

View File

@@ -0,0 +1,45 @@
#include "Adafruit_Crickit.h"
#include "seesaw_servo.h"
Adafruit_Crickit crickit;
#define NUM_SERVOS 4
//create an array of 4 servos with our crickit object
seesaw_Servo servos[] = { seesaw_Servo(&crickit),
seesaw_Servo(&crickit),
seesaw_Servo(&crickit),
seesaw_Servo(&crickit) };
//these are the pins they will be attached to
int servoPins[] = { CRICKIT_SERVO1, CRICKIT_SERVO2, CRICKIT_SERVO3, CRICKIT_SERVO4 };
void setup() {
Serial.begin(115200);
//begin the crickit
if(!crickit.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("Crickit started");
//attach the servos to their pins
for(int i=0; i<NUM_SERVOS; i++)
servos[i].attach(servoPins[i]); // attaches the servo to the pin
}
void loop() {
//repeat for all 4 servos
for(int i=0; i<NUM_SERVOS; i++){
servos[i].write(0);
delay(1000);
servos[i].write(90);
delay(1000);
servos[i].write(180);
delay(1000);
servos[i].write(90);
delay(1000);
}
}

View File

@@ -0,0 +1,29 @@
#include "Adafruit_Crickit.h"
#include "seesaw_servo.h"
Adafruit_Crickit crickit;
seesaw_Servo myservo(&crickit); // create servo object to control a servo
void setup() {
Serial.begin(115200);
if(!crickit.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("Crickit started");
myservo.attach(CRICKIT_SERVO1); // attaches the servo to CRICKIT_SERVO1 pin
}
void loop() {
myservo.write(0);
delay(1000);
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(90);
delay(1000);
}

View File

@@ -0,0 +1,40 @@
#include "Adafruit_Crickit.h"
Adafruit_Crickit crickit;
#define BUTTON_1 CRICKIT_SIGNAL1
#define BUTTON_2 CRICKIT_SIGNAL2
#define LED_1 CRICKIT_SIGNAL3
#define LED_2 CRICKIT_SIGNAL4
void setup() {
Serial.begin(9600);
if(!crickit.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("Crickit started");
//Two buttons are pullups, connect to ground to activate
crickit.pinMode(BUTTON_1, INPUT_PULLUP);
crickit.pinMode(BUTTON_2, INPUT_PULLUP);
// Two LEDs are outputs, on by default
crickit.pinMode(LED_1, OUTPUT);
crickit.pinMode(LED_2, OUTPUT);
crickit.digitalWrite(LED_1, HIGH);
crickit.digitalWrite(LED_2, HIGH);
}
void loop() {
if(!crickit.digitalRead(BUTTON_1))
crickit.digitalWrite(LED_1, HIGH);
else
crickit.digitalWrite(LED_1, LOW);
if(!crickit.digitalRead(BUTTON_2))
crickit.digitalWrite(LED_2, HIGH);
else
crickit.digitalWrite(LED_2, LOW);
}

View File

@@ -0,0 +1,31 @@
/*
* This example shows how to read and write EEPROM data. Try writing
* then removing power from both devices, commenting out the write, and
* uploading again.
*/
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
void setup() {
Serial.begin(115200);
//while(!Serial);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
Serial.println("writing 0x0D to register 0x02");
ss.EEPROMWrite8(0x02, 0xD);
delay(500);
Serial.print("reading from register 0x02...0x");
Serial.println(ss.EEPROMRead8(0x02), HEX);
}
void loop() {
//DONT WRITE EEPROM IN A LOOP!!!! YOU WILL DESTROY YOUR FLASH!!!
}

View File

@@ -0,0 +1,85 @@
#include "Adafruit_NeoKey_1x4.h"
#include "seesaw_neopixel.h"
Adafruit_NeoKey_1x4 neokey; // Create the NeoKey object
void setup() {
Serial.begin(115200);
while (! Serial) delay(10);
if (! neokey.begin(0x30)) { // begin with I2C address, default is 0x30
Serial.println("Could not start NeoKey, check wiring?");
while(1) delay(10);
}
Serial.println("NeoKey started!");
// Pulse all the LEDs on to show we're working
for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) {
neokey.pixels.setPixelColor(i, 0x808080); // make each LED white
neokey.pixels.show();
delay(50);
}
for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) {
neokey.pixels.setPixelColor(i, 0x000000);
neokey.pixels.show();
delay(50);
}
}
void loop() {
uint8_t buttons = neokey.read();
// Check each button, if pressed, light the matching neopixel
if (buttons & (1<<0)) {
Serial.println("Button A");
neokey.pixels.setPixelColor(0, 0xFF0000); // red
} else {
neokey.pixels.setPixelColor(0, 0);
}
if (buttons & (1<<1)) {
Serial.println("Button B");
neokey.pixels.setPixelColor(1, 0xFFFF00); // yellow
} else {
neokey.pixels.setPixelColor(1, 0);
}
if (buttons & (1<<2)) {
Serial.println("Button C");
neokey.pixels.setPixelColor(2, 0x00FF00); // green
} else {
neokey.pixels.setPixelColor(2, 0);
}
if (buttons & (1<<3)) {
Serial.println("Button D");
neokey.pixels.setPixelColor(3, 0x00FFFF); // blue
} else {
neokey.pixels.setPixelColor(3, 0);
}
neokey.pixels.show();
delay(10); // don't print too fast
}
/******************************************/
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
return 0;
}

View File

@@ -0,0 +1,81 @@
#include "Adafruit_NeoKey_1x4.h"
#include "seesaw_neopixel.h"
Adafruit_NeoKey_1x4 neokey; // Create the NeoKey object
//define a callback for key presses
NeoKey1x4Callback blink(keyEvent evt) {
uint8_t key = evt.bit.NUM;
if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
Serial.print("Key press ");
Serial.println(key);
neokey.pixels.setPixelColor(key, Wheel(map(key, 0, neokey.pixels.numPixels(), 0, 255)));
} else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) {
Serial.print("Key release ");
Serial.println(key);
neokey.pixels.setPixelColor(key, 0);
}
// Turn on/off the neopixels!
neokey.pixels.show();
return 0;
}
void setup() {
Serial.begin(115200);
while (! Serial) delay(10);
if (! neokey.begin(0x30)) { // begin with I2C address, default is 0x30
Serial.println("Could not start NeoKey, check wiring?");
while(1) delay(10);
}
Serial.println("NeoKey started!");
// Pulse all the LEDs on to show we're working
for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) {
neokey.pixels.setPixelColor(i, 0x808080); // make each LED white
neokey.pixels.show();
delay(50);
}
for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) {
neokey.pixels.setPixelColor(i, 0x000000);
neokey.pixels.show();
delay(50);
}
// set callbacks
for(int i=0; i<NEOKEY_1X4_KEYS; i++){
neokey.registerCallback(i, blink);
}
}
void loop() {
// we handle all key events with the callbacks
neokey.read();
delay(10); // don't print too fast
}
/******************************************/
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
return 0;
}

View File

@@ -0,0 +1,92 @@
#include "Adafruit_NeoKey_1x4.h"
#include "seesaw_neopixel.h"
#define Y_DIM 2 //number of rows of keys
#define X_DIM 4 //number of columns of keys
// create a matrix of NeoKey 1x4's
// this example is just two, one on top of another to make a 2x4 grid
Adafruit_NeoKey_1x4 nk_array[Y_DIM][X_DIM/4] = {
{ Adafruit_NeoKey_1x4(0x30) },
{ Adafruit_NeoKey_1x4(0x31) },
};
// pass this matrix to the multi-neokey object
Adafruit_MultiNeoKey1x4 neokey((Adafruit_NeoKey_1x4 *)nk_array, Y_DIM, X_DIM/4);
void setup() {
Serial.begin(115200);
while (! Serial) delay(10);
if (! neokey.begin()) { // start matrix
Serial.println("Could not start NeoKeys, check wiring?");
while(1) delay(10);
}
Serial.println("NeoKey started!");
// Pulse all the LEDs on to show we're working
for (uint16_t i=0; i< X_DIM*Y_DIM; i++) {
neokey.setPixelColor(i, 0x808080); // make each LED white
neokey.show();
delay(50);
}
for (uint16_t i=0; i< X_DIM*Y_DIM; i++) {
neokey.setPixelColor(i, 0x000000);
neokey.show();
delay(50);
}
// activate all keys and set callbacks
for(int y=0; y<Y_DIM; y++){
for(int x=0; x<X_DIM; x++){
neokey.registerCallback(x, y, blink);
}
}
}
void loop() {
neokey.read();
delay(10); // don't print too fast
}
//define a callback for key presses
NeoKey1x4Callback blink(keyEvent evt) {
uint8_t key = evt.bit.NUM;
if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
Serial.print("Key press ");
Serial.println(key);
neokey.setPixelColor(key, Wheel(map(key, 0, X_DIM*Y_DIM, 0, 255)));
} else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) {
Serial.print("Key release ");
Serial.println(key);
neokey.setPixelColor(key, 0);
}
// Turn on/off the neopixels!
neokey.show();
return 0;
}
/******************************************/
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
return 0;
}

View File

@@ -0,0 +1,86 @@
#include "Adafruit_NeoKey_1x4.h"
#include "seesaw_neopixel.h"
Adafruit_NeoKey_1x4 neokey;
void setup() {
Serial.begin(115200);
while (! Serial) delay(10);
if (! neokey.begin(0x30)) {
Serial.println("Could not start NeoKey, check wiring?");
while(1) delay(10);
}
Serial.println("NeoKey started!");
for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) {
neokey.pixels.setPixelColor(i, Wheel(map(i, 0, neokey.pixels.numPixels(), 0, 255)));
neokey.pixels.show();
delay(50);
}
for (uint16_t i=0; i<neokey.pixels.numPixels(); i++) {
neokey.pixels.setPixelColor(i, 0x000000);
neokey.pixels.show();
delay(50);
}
}
uint8_t j=0; // this variable tracks the colors of the LEDs cycle.
void loop() {
uint8_t buttons = neokey.read();
for (int i=0; i< neokey.pixels.numPixels(); i++) {
neokey.pixels.setPixelColor(i, Wheel(((i * 256 / neokey.pixels.numPixels()) + j) & 255));
}
if (buttons & (1<<0)) {
Serial.println("Button A");
} else {
neokey.pixels.setPixelColor(0, 0);
}
if (buttons & (1<<1)) {
Serial.println("Button B");
} else {
neokey.pixels.setPixelColor(1, 0);
}
if (buttons & (1<<2)) {
Serial.println("Button C");
} else {
neokey.pixels.setPixelColor(2, 0);
}
if (buttons & (1<<3)) {
Serial.println("Button D");
} else {
neokey.pixels.setPixelColor(3, 0);
}
neokey.pixels.show();
delay(10); // don't print too fast
j++; // make colors cycle
}
/******************************************/
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
return 0;
}

View File

@@ -0,0 +1,130 @@
#include <seesaw_neopixel.h>
#define PIN 10
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
seesaw_NeoPixel strip = seesaw_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
Serial.begin(115200);
if(!strip.begin()){
Serial.println("ERROR");
while(1);
}
Serial.println("seesaw started!");
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Some example procedures showing how to display to the pixels:
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
// Send a theater pixel chase in...
theaterChase(strip.Color(127, 127, 127), 50); // White
theaterChase(strip.Color(127, 0, 0), 50); // Red
theaterChase(strip.Color(0, 0, 127), 50); // Blue
rainbow(20);
rainbowCycle(20);
theaterChaseRainbow(50);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

View File

@@ -0,0 +1,79 @@
/* This example shows basic usage of the NeoTrellis.
The buttons will light up various colors when pressed.
The interrupt pin is not used in this example.
*/
#include "Adafruit_NeoTrellis.h"
Adafruit_NeoTrellis trellis;
//define a callback for key presses
TrellisCallback blink(keyEvent evt){
// Check is the pad pressed?
if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING) {
trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
} else if (evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING) {
// or is the pad released?
trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
}
// Turn on/off the neopixels!
trellis.pixels.show();
return 0;
}
void setup() {
Serial.begin(9600);
//while(!Serial);
if (!trellis.begin()) {
Serial.println("Could not start trellis, check wiring?");
while(1);
} else {
Serial.println("NeoPixel Trellis started");
}
//activate all keys and set callbacks
for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING);
trellis.registerCallback(i, blink);
}
//do a little animation to show we're on
for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
trellis.pixels.setPixelColor(i, Wheel(map(i, 0, trellis.pixels.numPixels(), 0, 255)));
trellis.pixels.show();
delay(50);
}
for (uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
trellis.pixels.setPixelColor(i, 0x000000);
trellis.pixels.show();
delay(50);
}
}
void loop() {
trellis.read(); // interrupt management does all the work! :)
delay(20); //the trellis has a resolution of around 60hz
}
/******************************************/
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return trellis.pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return trellis.pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return trellis.pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
return 0;
}

View File

@@ -0,0 +1,77 @@
/* This example shows basic usage of the NeoTrellis
with the interrupt pin.
The buttons will light up various colors when pressed.
*/
#include "Adafruit_NeoTrellis.h"
Adafruit_NeoTrellis trellis;
#define INT_PIN 10
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return trellis.pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return trellis.pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return trellis.pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
//define a callback for key presses
TrellisCallback blink(keyEvent evt){
if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING)
trellis.pixels.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, trellis.pixels.numPixels(), 0, 255))); //on rising
else if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING)
trellis.pixels.setPixelColor(evt.bit.NUM, 0); //off falling
trellis.pixels.show();
return 0;
}
void setup() {
Serial.begin(9600);
//while(!Serial);
pinMode(INT_PIN, INPUT);
if(!trellis.begin()){
Serial.println("could not start trellis");
while(1);
}
else{
Serial.println("trellis started");
}
//activate all keys and set callbacks
for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
trellis.activateKey(i, SEESAW_KEYPAD_EDGE_FALLING);
trellis.registerCallback(i, blink);
}
//do a little animation to show we're on
for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
trellis.pixels.setPixelColor(i, Wheel(map(i, 0, trellis.pixels.numPixels(), 0, 255)));
trellis.pixels.show();
delay(50);
}
for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
trellis.pixels.setPixelColor(i, 0x000000);
trellis.pixels.show();
delay(50);
}
}
void loop() {
if(!digitalRead(INT_PIN)){
trellis.read(false);
}
delay(2);
}

View File

@@ -0,0 +1,102 @@
/* This example shows basic usage of the
MultiTrellis object controlling an array of
NeoTrellis boards
As is this example shows use of two NeoTrellis boards
connected together with the leftmost board having the
default I2C address of 0x2E, and the rightmost board
having the address of 0x2F (the A0 jumper is soldered)
*/
#include "Adafruit_NeoTrellis.h"
#define Y_DIM 4 //number of rows of key
#define X_DIM 8 //number of columns of keys
//create a matrix of trellis panels
Adafruit_NeoTrellis t_array[Y_DIM/4][X_DIM/4] = {
{ Adafruit_NeoTrellis(0x2E), Adafruit_NeoTrellis(0x2F) }
};
/*
If you were using a 2x2 array of NeoTrellis boards, the above lines would be:
#define Y_DIM 8 //number of rows of key
#define X_DIM 8 //number of columns of keys
//create a matrix of trellis panels
Adafruit_NeoTrellis t_array[Y_DIM/4][X_DIM/4] = {
{ Adafruit_NeoTrellis(0x2E), Adafruit_NeoTrellis(0x2F) },
{ Adafruit_NeoTrellis(LOWER_LEFT_I2C_ADDR), Adafruit_NeoTrellis(LOWER_RIGHT_I2C_ADDR) }
};
*/
//pass this matrix to the multitrellis object
Adafruit_MultiTrellis trellis((Adafruit_NeoTrellis *)t_array, Y_DIM/4, X_DIM/4);
// Input a value 0 to 255 to get a color value.
// The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
return 0;
}
//define a callback for key presses
TrellisCallback blink(keyEvent evt){
if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_RISING)
trellis.setPixelColor(evt.bit.NUM, Wheel(map(evt.bit.NUM, 0, X_DIM*Y_DIM, 0, 255))); //on rising
else if(evt.bit.EDGE == SEESAW_KEYPAD_EDGE_FALLING)
trellis.setPixelColor(evt.bit.NUM, 0); //off falling
trellis.show();
return 0;
}
void setup() {
Serial.begin(9600);
//while(!Serial);
if(!trellis.begin()){
Serial.println("failed to begin trellis");
while(1);
}
/* the array can be addressed as x,y or with the key number */
for(int i=0; i<Y_DIM*X_DIM; i++){
trellis.setPixelColor(i, Wheel(map(i, 0, X_DIM*Y_DIM, 0, 255))); //addressed with keynum
trellis.show();
delay(50);
}
for(int y=0; y<Y_DIM; y++){
for(int x=0; x<X_DIM; x++){
//activate rising and falling edges on all keys
trellis.activateKey(x, y, SEESAW_KEYPAD_EDGE_RISING, true);
trellis.activateKey(x, y, SEESAW_KEYPAD_EDGE_FALLING, true);
trellis.registerCallback(x, y, blink);
trellis.setPixelColor(x, y, 0x000000); //addressed with x,y
trellis.show(); //show all LEDs
delay(50);
}
}
}
void loop() {
trellis.read();
delay(20);
}

View File

@@ -0,0 +1,180 @@
/* This example shows a more complex LED pattern
using a NeoTrellis board.
Note that due to memory requirements this example
will not work on boards with very limited memory such
as the Adafruit Metro (with ATMega328p)
*/
#include "Adafruit_NeoTrellis.h"
Adafruit_NeoTrellis trellis;
#define MAX_RIPPLES 16
#define FALLOFF_TIME 30
#define FALLOFF (0xFF/FALLOFF_TIME)
#define NUM_POINTS 8
#define RIPPLE_RATE .4
#define INT_PIN 10
#define MATRIX_POINT(x,y) ((y)*4+(x))
uint32_t colors[] = {
0xFF0000, 0x00FF00, 0x0000FF,
0xFF00FF, 0x00FFFF, 0xFFFFFF
};
union color {
struct {
uint8_t blue:8;
uint8_t green:8;
uint8_t red:8;
} bit;
uint32_t reg;
};
color matrix[4][4];
struct point {
float x;
float y;
};
struct ripple {
int8_t center;
uint32_t t;
color c;
point points[NUM_POINTS];
};
static struct ripple ripples[MAX_RIPPLES];
//define a callback for key presses
TrellisCallback blink(keyEvent evt){
for(int i=0; i<MAX_RIPPLES; i++){
if(ripples[i].center == -1){
//create a new ripple here
ripples[i].center = evt.bit.NUM;
ripples[i].t = 0;
for(int j=0; j<NUM_POINTS; j++){
ripples[i].points[j].x = NEO_TRELLIS_X(evt.bit.NUM);
ripples[i].points[j].y = NEO_TRELLIS_Y(evt.bit.NUM);
}
ripples[i].c.reg = colors[random(sizeof(colors)/sizeof(uint32_t))];
break;
}
}
return 0;
}
void setup() {
Serial.begin(9600);
//while(!Serial);
pinMode(INT_PIN, INPUT);
randomSeed(analogRead(0));
if(!trellis.begin()){
Serial.println("could not start trellis");
while(1);
}
else{
Serial.println("trellis started");
}
for(int i=0; i<MAX_RIPPLES; i++)
ripples[i].center = -1;
//activate all keys and set callbacks
for(int i=0; i<NEO_TRELLIS_NUM_KEYS; i++){
trellis.activateKey(i, SEESAW_KEYPAD_EDGE_RISING);
trellis.registerCallback(i, blink);
}
//do a little animation to show we're on
for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
trellis.pixels.setPixelColor(i, 0x0000FF);
trellis.pixels.show();
delay(50);
}
for(uint16_t i=0; i<trellis.pixels.numPixels(); i++) {
trellis.pixels.setPixelColor(i, 0x000000);
trellis.pixels.show();
delay(50);
}
}
void processRipples(){
for(int x=0; x<4; x++){
for(int y=0; y<4; y++)
matrix[x][y].reg = 0;
}
bool update = false;
for(int i=0; i<MAX_RIPPLES; i++){
if(ripples[i].center > -1){
update = true;
//push all points out from the center
point *p = ripples[i].points;
p[0].x += RIPPLE_RATE;
p[1].x += RIPPLE_RATE/2;
p[1].y += RIPPLE_RATE/2;
p[2].y += RIPPLE_RATE;
p[3].x -= RIPPLE_RATE/2;
p[3].y += RIPPLE_RATE/2;
p[4].x -= RIPPLE_RATE;
p[5].x -= RIPPLE_RATE/2;
p[5].y -= RIPPLE_RATE/2;
p[6].y -= RIPPLE_RATE;
p[7].x += RIPPLE_RATE/2;
p[7].y -= RIPPLE_RATE/2;
for(int j=0; j<NUM_POINTS; j++){
int x = round(p[j].x);
int y = round(p[j].y);
if(x < 4 && x >= 0 && y < 4 && y >= 0){
byte red = min(255, matrix[x][y].bit.red + ripples[i].c.bit.red);
byte green = min(255, matrix[x][y].bit.green + ripples[i].c.bit.green);
byte blue = min(255, matrix[x][y].bit.blue + ripples[i].c.bit.blue);
matrix[x][y].bit.red = red;
matrix[x][y].bit.green = green;
matrix[x][y].bit.blue = blue;
}
}
ripples[i].t++;
if(ripples[i].t >= FALLOFF_TIME) ripples[i].center = -1;
}
}
if(update){
for(int x=0; x<4; x++){
for(int y=0; y<4; y++)
trellis.pixels.setPixelColor(MATRIX_POINT(x,y), matrix[x][y].reg);
}
trellis.pixels.show();
}
}
void loop() {
if(!digitalRead(INT_PIN)){
trellis.read(false);
}
processRipples();
delay(20);
}

View File

@@ -0,0 +1,44 @@
/*
Fade
This example shows how to fade an LED on pin 6 of a seesaw board using the analogWrite()
function.
The analogWrite() function uses PWM, so if you want to change the pin you're
using, be sure to use another PWM capable pin. On the SAMD09 breakout these are pins 5, 6, and 7
*/
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
int led = 6; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
ss.analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

View File

@@ -0,0 +1,24 @@
/*
* This example shows how read the ADC on a seesaw. The default ADC pins on the SAMD09 Breakout are 2, 3, and 4.
*/
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
void setup() {
Serial.begin(9600);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
}
void loop() {
Serial.print(ss.analogRead(2));
Serial.print(",");
Serial.println(ss.analogRead(3));
delay(50);
}

View File

@@ -0,0 +1,31 @@
//This example takes UART data given to the seesaw, reads it and then loops it back
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
void setup()
{
Serial.begin(9600);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
//enable interrupt
ss.enableSercomDataRdyInterrupt();
}
void loop()
{
if(!digitalRead(3)){
char c = ss.readSercomData();
Serial.print(c); //print to arduino console
//delay after reading data
delayMicroseconds(100);
ss.print(c); //send back to the seesaw to print
}
}

View File

@@ -0,0 +1,28 @@
/*
* This example shows how to blink a pin on a seesaw.
* Attach the positive (longer lead) of the LED to pin 15 on the seesaw, and
* the negative lead of the LED to ground through a 1k ohm resistor.
*/
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
void setup() {
Serial.begin(115200);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
ss.pinMode(15, OUTPUT);
}
void loop() {
ss.digitalWrite(15, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
ss.digitalWrite(15, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}

View File

@@ -0,0 +1,35 @@
/*
* This example shows how set GPIO interrupts on a seesaw.
*/
#include "Adafruit_seesaw.h"
//connect the interrupt pin on the seesaw (pin 8 on samd09 breakout) to this pin on your arduino
#define INT_PIN 3
//the interrupt will fire when this pin on the seesaw changes state
#define SCAN_PIN 9
Adafruit_seesaw ss;
uint32_t mask = ((uint32_t)0b1 << SCAN_PIN);
void setup() {
Serial.begin(9600);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
ss.pinModeBulk(mask, INPUT_PULLUP);
ss.setGPIOInterrupts(mask, 1);
}
void loop() {
if(!digitalRead(INT_PIN)){
Serial.print("interrupt fired! pin state: ");
Serial.println(ss.digitalRead(SCAN_PIN));
}
}

View File

@@ -0,0 +1,30 @@
/*
* This example shows how to blink multiple pins at once on a seesaw.
* pin 13 is attached to the LED on the samd11 xplained board
*/
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
//blink pins PA11, PA12, PA13
uint32_t mask = ((uint32_t)0b111 << 11);
void setup() {
Serial.begin(9600);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
ss.pinModeBulk(mask, OUTPUT); //set pin modes
}
void loop() {
ss.digitalWriteBulk(mask, HIGH); //set pins
delay(1000); // wait for a second
ss.digitalWriteBulk(mask, LOW); //clear pins
delay(1000);
}

View File

@@ -0,0 +1,27 @@
/*
* This example shows how to read multiple pins at once on a seesaw.
*/
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
//read pins A8, A9, A10
uint32_t mask = ((uint32_t)0b111 << 8);
void setup() {
Serial.begin(9600);
if(!ss.begin()){
Serial.println("ERROR!");
while(1);
}
else Serial.println("seesaw started");
ss.pinModeBulk(mask, INPUT);
}
void loop() {
Serial.println(ss.digitalReadBulk(mask), BIN);
delay(500);
}

View File

@@ -0,0 +1,91 @@
/*
* This example shows how to read from a seesaw encoder module.
* The available encoder API is:
* int32_t getEncoderPosition();
int32_t getEncoderDelta();
void enableEncoderInterrupt();
void disableEncoderInterrupt();
void setEncoderPosition(int32_t pos);
*/
#include "Adafruit_seesaw.h"
#include <seesaw_neopixel.h>
#define SS_SWITCH 24
#define SS_NEOPIX 6
#define SEESAW_ADDR 0x36
Adafruit_seesaw ss;
seesaw_NeoPixel sspixel = seesaw_NeoPixel(1, SS_NEOPIX, NEO_GRB + NEO_KHZ800);
int32_t encoder_position;
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Looking for seesaw!");
if (! ss.begin(SEESAW_ADDR) || ! sspixel.begin(SEESAW_ADDR)) {
Serial.println("Couldn't find seesaw on default address");
while(1) delay(10);
}
Serial.println("seesaw started");
uint32_t version = ((ss.getVersion() >> 16) & 0xFFFF);
if (version != 4991){
Serial.print("Wrong firmware loaded? ");
Serial.println(version);
while(1) delay(10);
}
Serial.println("Found Product 4991");
// set not so bright!
sspixel.setBrightness(20);
sspixel.show();
// use a pin for the built in encoder switch
ss.pinMode(SS_SWITCH, INPUT_PULLUP);
// get starting position
encoder_position = ss.getEncoderPosition();
Serial.println("Turning on interrupts");
delay(10);
ss.setGPIOInterrupts((uint32_t)1 << SS_SWITCH, 1);
ss.enableEncoderInterrupt();
}
void loop() {
if (! ss.digitalRead(SS_SWITCH)) {
Serial.println("Button pressed!");
}
int32_t new_position = ss.getEncoderPosition();
// did we move arounde?
if (encoder_position != new_position) {
Serial.println(new_position); // display new position
// change the neopixel color
sspixel.setPixelColor(0, Wheel(new_position & 0xFF));
sspixel.show();
encoder_position = new_position; // and save for next round
}
// don't overwhelm serial port
delay(10);
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return sspixel.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return sspixel.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return sspixel.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

View File

@@ -0,0 +1,161 @@
/* Demo with 128x64 OLED display and multiple I2C encoders wired up. The sketch will auto-
* detect up to 4 encoder on the first 4 addresses. Twisting will display text on OLED
* and change neopixel color.
* set USE_OLED to true t
*/
#define USE_OLED false // set to false to skip the OLED, true to use it!
#include "Adafruit_seesaw.h"
#include <seesaw_neopixel.h>
#if USE_OLED
#include <Adafruit_SH110X.h>
#include <Fonts/FreeSans9pt7b.h>
Adafruit_SH110X display = Adafruit_SH110X(64, 128, &Wire);
#endif
#define SS_SWITCH 24 // this is the pin on the encoder connected to switch
#define SS_NEOPIX 6 // this is the pin on the encoder connected to neopixel
#define SEESAW_BASE_ADDR 0x36 // I2C address, starts with 0x36
// create 4 encoders!
Adafruit_seesaw encoders[4];
// create 4 encoder pixels
seesaw_NeoPixel encoder_pixels[4] = {
seesaw_NeoPixel(1, SS_NEOPIX, NEO_GRB + NEO_KHZ800),
seesaw_NeoPixel(1, SS_NEOPIX, NEO_GRB + NEO_KHZ800),
seesaw_NeoPixel(1, SS_NEOPIX, NEO_GRB + NEO_KHZ800),
seesaw_NeoPixel(1, SS_NEOPIX, NEO_GRB + NEO_KHZ800)};
int32_t encoder_positions[] = {0, 0, 0, 0};
bool found_encoders[] = {false, false, false, false};
void setup() {
Serial.begin(115200);
// wait for serial port to open
while (!Serial) delay(10);
Serial.println("128x64 OLED + seesaw Encoders test");
#if USE_OLED
display.begin(0x3C, true); // Address 0x3C default
Serial.println("OLED begun");
display.display();
delay(500); // Pause for half second
display.setRotation(1);
display.setFont(&FreeSans9pt7b);
display.setTextColor(SH110X_WHITE);
#endif
Serial.println("Looking for seesaws!");
for (uint8_t enc=0; enc<sizeof(found_encoders); enc++) {
// See if we can find encoders on this address
if (! encoders[enc].begin(SEESAW_BASE_ADDR + enc) ||
! encoder_pixels[enc].begin(SEESAW_BASE_ADDR + enc)) {
Serial.print("Couldn't find encoder #");
Serial.println(enc);
} else {
Serial.print("Found encoder + pixel #");
Serial.println(enc);
uint32_t version = ((encoders[enc].getVersion() >> 16) & 0xFFFF);
if (version != 4991){
Serial.print("Wrong firmware loaded? ");
Serial.println(version);
while(1) delay(10);
}
Serial.println("Found Product 4991");
// use a pin for the built in encoder switch
encoders[enc].pinMode(SS_SWITCH, INPUT_PULLUP);
// get starting position
encoder_positions[enc] = encoders[enc].getEncoderPosition();
Serial.println("Turning on interrupts");
delay(10);
encoders[enc].setGPIOInterrupts((uint32_t)1 << SS_SWITCH, 1);
encoders[enc].enableEncoderInterrupt();
// set not so bright!
encoder_pixels[enc].setBrightness(30);
encoder_pixels[enc].show();
found_encoders[enc] = true;
}
}
Serial.println("Encoders started");
}
void loop() {
#if USE_OLED
display.clearDisplay();
#endif
uint16_t display_line = 1;
for (uint8_t enc=0; enc<sizeof(found_encoders); enc++) {
if (found_encoders[enc] == false) continue;
int32_t new_position = encoders[enc].getEncoderPosition();
// did we move around?
if (encoder_positions[enc] != new_position) {
Serial.print("Encoder #");
Serial.print(enc);
Serial.print(" -> ");
Serial.println(new_position); // display new position
encoder_positions[enc] = new_position;
// change the neopixel color, mulitply the new positiion by 4 to speed it up
encoder_pixels[enc].setPixelColor(0, Wheel((new_position*4) & 0xFF));
encoder_pixels[enc].show();
}
#if USE_OLED
// draw the display
display.setCursor(0, 20*display_line++);
display.print("Enc #");
display.print(enc);
display.print(" : ");
display.print(encoder_positions[enc]);
#endif
if (! encoders[enc].digitalRead(SS_SWITCH)) {
Serial.print("Encoder #");
Serial.print(enc);
Serial.println(" pressed");
#if USE_OLED
display.print(" P");
#endif
}
}
#if USE_OLED
display.display();
#endif
// don't overwhelm serial port
yield();
delay(10);
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return seesaw_NeoPixel::Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return seesaw_NeoPixel::Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return seesaw_NeoPixel::Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

View File

@@ -0,0 +1,86 @@
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
#define BUTTON_RIGHT 6
#define BUTTON_DOWN 7
#define BUTTON_LEFT 9
#define BUTTON_UP 10
#define BUTTON_SEL 14
uint32_t button_mask = (1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) |
(1 << BUTTON_LEFT) | (1 << BUTTON_UP) | (1 << BUTTON_SEL);
#if defined(ESP8266)
#define IRQ_PIN 2
#elif defined(ESP32)
#define IRQ_PIN 14
#elif defined(ARDUINO_NRF52832_FEATHER)
#define IRQ_PIN 27
#elif defined(TEENSYDUINO)
#define IRQ_PIN 8
#elif defined(ARDUINO_ARCH_WICED)
#define IRQ_PIN PC5
#else
#define IRQ_PIN 5
#endif
void setup() {
Serial.begin(115200);
while(!Serial) {
delay(10);
}
Serial.println("Joy FeatherWing example!");
if(!ss.begin(0x49)){
Serial.println("ERROR! seesaw not found");
while(1);
} else {
Serial.println("seesaw started");
Serial.print("version: ");
Serial.println(ss.getVersion(), HEX);
}
ss.pinModeBulk(button_mask, INPUT_PULLUP);
ss.setGPIOInterrupts(button_mask, 1);
pinMode(IRQ_PIN, INPUT);
}
int last_x = 0, last_y = 0;
void loop() {
int x = ss.analogRead(2);
int y = ss.analogRead(3);
if ( (abs(x - last_x) > 3) || (abs(y - last_y) > 3)) {
Serial.print(x); Serial.print(", "); Serial.println(y);
last_x = x;
last_y = y;
}
/* if(!digitalRead(IRQ_PIN)) { // Uncomment to use IRQ */
uint32_t buttons = ss.digitalReadBulk(button_mask);
//Serial.println(buttons, BIN);
if (! (buttons & (1 << BUTTON_RIGHT))) {
Serial.println("Button A pressed");
}
if (! (buttons & (1 << BUTTON_DOWN))) {
Serial.println("Button B pressed");
}
if (! (buttons & (1 << BUTTON_LEFT))) {
Serial.println("Button Y pressed");
}
if (! (buttons & (1 << BUTTON_UP))) {
Serial.println("Button X pressed");
}
if (! (buttons & (1 << BUTTON_SEL))) {
Serial.println("Button SEL pressed");
}
/* } // Uncomment to use IRQ */
delay(10);
}

View File

@@ -0,0 +1,149 @@
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
#define BUTTON_RIGHT 6
#define BUTTON_DOWN 7
#define BUTTON_LEFT 9
#define BUTTON_UP 10
#define BUTTON_START 14
uint32_t button_mask = (1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) |
(1 << BUTTON_LEFT) | (1 << BUTTON_UP) | (1 << BUTTON_START);
#if defined(ESP8266)
#define IRQ_PIN 2
#elif defined(ESP32)
#define IRQ_PIN 14
#elif defined(ARDUINO_NRF52832_FEATHER)
#define IRQ_PIN 27
#elif defined(TEENSYDUINO)
#define IRQ_PIN 8
#elif defined(ARDUINO_ARCH_WICED)
#define IRQ_PIN PC5
#else
#define IRQ_PIN 5
#endif
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT_CS 6
#define TFT_DC 10
#define TFT_RST 9 // you can also connect this to the Arduino reset
// in which case, set this #define pin to -1!
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
void setup() {
//while (!Serial);
Serial.begin(115200);
if(!ss.begin(0x49)){
Serial.println("ERROR!");
while(1);
}
else{
Serial.println("seesaw started");
Serial.print("version: ");
Serial.println(ss.getVersion(), HEX);
}
ss.pinModeBulk(button_mask, INPUT_PULLUP);
ss.setGPIOInterrupts(button_mask, 1);
pinMode(IRQ_PIN, INPUT);
Serial.println(F("TFT TIME"));
tft.initR(INITR_MINI160x80); // initialize a ST7735S chip, mini display
Serial.println("Initialized");
tft.setRotation(1);
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
time = millis() - time;
Serial.println(time, DEC);
delay(500);
// large block of text
tft.fillScreen(ST7735_BLACK);
}
int last_x = 0, last_y = 0;
void loop() {
int y = ss.analogRead(2);
int x = ss.analogRead(3);
if(x > 600 && last_x < 600){
tft.fillTriangle(120, 30, 120, 50, 110, 40, ST7735_WHITE);
Serial.println(F("LEFT"));
}
else if(last_x > 600 && x < 600){
tft.fillTriangle(120, 30, 120, 50, 110, 40, ST7735_BLACK);
}
if(x < 400 && last_x > 400){
tft.fillTriangle(150, 30, 150, 50, 160, 40, ST7735_WHITE);
Serial.println(F("RIGHT"));
}
else if(last_x < 400 && x > 400){
tft.fillTriangle(150, 30, 150, 50, 160, 40, ST7735_BLACK);
}
if(y > 600 && last_y < 600){
tft.fillTriangle(125, 26, 145, 26, 135, 16, ST7735_WHITE);
Serial.println(F("DOWN"));
}
else if(last_y > 600 && y < 600){
tft.fillTriangle(125, 26, 145, 26, 135, 16, ST7735_BLACK);
}
if(y < 400 && last_y > 400){
tft.fillTriangle(125, 53, 145, 53, 135, 63, ST7735_WHITE);
Serial.println(F("UP"));
}
else if(last_y < 400 && y > 400){
tft.fillTriangle(125, 53, 145, 53, 135, 63, ST7735_BLACK);
}
if ( (abs(x - last_x) > 3) || (abs(y - last_y) > 3)) {
Serial.print(x); Serial.print(", "); Serial.println(y);
last_x = x;
last_y = y;
}
if(!digitalRead(IRQ_PIN)){
uint32_t buttons = ss.digitalReadBulk(button_mask);
//Serial.println(buttons, BIN);
if (! (buttons & (1 << BUTTON_DOWN))) {
tft.fillCircle(30, 18, 10, ST7735_GREEN);
Serial.println("B");
}
else tft.fillCircle(30, 18, 10, ST7735_BLACK);
if (! (buttons & (1 << BUTTON_RIGHT))) {
tft.fillCircle(10, 40, 10, ST7735_RED);
Serial.println("A");
}
else tft.fillCircle(10, 40, 10, ST7735_BLACK);
if (! (buttons & (1 << BUTTON_LEFT))) {
tft.fillCircle(50, 40, 10, ST7735_BLUE);
Serial.println("Y");
}
else tft.fillCircle(50, 40, 10, ST7735_BLACK);
if (! (buttons & (1 << BUTTON_UP))) {
tft.fillCircle(30, 57, 10, ST7735_YELLOW);
Serial.println("X");
}
else tft.fillCircle(30, 57, 10, ST7735_BLACK);
if (! (buttons & (1 << BUTTON_START))) {
tft.fillCircle(80, 40, 7, ST7735_WHITE);
Serial.println(F("START"));
}
else tft.fillCircle(80, 40, 7, ST7735_BLACK);
}
delay(10);
}

View File

@@ -0,0 +1,26 @@
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
void setup() {
Serial.begin(115200);
Serial.println("seesaw Soil Sensor example!");
if (!ss.begin(0x36)) {
Serial.println("ERROR! seesaw not found");
while(1);
} else {
Serial.print("seesaw started! version: ");
Serial.println(ss.getVersion(), HEX);
}
}
void loop() {
float tempC = ss.getTemp();
uint16_t capread = ss.touchRead(0);
Serial.print("Temperature: "); Serial.print(tempC); Serial.println("*C");
Serial.print("Capacitive: "); Serial.println(capread);
delay(100);
}