Some simple demo code?

Post Reply
aspro648
Posts: 5
Joined: Sat Aug 30, 2008 12:56 am

Some simple demo code?

Post by aspro648 » Sat Oct 18, 2008 11:55 pm

Hey Paul,

Newbie again. Your Arduino scrolling text code is way over my head. Could you post something simple like displaying a single, non-scrolling pattern, for a single board? Your kit instructions do promise "several Arduino sketches" for the board. I've only found the one.

It's a brilliant kit. I'd like to see more of what others have done with it.

Many thanks!

paul
Site Admin
Posts: 706
Joined: Mon May 12, 2008 4:19 pm

Re: Some simple demo code?

Post by paul » Sun Oct 19, 2008 11:18 pm

I've thought about doing this and always found something more important. This will spur me on. I'll just set up an array and flip frames in an animation.
Write back if it's not on the site in a couple of days.

Paul

aspro648
Posts: 5
Joined: Sat Aug 30, 2008 12:56 am

Re: Some simple demo code?

Post by aspro648 » Sun Oct 19, 2008 11:59 pm

Had some time to play around today. I'm working on a high-output rear LED for a bicycle. Man, is it bright! This code will flash the entire matrix on and off for random intervals. I'm sure I can come up with something more imaginative and eye-catching, but it is a start.

Code: Select all


#include <avr/pgmspace.h>

int latchPin = 2; //Pin connected to SPI latch
int clockPin = 4; //Pin connected to SPI clock -
int outputEnable = 3; //Pin connected to SPI output enable - high equals off
int dataPin = 5; //Pin connected to SPI clock

unsigned long show[] = {65535,65535,65535,65535,65535}; //light up all LEDs

void setup() {

  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  digitalWrite(latchPin, HIGH);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(outputEnable, OUTPUT);
  digitalWrite(outputEnable, LOW);
  Serial.begin(9600);
  Serial.println("start");
}

void loop(){

  on(random(500));
  off(random(500));
 
}

void on(int pause){
  
   digitalWrite(latchPin, LOW);  //take latchPin LOW for as long as you are sending data
   for (int i=0; i<4; i++){
      shiftOut(dataPin, clockPin, MSBFIRST, (show[i] >> 8));   // send high byte
      shiftOut(dataPin, clockPin, MSBFIRST, show[i] );         // send low byte
    }
    digitalWrite(latchPin, HIGH);    //return the latch pin HIGH to update LED's
    delay(pause);
}

void off(int pause){
    digitalWrite(outputEnable, HIGH);
    delay(pause);  
    digitalWrite(outputEnable, LOW); 
}
Some flip-screen animation? Now that would be cool!

paul
Site Admin
Posts: 706
Joined: Mon May 12, 2008 4:19 pm

Re: Some simple demo code?

Post by paul » Thu Oct 23, 2008 11:53 am

Try this for now. I'm trying to find time to get something better together. You've got the basic idea though

Code: Select all

#include <avr/pgmspace.h>

Removed by Paul - use code below

}

paul
Site Admin
Posts: 706
Joined: Mon May 12, 2008 4:19 pm

Re: Some simple demo code?

Post by paul » Thu Oct 23, 2008 5:39 pm

Oops, that code has a problem in the way frames are indexed. Here's the fix I think.
I haven't tested either listing so there may be issues...
Write back if they don't work. I'll try and stay closer to the forum. I can't seem to find an email reminder in the prefs. Probably something I'll have to install.

Code: Select all

#include <avr/pgmspace.h>

int latchPin = 2; //Pin connected to SPI latch
int clockPin = 4; //Pin connected to SPI clock -
int outputEnable = 3; //Pin connected to SPI output enable - high equals off
int dataPin = 5; //Pin connected to SPI clock

int totalFrames;         
int frameDelay = 100;   // 10 frames per second

//                      first frame,               second frame,              third frame 
unsigned int show[] = {
  65535,65535,65535,65535,   65535,65535,65535,65535,   65535,65535,65535,65535,       }; // put some data in here with 8x8 calculator on the 8x8 page

