Page 1 of 1
Using Digispark
Posted: Fri Aug 07, 2015 3:34 am
by canibalimao
Hi,
I've got a digispark and now I want to use my digipixel with it. However I'm having problems making it work. I've uploaded some sketches to the digispark but when I plug it to the digipixel (or plug the digipixel to it? good question) nothing happens to the leds... They stay off
What could this problem be?
Thanks in advance.
Re: Using Digispark
Posted: Fri Aug 07, 2015 11:13 am
by brad
canibalimao wrote:Hi,
I've got a digispark and now I want to use my digipixel with it. However I'm having problems making it work. I've uploaded some sketches to the digispark but when I plug it to the digipixel (or plug the digipixel to it? good question) nothing happens to the leds... They stay off
What could this problem be?
Thanks in advance.
Hi welcome to the forum. did you install the digipixel library? what code did you upload - did you try out some sample code first to make sure that works?
Re: Using Digispark
Posted: Fri Oct 09, 2015 3:37 am
by canibalimao
Sorry for the late reply. I didn't get the email notification...
Yes brad, I have installed everything. The DigiPixel works fine with an arduino and de Digispark works fine alone, but I can't make them work together....
Re: Using Digispark
Posted: Fri Oct 09, 2015 2:36 pm
by brad
have you made sure to comment out the arduino specific code and then uncomment the digispark code?

