Using Digispark

Post here to discuss all things DigiPixel related.

Moderators: Chuckt, Garth, bitfogav

Post Reply [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
canibalimao
newbie
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

Post by canibalimao » Fri Aug 07, 2015 3:34 am

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.

User avatar
brad
Site Admin
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

Post by brad » Fri Aug 07, 2015 11:13 am

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?

canibalimao
newbie
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

Post by canibalimao » Fri Oct 09, 2015 3:37 am

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....

User avatar
brad
Site Admin
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

Post by brad » Fri Oct 09, 2015 2:36 pm

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
Screen Shot 2015-10-09 at 3.37.09 PM.png (14.03 KiB) Viewed 23929 times

canibalimao
newbie
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

Post by canibalimao » Fri Oct 09, 2015 6:07 pm

Yes yes, that is also correct. Does the digispark need any special attention before playing with this?

User avatar
brad
Site Admin
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

Post by brad » Fri Oct 09, 2015 10:49 pm

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.

canibalimao
newbie
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

Post by canibalimao » Fri Oct 09, 2015 11:15 pm

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();
  }
}

User avatar
brad
Site Admin
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

Post by brad » Sat Oct 10, 2015 8:02 pm

It seems I have left my digispark at work so I'll have to check on Monday for you i'm afraid.

User avatar
brad
Site Admin
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

Post by brad » Wed Oct 14, 2015 9:37 pm

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?

canibalimao
newbie
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

Post by canibalimao » Wed Oct 14, 2015 10:23 pm

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?

User avatar
brad
Site Admin
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

Post by brad » Wed Oct 14, 2015 10:30 pm

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).

Post Reply
[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
[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

Who is online

Users browsing this forum: No registered users and 10 guests