void setup() {

  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  digitalWrite(latchPin, HIGH);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(outputEnable, OUTPUT);
  digitalWrite(outputEnable, LOW);
  Serial.begin(9600);
  Serial.println("start");

// finds total frames divide by 8  because 2 bytes per int, 4 ints per frame
// sizeof may report bytes instead of ints
  totalFrames =  sizeof(show);  // find message size, counting total ints because 
                                // I'm indexing frames by 4 below (frames+=4)

}

void loop(){

  playAnimation();

}

void playAnimation(){
  // send the data to the display
  digitalWrite(latchPin, LOW);  //take latchPin LOW for as long as you are sending data
  for (int frames=0; frames<totalFrames; frames+=4){
    for (int i=0; i<4; i++){
      shiftOut(dataPin, clockPin, MSBFIRST, (show[frames + i] >> 8));   // send high byte
      shiftOut(dataPin, clockPin, MSBFIRST, show[frames + i] );         // send low byte
    }
    digitalWrite(latchPin, HIGH);    //return the latch pin HIGH to update LED's
    delay(frameDelay);
  }
}


void off(int pause){
  digitalWrite(outputEnable, HIGH);     // turn off enable line, you can also use analogWrite() to dim the display
  // make sure you use a PWM pin though on Arduino, or it won't work
}

snapshot 720
Posts: 1
Joined: Mon Dec 15, 2008 7:18 pm

Re: Some simple demo code?

Post by snapshot 720 » Tue Dec 16, 2008 7:04 pm

Hi Paul,

I'm newer than a newbie! I've bought your 8x8 LED panel and had a wonderful time putting it together. I ran your sketch with the robot code and it worked beautifully. I had no problem figuring out how to replace the robot code with my own.
However, when I tried to tried to wrap my head around the 8x8 Demo code found in this forum, I failed completely. When I loaded it, my result was all 64 LEDs lit. I used your 8x8 calculator (which on my computer -a PC- is backwards. The dark squares light up the LEDs and the light squares leave them off) and loaded in something different and, while I could get the display I wanted, I could not get any animation. It is true that I am struggling with the sketches. Can you help me out?
Thanks,
Dan

madbeing
Posts: 4
Joined: Wed Dec 24, 2008 3:50 pm

Re: Some simple demo code?

Post by madbeing » Wed Dec 24, 2008 4:35 pm

I've got a couple of demo's that I did based on the original Laws of Robotics code. They are fairly simple and test all of the leds on an individual panel. I wrote them to make sure every led was working correctly. If you hook multiple panel's together the software should load the same patterns (out of phase by 4 patterns per panel) on each successively.

LED_8x8_Test.zip does various test patterns (stolen from various memory diagnostics I worked on in the past).

Then LED_8x8_Walking_Bit.zip walks a single bit through the array and wraps it back to the beginning when it hits the bottom. I got the idea for this from an old lights pattern on the front panel of a DEC PDP 11/45 computer that I used to manage. The idle task for the system did a set of walking bits in the address / data lights of the system. You could tell how busy the system was by the rotation speed of the bits. (faster rotation == more context switches between users in a shorter period).

By playing with the delay value I've found that when updating the pattern faster than 50ms the led's start to smear (at least to my eyes) down around 20 or 10 it looks like all leds are on.

I haven't decided what to do with this yet. I'm still trying different coloured leds. The first one was built using 5000mcd yellows which are bright enough to put spots in your vision. I ordered a set of 6000mcd blue's that should be a bit brighter for the next panel.

Dan
Attachments
LED_8x8_Walking_Bit.zip
unzip this in your sketchbook directory. Then compile it from the ide.
(1.27 KiB) Downloaded 754 times
LED_8x8_Test.zip
unzip this in your sketchbook directory. Then compile it from the ide.
(1.25 KiB) Downloaded 652 times

Post Reply