forked from Michel2/LoLshield
Move example programs into lib/examples, to make packaging easier.
This commit is contained in:
@@ -1 +0,0 @@
|
||||
../lib/Charliplexing.cpp
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Charliplexing.h
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Font.cpp
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Font.h
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Charliplexing.cpp
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Charliplexing.h
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Figure.cpp
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Figure.h
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
Basic LoL Shield Test
|
||||
|
||||
Writen for the LoL Shield, designed by Jimmie Rodgers:
|
||||
http://jimmieprodgers.com/kits/lolshield/
|
||||
|
||||
This needs the Charliplexing library, which you can get at the
|
||||
LoL Shield project page: http://code.google.com/p/lolshield/
|
||||
|
||||
Created by Jimmie Rodgers on 12/30/2009.
|
||||
Adapted from: http://www.arduino.cc/playground/Code/BitMath
|
||||
|
||||
History:
|
||||
December 30, 2009 - V1.0 first version written at 26C3/Berlin
|
||||
|
||||
This is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Version 3 General Public
|
||||
License as published by the Free Software Foundation;
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <avr/pgmspace.h> //AVR library for writing to ROM
|
||||
#include <Charliplexing.h> //Imports the library, which needs to be
|
||||
//Initialized in setup.
|
||||
|
||||
int blinkdelay = 100; //Sets the time each frame is shown
|
||||
|
||||
/*
|
||||
The BitMap array is what contains the frame data. Each line is one full frame.
|
||||
Since each number is 16 bits, we can easily fit all 14 LEDs per row into it.
|
||||
The number is calculated by adding up all the bits, starting with lowest on
|
||||
the left of each row. 18000 was chosen as the kill number, so make sure that
|
||||
is at the end of the matrix, or the program will continue to read into memory.
|
||||
|
||||
Here PROGMEM is called, which stores the array into ROM, which leaves us
|
||||
with our RAM. You cannot change the array during run-time, only when you
|
||||
upload to the Arduino. You will need to pull it out of ROM, which is covered
|
||||
below. If you want it to stay in RAM, just delete PROGMEM
|
||||
*/
|
||||
uint16_t BitMap[][9] PROGMEM = {
|
||||
//Diaganal swipe across the screen
|
||||
{1, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{3, 1, 0, 0, 0, 0, 0, 0, 0},
|
||||
{7, 3, 1, 0, 0, 0, 0, 0, 0},
|
||||
{15, 7, 3, 1, 0, 0, 0, 0, 0},
|
||||
{31, 15, 7, 3, 1, 0, 0, 0, 0},
|
||||
{63, 31, 15, 7, 3, 1, 0, 0, 0},
|
||||
{127, 63, 31, 15, 7, 3, 1, 0, 0},
|
||||
{255, 127, 63, 31, 15, 7, 3, 1, 0},
|
||||
{511, 255, 127, 63, 31, 15, 7, 3, 1},
|
||||
{1023, 511, 255, 127, 63, 31, 15, 7, 3},
|
||||
{2047, 1023, 511, 255, 127, 63, 31, 15, 7},
|
||||
{4095, 2047, 1023, 511, 255, 127, 63, 31, 15},
|
||||
{8191, 4095, 2047, 1023, 511, 255, 127, 63, 31},
|
||||
{16383, 8191, 4095, 2047, 1023, 511, 255, 127, 63},
|
||||
{16383, 16383, 8191, 4095, 2047, 1023, 511, 255, 127},
|
||||
{16383, 16383, 16383, 8191, 4095, 2047, 1023, 511, 255},
|
||||
{16383, 16383, 16383, 16383, 8191, 4095, 2047, 1023, 511},
|
||||
{16383, 16383, 16383, 16383, 16383, 8191, 4095, 2047, 1023},
|
||||
{16383, 16383, 16383, 16383, 16383, 16383, 8191, 4095, 2047},
|
||||
{16383, 16383, 16383, 16383, 16383, 16383, 16383, 8191, 4095},
|
||||
{16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383, 8191},
|
||||
{16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383},
|
||||
{16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383},
|
||||
{16382, 16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383},
|
||||
{16380, 16382, 16383, 16383, 16383, 16383, 16383, 16383, 16383},
|
||||
{16376, 16380, 16382, 16383, 16383, 16383, 16383, 16383, 16383},
|
||||
{16368, 16376, 16380, 16382, 16383, 16383, 16383, 16383, 16383},
|
||||
{16352, 16368, 16376, 16380, 16382, 16383, 16383, 16383, 16383},
|
||||
{16320, 16352, 16368, 16376, 16380, 16382, 16383, 16383, 16383},
|
||||
{16256, 16320, 16352, 16368, 16376, 16380, 16382, 16383, 16383},
|
||||
{16128, 16256, 16320, 16352, 16368, 16376, 16380, 16382, 16383},
|
||||
{15872, 16128, 16256, 16320, 16352, 16368, 16376, 16380, 16382},
|
||||
{15360, 15872, 16128, 16256, 16320, 16352, 16368, 16376, 16380},
|
||||
{14336, 15360, 15872, 16128, 16256, 16320, 16352, 16368, 16376},
|
||||
{12288, 14336, 15360, 15872, 16128, 16256, 16320, 16352, 16368},
|
||||
{8192, 12288, 14336, 15360, 15872, 16128, 16256, 16320, 16352},
|
||||
{0, 8192, 12288, 14336, 15360, 15872, 16128, 16256, 16320},
|
||||
{0, 0, 8192, 12288, 14336, 15360, 15872, 16128, 16256},
|
||||
{0, 0, 0, 8192, 12288, 14336, 15360, 15872, 16128},
|
||||
{0, 0, 0, 0, 8192, 12288, 14336, 15360, 15872},
|
||||
{0, 0, 0, 0, 0, 8192, 12288, 14336, 15360},
|
||||
{0, 0, 0, 0, 0, 0, 8192, 12288, 14336},
|
||||
{0, 0, 0, 0, 0, 0, 0, 8192, 12288},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 8192},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
|
||||
//Horizontal swipe
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1} ,
|
||||
{3, 3, 3, 3, 3, 3, 3, 3, 3},
|
||||
{7, 7, 7, 7, 7, 7, 7, 7, 7},
|
||||
{15, 15, 15, 15, 15, 15, 15, 15, 15},
|
||||
{31, 31, 31, 31, 31, 31, 31, 31, 31},
|
||||
{63, 63, 63, 63, 63, 63, 63, 63, 63},
|
||||
{127, 127, 127, 127, 127, 127, 127, 127, 127},
|
||||
{255, 255, 255, 255, 255, 255, 255, 255, 255},
|
||||
{511, 511, 511, 511, 511, 511, 511, 511, 511},
|
||||
{1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023},
|
||||
{2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047},
|
||||
{4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095},
|
||||
{8191, 8191, 8191, 8191, 8191, 8191, 8191, 8191, 8191},
|
||||
{16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383, 16383},
|
||||
{16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382},
|
||||
{16380, 16380, 16380, 16380, 16380, 16380, 16380, 16380, 16380},
|
||||
{16376, 16376, 16376, 16376, 16376, 16376, 16376, 16376, 16376},
|
||||
{16368, 16368, 16368, 16368, 16368, 16368, 16368, 16368, 16368},
|
||||
{16352, 16352, 16352, 16352, 16352, 16352, 16352, 16352, 16352},
|
||||
{16320, 16320, 16320, 16320, 16320, 16320, 16320, 16320, 16320},
|
||||
{16256, 16256, 16256, 16256, 16256, 16256, 16256, 16256, 16256},
|
||||
{16128, 16128, 16128, 16128, 16128, 16128, 16128, 16128, 16128},
|
||||
{15872, 15872, 15872, 15872, 15872, 15872, 15872, 15872, 15872},
|
||||
{15360, 15360, 15360, 15360, 15360, 15360, 15360, 15360, 15360},
|
||||
{14336, 14336, 14336, 14336, 14336, 14336, 14336, 14336, 14336},
|
||||
{12288, 12288, 12288, 12288, 12288, 12288, 12288, 12288, 12288},
|
||||
{8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192, 8192},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{18000}
|
||||
};
|
||||
|
||||
void setup() {
|
||||
LedSign::Init(); //Initializes the screen
|
||||
}
|
||||
void loop() {
|
||||
DisplayBitMap(); //Displays the bitmap
|
||||
}
|
||||
|
||||
void DisplayBitMap()
|
||||
{
|
||||
boolean run=true; //While this is true, the screen updates
|
||||
byte frame = 0; //Frame counter
|
||||
byte line = 0; //Row counter
|
||||
unsigned long data; //Temporary storage of the row data
|
||||
|
||||
while(run == true) {
|
||||
for(line = 0; line < 9; line++) {
|
||||
|
||||
//Here we fetch data from program memory with a pointer.
|
||||
data = pgm_read_word_near (&BitMap[frame][line]);
|
||||
|
||||
//Kills the loop if the kill number is found
|
||||
if (data==18000){
|
||||
run=false;
|
||||
}
|
||||
|
||||
//This is where the bit-shifting happens to pull out
|
||||
//each LED from a row. If the bit is 1, then the LED
|
||||
//is turned on, otherwise it is turned off.
|
||||
else for (byte led=0; led<14; ++led) {
|
||||
if (data & (1<<led)) {
|
||||
LedSign::Set(led, line, 1);
|
||||
}
|
||||
else {
|
||||
LedSign::Set(led, line, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Delays the next update
|
||||
delay(blinkdelay);
|
||||
frame++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
Conway's "Life"
|
||||
|
||||
Writen for the LoL Shield, designed by Jimmie Rodgers:
|
||||
http://jimmieprodgers.com/kits/lolshield/
|
||||
|
||||
This needs the Charliplexing library, which you can get at the
|
||||
LoL Shield project page: http://code.google.com/p/lolshield/
|
||||
|
||||
Created by Jimmie Rodgers on 12/30/2009.
|
||||
Adapted from: http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix
|
||||
|
||||
History:
|
||||
December 30, 2009 - V1.0 first version written at 26C3/Berlin
|
||||
|
||||
This is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Version 3 General Public
|
||||
License as published by the Free Software Foundation;
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <Charliplexing.h> //Imports the library, which needs to be
|
||||
//Initialized in setup.
|
||||
|
||||
#define DELAY 150 //Sets the time each generation is shown
|
||||
#define RESEEDRATE 5000 //Sets the rate the world is re-seeded
|
||||
#define SIZEX 14 //Sets the X axis size
|
||||
#define SIZEY 9 //Sets the Y axis size
|
||||
byte world[SIZEX][SIZEY][2]; //Creates a double buffer world
|
||||
long density = 50; //Sets density % during seeding
|
||||
int geck = 0; //Counter for re-seeding
|
||||
|
||||
void setup() {
|
||||
LedSign::Init(); //Initilizes the LoL Shield
|
||||
randomSeed(analogRead(5));
|
||||
//Builds the world with an initial seed.
|
||||
for (int i = 0; i < SIZEX; i++) {
|
||||
for (int j = 0; j < SIZEY; j++) {
|
||||
if (random(100) < density) {
|
||||
world[i][j][0] = 1;
|
||||
}
|
||||
else {
|
||||
world[i][j][0] = 0;
|
||||
}
|
||||
world[i][j][1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Birth and death cycle
|
||||
for (int x = 0; x < SIZEX; x++) {
|
||||
for (int y = 0; y < SIZEY; y++) {
|
||||
// Default is for cell to stay the same
|
||||
world[x][y][1] = world[x][y][0];
|
||||
int count = neighbours(x, y);
|
||||
geck++;
|
||||
if (count == 3 && world[x][y][0] == 0) {
|
||||
// A new cell is born
|
||||
world[x][y][1] = 1;
|
||||
LedSign::Set(x,y,1);
|
||||
}
|
||||
else if ((count < 2 || count > 3) && world[x][y][0] == 1) {
|
||||
// Cell dies
|
||||
world[x][y][1] = 0;
|
||||
LedSign::Set(x,y,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Counts and then checks for re-seeding
|
||||
//Otherwise the display will die out at some point
|
||||
geck++;
|
||||
if (geck > RESEEDRATE){
|
||||
seedWorld();
|
||||
geck = 0;
|
||||
}
|
||||
|
||||
// Copy next generation into place
|
||||
for (int x = 0; x < SIZEX; x++) {
|
||||
for (int y = 0; y < SIZEY; y++) {
|
||||
world[x][y][0] = world[x][y][1];
|
||||
}
|
||||
}
|
||||
delay(DELAY);
|
||||
}
|
||||
|
||||
//Re-seeds based off of RESEEDRATE
|
||||
void seedWorld(){
|
||||
randomSeed(analogRead(5));
|
||||
for (int i = 0; i < SIZEX; i++) {
|
||||
for (int j = 0; j < SIZEY; j++) {
|
||||
if (random(100) < density) {
|
||||
world[i][j][1] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Runs the rule checks, including screen wrap
|
||||
int neighbours(int x, int y) {
|
||||
return world[(x + 1) % SIZEX][y][0] +
|
||||
world[x][(y + 1) % SIZEY][0] +
|
||||
world[(x + SIZEX - 1) % SIZEX][y][0] +
|
||||
world[x][(y + SIZEY - 1) % SIZEY][0] +
|
||||
world[(x + 1) % SIZEX][(y + 1) % SIZEY][0] +
|
||||
world[(x + SIZEX - 1) % SIZEX][(y + 1) % SIZEY][0] +
|
||||
world[(x + SIZEX - 1) % SIZEX][(y + SIZEY - 1) % SIZEY][0] +
|
||||
world[(x + 1) % SIZEX][(y + SIZEY - 1) % SIZEY][0];
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Example for Charliplexing library
|
||||
|
||||
Alex Wenger <a.wenger@gmx.de> http://arduinobuch.wordpress.com/
|
||||
|
||||
History:
|
||||
30/Dez/09 - V0.0 wrote the first version at 26C3/Berlin
|
||||
|
||||
*/
|
||||
#include "Charliplexing.h"
|
||||
|
||||
struct point {
|
||||
uint8_t xp; // Point Position in X direction (multplied by 16)
|
||||
uint8_t x_speed; // Speed
|
||||
uint8_t flag;
|
||||
} points[9];
|
||||
|
||||
void setup() // run once, when the sketch starts
|
||||
{
|
||||
LedSign::Init();
|
||||
|
||||
for(uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
points[i].xp = 0;
|
||||
points[i].x_speed = random(1, 16);
|
||||
points[i].flag = 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t heart_p[] = {
|
||||
4,5,
|
||||
3,4,
|
||||
2,4,
|
||||
5,4,
|
||||
6,4,
|
||||
7,5,
|
||||
1,5,
|
||||
7,6,
|
||||
1,6,
|
||||
6,7,
|
||||
2,7,
|
||||
5,8,
|
||||
3,8,
|
||||
4,9,
|
||||
};
|
||||
|
||||
void heart()
|
||||
{
|
||||
for(uint8_t y = 0; y < 9; y++)
|
||||
for(uint8_t x = 3; x < 11; x++)
|
||||
{
|
||||
LedSign::Set(x,y,0);
|
||||
}
|
||||
for(uint8_t i = 0; i < 14; i++)
|
||||
{
|
||||
LedSign::Set(heart_p[i*2+1],heart_p[i*2],1);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t heart_flag;
|
||||
|
||||
void loop() // run over and over again
|
||||
{
|
||||
for(uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
points[i].xp += points[i].x_speed;
|
||||
if (points[i].xp >= 14*16)
|
||||
{
|
||||
points[i].x_speed = random(1, 16);
|
||||
points[i].xp = 0;
|
||||
points[i].flag ^= 1;
|
||||
}
|
||||
LedSign::Set(points[i].xp/16,i,points[i].flag);
|
||||
}
|
||||
|
||||
heart_flag++;
|
||||
if (heart_flag < 20) {
|
||||
heart();
|
||||
}
|
||||
|
||||
delay(40);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Charliplexing.cpp
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Charliplexing.h
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Figure.cpp
|
||||
@@ -1 +0,0 @@
|
||||
../lib/Figure.h
|
||||
Reference in New Issue
Block a user