初始化提交

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,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);
}