initial version
This commit is contained in:
parent
ce1b800f37
commit
a8a7222e03
14 changed files with 718 additions and 0 deletions
5
VSCode/Matrix/Ping Pong/.gitignore
vendored
Executable file
5
VSCode/Matrix/Ping Pong/.gitignore
vendored
Executable file
|
@ -0,0 +1,5 @@
|
|||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
7
VSCode/Matrix/Ping Pong/.vscode/extensions.json
vendored
Executable file
7
VSCode/Matrix/Ping Pong/.vscode/extensions.json
vendored
Executable file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
39
VSCode/Matrix/Ping Pong/include/README
Executable file
39
VSCode/Matrix/Ping Pong/include/README
Executable file
|
@ -0,0 +1,39 @@
|
|||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
46
VSCode/Matrix/Ping Pong/lib/README
Executable file
46
VSCode/Matrix/Ping Pong/lib/README
Executable file
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
18
VSCode/Matrix/Ping Pong/platformio.ini
Executable file
18
VSCode/Matrix/Ping Pong/platformio.ini
Executable file
|
@ -0,0 +1,18 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:nanoatmega328new]
|
||||
platform = atmelavr
|
||||
board = nanoatmega328
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
adafruit/Adafruit NeoMatrix@^1.2.0
|
||||
adafruit/Adafruit NeoPixel@^1.10.4
|
||||
adafruit/Adafruit WS2801 Library@^1.1.1
|
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);
|
||||
}
|
||||
|
11
VSCode/Matrix/Ping Pong/test/README
Executable file
11
VSCode/Matrix/Ping Pong/test/README
Executable file
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
Loading…
Add table
Add a link
Reference in a new issue