- Screen Shot 2015-10-09 at 3.37.09 PM.png (14.03 KiB) Viewed 32480 times
Re: Using Digispark
Posted: Fri Oct 09, 2015 6:07 pm
by canibalimao
Yes yes, that is also correct. Does the digispark need any special attention before playing with this?
Re: Using Digispark
Posted: Fri Oct 09, 2015 10:49 pm
by brad
No, the Digispark shouldn't need anything special at all.
Could you post some of the exact code you are using? I'll try it over the weekend with my Digispark.
Re: Using Digispark
Posted: Fri Oct 09, 2015 11:15 pm
by canibalimao
This is one of the sketches I've tried:
Code: Select all
#include <DigiPixel.h>
// DEFAULT CODE FROM EXAMPLE
// leave the following line uncommented for use with a Digispark
DigiPixel digiPixel(3,0,5,2,1); // LED Latch/Button Shift !load pin, LED/Button clock pin, LED Data Pin, LED Output Enable pin, Buttons data pin)
// leave the following line uncommented for use with an Arduino
//DigiPixel digiPixel(5,2,6,4,3); // LED Latch/Button Shift !load pin, LED/Button clock pin, LED Data Pin, LED Output Enable pin, Buttons data pin)
// PIXELBIRD CODE
// bird values
int birdX;
int birdY;
const byte birdColor = 3;
const int birdFallSpeed = 200; // bigger = slower
long birdFallUpdate; // millis() when bird falling should be updated
const int birdMoveSpeed = 400; // bigger = slower
long birdMoveUpdate; // millis() when bird moving (pipes and background) should be updated
int score;
boolean birdIsHovering = false;
const int birdHoverDelayDefault = 30;
int birdHoverDelay = birdHoverDelayDefault;
// pipe values (2 pipes)
const byte numberOfPipes = 2;
int pipeX[numberOfPipes];
int pipeY[numberOfPipes];
const byte pipeColor = 2;
// cloud values
int clouds[] = {0, 1, 1, 0, 1, 0, 1, 1};
const byte cloudColor = 7;
// states (buttons, gameOver)
boolean buttonPressed = false;
byte buttonCounter = 0;
boolean gameOver = false;
const byte scoreColor = 3;
const byte gameOverColor = 1;
void setup(){
restart();
}
void restart() {
// start in middle
birdX = 3;
birdY = 3;
score = 0;
// set first move updates
birdFallUpdate = millis() + birdFallSpeed;
birdMoveUpdate = millis() + birdMoveSpeed;
// set the first pipes
for(int i = 0; i<numberOfPipes; i++)
{
pipeX[i] = 10 + (i*5);
pipeY[i] = random(6);
}
// reset gameover
gameOver = false;
buttonCounter = 0;
}
void loop(){
updateGame();
updateGraphics();
digiPixel.saveButtonStates();
digiPixel.drawScreen();
}
void updateGame(){
if (!gameOver)
{
// move bird
if (millis() > birdFallUpdate)
{
if (birdHoverDelay != 0)
{
birdHoverDelay--;
}
else{
birdFallUpdate = millis() + birdFallSpeed;
birdY = birdY - 1;
if ((birdY < 0) || (birdY > 200)) // game over if under screen
{
birdY = 0;
gameOver = true;
}
}
}
// flap at keypress (keep state to avoid key hold)
if (digiPixel.buttonAPressed == true){
if (!buttonPressed)
{
birdY = birdY + 1;
buttonPressed = true;
birdHoverDelay = birdHoverDelayDefault;
}
}
else
{
buttonPressed = false;
}
// move background and pipes
if (millis() > birdMoveUpdate)
{
birdMoveUpdate = millis() + birdMoveSpeed;
// move clouds
for (int i = 0; i < 7; i ++)
{
clouds[i] = clouds[i+1];
}
clouds[7] = random(2); // 0 sky, 1 cloud
// move pipes
for(int i = 0; i<numberOfPipes; i++)
{
pipeX[i] = pipeX[i] - 1;
if (pipeX[i] == birdX-1) // bird passes pipe
{
score++;
}
if (pipeX[i] < 0)
{
pipeY[i] = random(6);
pipeX[i] = 9;
}
}
}
// check for collision with pipes
for(int i = 0; i<numberOfPipes; i++)
{
if (birdX == pipeX[i])
{
if ((birdY < pipeY[i]) || (birdY > pipeY[i] + 2))
{
gameOver = true;
}
}
}
}
else
{
waitForRestart();
}
}
void updateGraphics(){
digiPixel.clearScreen();
// draw clouds
for (int i = 0; i < 8; i++)
{
if (clouds[i] == 1)
{
digiPixel.setPixel(i, 7, cloudColor);
}
}
// draw pipes
for (int i = 0; i < numberOfPipes; i++)
{
for (int j = 0; j < 8; j++)
{
if (pipeX[i] < 8)
{
if ((j < pipeY[i]) or (j > pipeY[i] + 2))
{
digiPixel.setPixel(pipeX[i], j, pipeColor);
}
}
}
}
// draw bird
digiPixel.setPixel(birdX, birdY, birdColor);
// draw game over
if (gameOver)
{
int scoreCounter = 0;
for (int j = 0; j < 8; j++)
{
for (int i = 0; i < 8; i++)
{
digiPixel.setPixel(i, j, (scoreCounter < score ? scoreColor : gameOverColor));
scoreCounter++;
}
}
}
}
void waitForRestart()
{
if (digiPixel.buttonAPressed == true){
if (!buttonPressed)
{
buttonPressed = true;
}
}
else
{
if (buttonPressed)
{
// only count button ups
buttonCounter++;
}
buttonPressed = false;
}
if (buttonCounter > 1)
{
// reset after two button ups (2 to avoid direct restart)
restart();
}
}
Re: Using Digispark
Posted: Sat Oct 10, 2015 8:02 pm
by brad
It seems I have left my digispark at work so I'll have to check on Monday for you i'm afraid.
Re: Using Digispark
Posted: Wed Oct 14, 2015 9:37 pm
by brad
Well I've spent some time with my Digispark and have tried it on numerous computers and well, my Digispark is faulty. It simply does not get recognised on our two computers. So unfortunately I can't actually test out your code on an actual Digispark.
My next thing to check however - are you sure you have the DigiSpark connected to the correct pins on the digipixel?
Re: Using Digispark
Posted: Wed Oct 14, 2015 10:23 pm
by canibalimao
Yes, I have it connected to the dedicated pinouts...
I'm now waiting for a new digispark to see if it's a problem with this one I have here or if it's something else. I've read about the on board led that interfere with the i2c protocol on the ATtiny. Is this true?
Re: Using Digispark
Posted: Wed Oct 14, 2015 10:30 pm
by brad
I am not too sure about the I2C problem however the DigiPixel isn't using the I2C on the DigiSpark anyway.
Have you run a simple DigiSpark program to check that all pins are working as both inputs and then outputs? For example continuously set and clear each output and using an LED or logic probe, check to see that it keeps flashing on and off. Then try making sure that you can use them all as an input (I.E. with a switch or a button).