[dorkbotdc-blabber] Arduino code for LED cube

Dale Ghent daleg at elemental.org
Mon Jan 21 01:03:53 EST 2008


On Jan 20, 2008, at 10:40 PM, David Brunton wrote:

> Hey all,
>
> I got a little more chance to play around with the cube tonight.  I  
> don't have a video camera handy, which is a shame, because these  
> blue LEDs are pretty, and Zoe and Tommy have decided this is their  
> new favorite toy.  However, I have enclosed some code doodling that  
> lights up each light in sequence, then each plane in sequence, then  
> a bunch of random lights.
>
> I didn't make a lot of comments in the code, and I didn't spend any  
> time abstracting yet, but it's there and it works (minus any bugs  
> that it almost certainly has).  Has anyone else come up with  
> something cool?  I've been trying some 3-d game-of-life variations,  
> but they're all boring so far.

I finished my green cube up today, figuring out how the planes were  
wired by reading back through the demo code that was posted here  
earlier. I managed a program that (passably) spells out my  
girlfriend's name: T - A - L - I - A, from top to bottom. Now only if  
she'd sit down and get her red cube done ;)

That's a nice bit of code you've posted, David. I went ahead and added  
something to it, a drop-in replacement for randomLight(). It checks to  
see if the random() call for the anodes returned a number that  
corresponds with a pin that's PWM-capable and will randomly choose to  
fade it up and back down if so. The fading randomLight() func is  
attached.

Thanks to MAKE and Dr0kbot for that shindig the other night. This was  
my first real electronics kit aside from playing around with one of  
those Radio Shack 150-in-1 kits when I was 10.

/dale
-------------- next part --------------


void randomLight() {
  int pwm;
  int perhaps = random(2);
  int i = random(3);
  int j = random(9);
  
  // See if we've stumbled on a PWM-capable anode
  // These pins are PWM-capable on the Diecimila
  if (perhaps == 1 && (anode[j] == 3 || anode[j] == 5 ||
      anode[j] == 6 || anode[j] == 9 || 
      anode[j] == 10 || anode[j] == 11)) {
    
    digitalWrite(cathode[i], LOW);
    digitalWrite(anode[j], HIGH);
    
    for (pwm = 0; pwm <= 255; pwm += 5) {
      analogWrite(anode[j], pwm);
      delay(6);
    }
    
    for (pwm = 255; pwm >= 0; pwm -= 5) {
      analogWrite(anode[j], pwm);
      delay(6);
    }
    
    digitalWrite(cathode[i], HIGH);
    digitalWrite(anode[j], LOW);
  
  // We havnt got a PWM-capable pin so do a normal bink on/off
  } else {
    
    digitalWrite(cathode[i], LOW);
    digitalWrite(anode[j], HIGH);
    delay(delayTime);
    digitalWrite(cathode[i], HIGH);
    digitalWrite(anode[j], LOW);
  }
}



More information about the dorkbotdc-blabber mailing list