Pages

Showing posts with label lol shield. Show all posts
Showing posts with label lol shield. Show all posts

Monday, August 29, 2011

The Matrix Falling Code, Arduino LOL Shield Style

I got an Arduino over the weekend. I also picked up a LOL Shield from JimmiePRodgers.com. After what seemed like an eternity soldering LEDs, I finally got a chance to try out some code. There is nothing earth shattering here, just a fun little demo. Enjoy!



My code is below:
----------------------------------------------------

// Matrix Falling Code LOL Shield Demo
// Code from Marshal Graham via marshalgraham.com 
// August 29, 2011 - First revision
// This runs on the Arduino with the LOL Shield from JimmiePRodgers.com
/*
  This is free software; you can redistribute it and/or
  modify it under the terms of the GNU Version 3 General Public
  License as published by the Free Software Foundation;
  or (at your option) any later version.

  This code is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <Charliplexing.h> //Imports the library, which needs to be

// array to store the LED column state
boolean ledState[14];

void setup() 
{
  // Initialize the LOL Shield
  LedSign::Init();
  // seed the random number generator
  randomSeed(analogRead(0));
}

void loop()
{
  // Randomly choose a column
  DropColumn(random(14));
  // Wait a random amount of time up to 50 ms
  delay(random(50));
}

void DropColumn(int col)
{
  // Check the LED column state
  // If it's not lit then light it
  if (ledState[col] == false) {
    // cycle through each LED in the column
    for (byte i=0; i<9; i++){
      LedSign::Set(col,i,1);
      delay(25);
      }
    ledState[col]=true;
  }
  // otherwise shut it off
  else {
    // cycle through each LED in the column
    for (byte i=0; i<9; i++){
      LedSign::Set(col,i,0);
      delay(25);
      }
      ledState[col]=false;
  }
}