Pages: [1]   Go Down
Author Topic: Scrolling text  (Read 401 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to figure out how to create scrolling text across my 34x16 bicolor led display but cant seem to figure it out.

Here is the code I use to display an image across the entire display.  How can I adapt to this.  Most code i find is for single color small displays but for some reason trying to adapt this to my program things just get messed up.

Just a solid idea would be appreciated.

Code:
#define   _spi_latch   10     // Latch
#define   _spi_clock   13     // Clock
#define   _spi_data    11     // Data
#define   _control     5      //Control for ground


int _delay = 0;

void setup() {
  pinMode(_spi_clock, OUTPUT);
  pinMode(_spi_latch, OUTPUT);
  pinMode(_spi_data, OUTPUT);
  pinMode(_control, OUTPUT);
  digitalWrite(_spi_latch, HIGH);
  digitalWrite(_spi_data, HIGH);
  digitalWrite(_spi_clock, HIGH);
  digitalWrite(_control, LOW);
  setup_hardware_spi();
  delay(10);
  digitalWrite(_spi_latch, LOW);
  //GROUND
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  //RED
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  //BLUE
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  spi_transfer(B00000000);
  digitalWrite(_spi_latch, HIGH);
  delay(1000);
  digitalWrite(_control, HIGH);
}
void loop() {
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000001);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000010);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000100);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00001000);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00010000);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00100000);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B01000000);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B10000000);
spi_transfer(B00000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000000);
spi_transfer(B00000001);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000000);
spi_transfer(B00000010);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000000);
spi_transfer(B00000100);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);

digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000000);
spi_transfer(B00010000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000000);
spi_transfer(B00100000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000000);
spi_transfer(B01000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
digitalWrite(_spi_latch, LOW);
//GROUND
spi_transfer(B00000000);
spi_transfer(B10000000);
//RED
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
spi_transfer(B00000000);
//BLUE
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
spi_transfer(B11111111);
digitalWrite(_spi_latch, HIGH);
delay(_delay);
}

void setup_hardware_spi(void) {
  byte clr;
  // spi prescaler:
  // SPI2X SPR1 SPR0
  //   0     0     0    fosc/4
  //   0     0     1    fosc/16
  //   0     1     0    fosc/64
  //   0     1     1    fosc/128
  //   1     0     0    fosc/2
  //   1     0     1    fosc/8
  //   1     1     0    fosc/32
  //   1     1     1    fosc/64
  SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
  //SPCR |= ( (1<<SPR1) ); // set prescaler bits
  SPCR &= ~ ( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
  clr=SPSR; // clear SPI status reg
  clr=SPDR; // clear SPI data reg
  SPSR |= (1<<SPI2X); // set prescaler bits
  //SPSR &= ~(1<<SPI2X); // clear prescaler bits
}

byte spi_transfer(byte data) {
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte. (we don't need that here)
}

Also any idea how to organize a pattern file in order to be able to easily switch images?

Thanks
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm willing to throw some money to whomever can help me get this working by the end of the day.
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Without more information, this is going to be tough.

Your code seems to write to 16 elements 40 bits of blue each. There's no text involved yet it seems and we don't know what that display of yours is capable or how your led are arranged. Please post some more details about your display if you want useful answers.

If you display can just display bitmaps, you're first going to need a font. Those can be found in the libraries of various other displays, but you need to know how that font needs to be arranged.

Also your monster block of spaghetti code isn't really good and maintainable programming style. You better look up some concepts like loop and array in your favourite programming book.

After this, it's time to write or adapt a library for your display, so that you can do easy things like mydisplay.write ("Hello", 1, 5). The functions of that library depends largely on what you need that code for.

Lastly, once you have some text displayed, you can extend the library to offer some scrollable text function. But until then, a you have some work to do.

Have fun,

Korman
Logged

Pages: [1]   Go Up
Jump to: