#define joystickX 2
#define joystickY 26
uint16_t x, y, x00, y00;
uint16_t colour;
uint32_t z;
#include "font.h"
// MIC and Buzzer
#define AIN 0 // Note: AIN0 == pin2
#define BUZ1 3
#define BUZ2 4
// The 8x8 led matrix
// define pin where LATCH is located, can be any GPIO
// (default on BoosterPack is 6)
#define LATCH 9
// define pin where CLOCK is located, can be any GPIO
// (default on BoosterPack is 7)
#define CLOCK 10
// define pin where DATA is located, can be any GPIO
// (default on BoosterPack is 14)
#define DATA 8
#define DELAYTIME 1 // microseconds to wait after setting pin
#define TILES 6 // number of tiles
#define SPEED 40 // smaller number is faster
// The string to display, change this to dsiplay a different message
// const char *str = "}} Hello World... good morning! }}";
// const char *str = "}} !\"#$%&'( }}";
const char *strright = "%%%";
const char *strleft = "$$$";
// +*)('&%$#"\!
// Image buffer, you can modify the bits and they will be displayed on the 8x8 matrix with the sendImage() function
unsigned char image[8*TILES];
/**
*** setup()
*** Enable the output pins
**/
void setup()
{
memset(image,0xFF,sizeof(image));
pinMode(CLOCK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(LATCH, OUTPUT);
pinMode(PUSH2, INPUT_PULLUP);
Serial.begin(9600);
}
// Read switch status
boolean button()
{
return digitalRead(PUSH2) == 0;
}
// send bits to tiles, each 8x8 tile receives 16 bits to LED tile (bits 0..7 are column, 8..15 are row)
void sendData(unsigned short data)
{
for(unsigned short i=0; i<16; i++)
{
if ( data & ((unsigned short)1<<i) )
digitalWrite(DATA, 1);
else
digitalWrite(DATA, 0);
// nop();
digitalWrite(CLOCK,1);
// nop();
digitalWrite(CLOCK,0);
}
}
// scan an image on the LED tile
// 8x8 bitmap img is the input
void sendImage(unsigned char *img)
{
unsigned short data;
for(unsigned int i=0;i<8;i++)
{
for(unsigned int n=0;n<TILES;n++)
{
data = (1<<8)<<i;
data |= *(img+i+(8*n));
sendData(data);
}
// Latch data
//nop();
digitalWrite(LATCH,1);
//nop();
digitalWrite(LATCH,0);
}
}
// Shift alls bytes in the image right and add a byte in the display buffer
void shiftRight(unsigned char c)
{
for(unsigned short i=((8*TILES)-1); i>0; i--)
image[i] = image[i-1];
image[0] = c;
}
// Shift all bytes in the image buffer left and add byte in the display buffer
void shiftLeft(unsigned char c)
{
for(unsigned short i=0; i<((8*TILES)-1); i++)
image[i] = image[i+1];
image[(8*TILES)-1] = c;
}
#define ABS(a) ( (a<0 ? -a : a) )
// Sinewave example
void sineWave()
{
static const unsigned char wave[] = {4,5,6,6,7,7,7,6,6,5,4,3,2,1,1,0,0,0,1,1,2,3,4};
unsigned char j = 0, q;
for(int i=0; i<60;i++)
{
j = i % sizeof(wave);
shiftLeft(1 << wave[j]);
for(q=0; q<2; q++) sendImage(image);
}
}
// display a text going right on the 8x8 display
void showTextRight(const char *txt)
{
int a =0, i=0, j=0;
while(1)
{
sendImage(image);
if ( a++ > SPEED ) // shift in new line
{
a=0;
if ( j < 5 ) // copy character
shiftRight( *(fontPtr(txt[i]) + (unsigned int)j) );
else
{
shiftRight(0); // blank line
sendImage(image);
}
if ( ++j > 5 ) // next character
{
j = 0;
if ( ++i >= strlen(txt) )
return;
}
}
}
}
// display a text going right on the 8x8 display
void showTextLeft(const char *txt)
{
int a=0, i=0, j=0;
{
while(1)
{
sendImage(image);
if ( a++ > SPEED ) // shift in new line
{
a=0;
if ( j < 5 ) // copy character
shiftLeft( *(fontPtr(txt[i]) + (unsigned int)j) );
else
{
shiftLeft(0); // blank line
sendImage(image);
// tone(500);
}
if ( ++j > 5 ) // next character
{
j = 0;
if ( ++i >= strlen(txt) )
return;
}
}
}
}
}
/**
*** main loop, keep refreshing the image
**/
void loop()
{
x = map(analogRead(joystickX), 0, 4096, 0, 128);
y = map(analogRead(joystickY), 0, 4096, 128, 0);
if (x < 1) x = 1;
if (x > 126) x = 126;
if (y < 1) y = 1;
if (y > 126) y = 126;
//Serial.println(x);
if (x == 126){
showTextRight(strright);
}
else if (x == 1){
showTextLeft(strleft);
}
else
{
showTextLeft(" 4-19-1955 ");
}
}
Comments