initial version
This commit is contained in:
parent
ce1b800f37
commit
a8a7222e03
14 changed files with 718 additions and 0 deletions
167
VSCode/Matrix/Ping Pong/src/main.cpp
Executable file
167
VSCode/Matrix/Ping Pong/src/main.cpp
Executable file
|
@ -0,0 +1,167 @@
|
|||
#include "SPI.h"
|
||||
#include "Adafruit_WS2801.h"
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
/*****************************************************************************
|
||||
Example sketch for driving Adafruit WS2801 pixels!
|
||||
|
||||
|
||||
Designed specifically to work with the Adafruit RGB Pixels!
|
||||
12mm Bullet shape ----> https://www.adafruit.com/products/322
|
||||
12mm Flat shape ----> https://www.adafruit.com/products/738
|
||||
36mm Square shape ----> https://www.adafruit.com/products/683
|
||||
|
||||
These pixels use SPI to transmit the color data, and have built in
|
||||
high speed PWM drivers for 24 bit color per pixel
|
||||
2 pins are required to interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by David Kavanagh (dkavanagh@gmail.com).
|
||||
BSD license, all text above must be included in any redistribution
|
||||
|
||||
*****************************************************************************/
|
||||
|
||||
// Choose which 2 pins you will use for output.
|
||||
// Can be any valid output pins.
|
||||
// The colors of the wires may be totally different so
|
||||
// BE SURE TO CHECK YOUR PIXELS TO SEE WHICH WIRES TO USE!
|
||||
uint8_t dataPin = 6; // Yellow wire on Adafruit Pixels
|
||||
uint8_t clockPin = 3; // Green wire on Adafruit Pixels
|
||||
|
||||
// Don't forget to connect the ground wire to Arduino ground,
|
||||
// and the +5V wire to a +5V supply
|
||||
|
||||
// Set the first variable to the NUMBER of pixels in a row and
|
||||
// the second value to number of pixels in a column.
|
||||
Adafruit_WS2801 strip = Adafruit_WS2801((uint16_t)200, dataPin, clockPin);
|
||||
|
||||
|
||||
/* Helper functions */
|
||||
|
||||
// Create a 24 bit color value from R,G,B
|
||||
uint32_t Color(byte r, byte g, byte b)
|
||||
{
|
||||
uint32_t c;
|
||||
c = r;
|
||||
c <<= 8;
|
||||
c |= g;
|
||||
c <<= 8;
|
||||
c |= b;
|
||||
return c;
|
||||
}
|
||||
|
||||
uint32_t Wheel(byte WheelPos)
|
||||
{
|
||||
if (WheelPos < 85) {
|
||||
return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
} else if (WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
return Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
} else {
|
||||
WheelPos -= 170;
|
||||
return Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawX(uint8_t w, uint8_t h, uint8_t wait) {
|
||||
uint16_t x, y;
|
||||
for (x=0; x<w; x++) {
|
||||
strip.setPixelColor(x, x, 255, 0, 0);
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
for (y=0; y<h; y++) {
|
||||
strip.setPixelColor(w-1-y, y, 0, 0, 255);
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void bounce(uint8_t w, uint8_t h, uint8_t wait) {
|
||||
int16_t x = 1;
|
||||
int16_t y = 2;
|
||||
int8_t xdir = +1;
|
||||
int8_t ydir = -1;
|
||||
int j;
|
||||
for (j=0; j < 256; j++) {
|
||||
x = x + xdir;
|
||||
y = y + ydir;
|
||||
if (x < 0) {
|
||||
x = -x;
|
||||
xdir = - xdir;
|
||||
}
|
||||
if (y < 0) {
|
||||
y = -y;
|
||||
ydir = - ydir;
|
||||
}
|
||||
if (x == w) {
|
||||
x = w-2;
|
||||
xdir = - xdir;
|
||||
}
|
||||
if (y == h) {
|
||||
y = h-2;
|
||||
ydir = - ydir;
|
||||
}
|
||||
strip.setPixelColor(x, y, Wheel(j));
|
||||
strip.show();
|
||||
delay(wait);
|
||||
strip.setPixelColor(x, y, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Input a value 0 to 255 to get a color value.
|
||||
//The colours are a transition r - g -b - back to r
|
||||
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
strip.begin();
|
||||
|
||||
// Update LED contents, to start they are all 'off'
|
||||
strip.show();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// Some example procedures showing how to display to the pixels
|
||||
//drawX(10, 20, 100);
|
||||
//bounce(10, 20, 50);
|
||||
for(uint8_t i; i<200; i++)
|
||||
{
|
||||
|
||||
strip.setPixelColor(i,255,0,0);
|
||||
}
|
||||
strip.show();
|
||||
delay(5000);
|
||||
for(uint8_t i; i<200; i++)
|
||||
{
|
||||
|
||||
strip.setPixelColor(i,0,255,0);
|
||||
}
|
||||
strip.show();
|
||||
delay(5000);
|
||||
|
||||
for(uint8_t i; i<200; i++)
|
||||
{
|
||||
|
||||
strip.setPixelColor(i,0,0,255);
|
||||
}
|
||||
strip.show();
|
||||
delay(5000);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue