We have been working on combining LED matrix with other sensors to create a game controller, where the matrix functions as display, sensor as data input and Arduino as internal game logics. The controller includes a battery (1.5V?), an LED matrix, an accelerometer, a 7-digit display, an Arduino board and an enclousure.
The LED matrix that we bought from Sparkfun is an 8x8 Red/Green display. The accelerometer from RadioShack is dual-axis, sensing tilt, collision, vibration, rotation, and gravity. The idea is to use accelerometer to sense tilting and shaking of the controller itself, using the data as input for the pong game that's embedded in the Arduino. The faster you shake the controler when the ball hit the "pong board", the faster the ball will fly away. The 7-digit display will show your score, and it'll be cleared every time you lose.
The making process:
(here I moved the 7-digit display to the top side so that there's space for battery.)
We have been working on the code, which is a hybrid between two sets of codes (matrix and acceleromter). The hybridization is quite complicated, as the matrix code came with lots of unfamiliar syntax... I am posting the two sets of code separately here:
LED Matrix code:
/ Simple program to test using the Arduino with the RGB Matrix
// & Backpack from Sparkfun. Code is a combination of Heather Dewey-Hagborg,
// Arduino Forum user: Little-Scale, and // Daniel Hirschmann. Enjoy!
//
// The Backpack requires 125Khz SPI, which is the slowest rate
// at which the Arduino's hardware SPI bus can communicate at.
//
// We need to send SPI to the backpack in the following steps:
// 1) Activate ChipSelect;
// 2) Wait 500microseconds;
// 3) Transfer 64bytes @ 125KHz (1 byte for each RGB LED in the matrix);
// 4) De-activate ChipSelect;
// 5) Wait 500microseconds
// Repeat however often you like!
#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI / DI
#define DATAIN 12//MISO / DO
int data[] =
//{0,0,0,0,0,0,0,0,
//0,0,1,1,0,1,1,0,
//0,1,0,0,1,0,0,1,
//0,1,0,0,0,0,0,1,
//0,0,1,0,0,0,1,0,
//0,0,0,1,0,1,0,0,
//0,0,0,0,1,0,0,0,
//0,0,0,0,0,0,0,0
//};
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}
void setup()
{
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device
SPCR = B01010001; //SPI Registers
SPSR = SPSR & B11111110; //make sure the speed is 125KHz
/*
SPCR bits:
7: SPIEE - enables SPI interrupt when high
6: SPE - enable SPI bus when high
5: DORD - LSB first when high, MSB first when low
4: MSTR - arduino is in master mode when high, slave when low
3: CPOL - data clock idle when high if 1, idle when low if 0
2: CPHA - data on falling edge of clock when high, rising edge when low
1: SPR1 - set speed of SPI bus
0: SPR0 - set speed of SPI bus (00 is fastest @ 4MHz, 11 is slowest @ 250KHz)
*/
clr=SPSR;
clr=SPDR;
delay(10);
}
void loop()
{
delay(100);
int index = 0;
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
for (int i=0;i<8;i++) for (int j=0;j<8;j++)
{
spi_transfer(data[index]);
index++;
}
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
delayMicroseconds(500);
}
Accelerometer code:
int pinX = 3;
int pinY = 2;
unsigned long serialTimer = millis();
unsigned long xAcc = 0;
unsigned long yAcc = 0;
boolean flipflop;
void setup()
{
pinMode(pinX, INPUT);
pinMode(pinY, INPUT);
Serial.begin(115200);
}
void loop()
{
if (flipflop == true) {
xAcc = pulseIn(pinX, HIGH);
flipflop = false;
} else {
yAcc = pulseIn(pinY, HIGH);
flipflop = true;
}
if ((millis() - serialTimer) > 50 ) {
Serial.print("X ");
Serial.println(xAcc);
Serial.print("Y ");
Serial.println(yAcc);
}
}
Comments
You can follow this conversation by subscribing to the comment feed for this post.