Using Digispark
Moderators: Chuckt, Garth, bitfogav
-
- newbie
- Posts: 6
- Joined: Wed Mar 19, 2014 6:31 am [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Using Digispark
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.
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.
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
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?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.
-
- newbie
- Posts: 6
- Joined: Wed Mar 19, 2014 6:31 am [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
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....
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....
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
have you made sure to comment out the arduino specific code and then uncomment the digispark code?
-
- newbie
- Posts: 6
- Joined: Wed Mar 19, 2014 6:31 am [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
Yes yes, that is also correct. Does the digispark need any special attention before playing with this?
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
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.
Could you post some of the exact code you are using? I'll try it over the weekend with my Digispark.
-
- newbie
- Posts: 6
- Joined: Wed Mar 19, 2014 6:31 am [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
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();
}
}
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
It seems I have left my digispark at work so I'll have to check on Monday for you i'm afraid.
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
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?
My next thing to check however - are you sure you have the DigiSpark connected to the correct pins on the digipixel?
-
- newbie
- Posts: 6
- Joined: Wed Mar 19, 2014 6:31 am [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
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?
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?
- brad
- Site Admin
- Posts: 2578
- Joined: Fri Mar 26, 2010 10:30 pm [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
Re: Using Digispark
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).
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).
Who is online
Users browsing this forum: No registered users and 3 guests