Tuesday, 7 April 2009

Basic Description

The library controls a Kingbright compatible 17-Segment LED display on Arduino on digital pins 2-17 (14-17 being analog in 0-3). It should be wired to the display so that pins 2-17 correspond to segments [a m k h u s t g f e d r p c n b].

The diagram shows how the common cathode should be connected to ground and all outputs used connected to the display via 300r resistors.
___________________________________________________________________________________

Code:

Sts.h

/*
  Created by Ben Duncan - 7 April, 2009
 Shared under Creative Commons
 Give easy control of Alphanumeric LED displays
 (Kingbright type)
 */

#ifndef Sts_h
#define Sts_h

#include "WProgram.h"

class Sts
{
  public:
    int _charNum;
    void displayChar(int _charNum);
    void displayNumb(int _charNum);
    byte charactersCap[26][16];
    byte numbers[10][16];
  private:
    void setPins();
};

#endif

Sts.cpp

/*
  Created by Ben Duncan - 7 April, 2009
 Shared under Creative Commons
 Give easy control of Alphanumeric LED displays
 (Kingbright type)
 */

#include "WProgram.h"
#include "Sts.h"

byte characters[26][16] = {
  {1,0,0,1,1,0,0,1,0,0,1,0,1,1,0,1},  // A
  {1,0,0,1,0,0,0,1,1,1,0,1,0,0,1,1},  // B
  {1,0,0,1,0,0,0,1,1,1,0,0,0,0,0,1},  // C
  {1,0,0,1,0,0,0,1,1,1,0,1,0,1,0,1},  // D
  {1,0,0,1,0,0,0,1,1,1,0,0,0,1,0,1},  // E
  {1,0,0,1,1,0,0,1,0,0,0,0,0,0,0,1},  // F
  {1,0,0,1,0,0,0,1,1,1,1,0,1,0,0,1},  // G
  {0,0,0,1,1,0,0,1,0,0,1,0,1,1,0,0},  // H
  {1,1,0,0,0,1,0,0,1,1,0,0,0,0,0,1},  // I
  {1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1},  // J
  {0,0,0,1,1,0,0,1,0,0,0,1,0,0,1,0},  // K
  {0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,0},  // L
  {1,1,0,1,0,0,0,1,0,0,1,0,0,1,0,1},  // M
  {0,0,1,1,0,0,0,1,0,0,1,1,0,1,0,0},  // N
  {1,0,0,1,0,0,0,1,1,1,1,0,0,1,0,1},  // O
  {1,0,0,1,1,0,0,1,0,0,0,0,1,1,0,1},  // P
  {1,0,0,1,0,0,0,1,1,1,1,1,0,1,0,1},  // Q
  {1,0,0,1,1,0,0,1,0,0,0,1,1,1,0,1},  // R
  {1,0,0,1,1,0,0,0,1,1,1,0,1,0,0,1},  // S
  {1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1},  // T
  {0,0,0,1,0,0,0,1,1,1,1,0,0,1,0,0},  // U
  {0,0,1,0,0,0,0,0,0,0,1,1,0,1,0,0},  // V
  {0,0,0,1,0,1,0,1,1,1,1,0,0,1,0,0},  // W
  {0,0,1,0,0,0,1,0,0,0,0,1,0,0,1,0},  // X
  {0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0},  // Y
  {1,0,0,0,0,0,1,0,1,1,0,0,0,0,1,1}};  // Z

byte numbers[10][16] = {
  {1,0,0,1,0,0,0,1,1,1,0,1,0,1,0,1},  // 0
  {1,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},  // 1
  {1,0,0,0,1,0,0,0,1,1,0,0,1,0,0,1},  // 2
  {1,0,0,0,1,0,0,0,1,1,1,0,1,1,0,1},  // 3
  {0,0,0,1,1,0,0,0,0,0,1,0,1,1,0,0},  // 4
  {1,0,0,1,1,0,0,0,1,1,1,0,1,0,0,1},  // 5
  {1,0,0,1,1,0,0,1,1,1,1,0,1,0,0,1},  // 6
  {1,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1},  // 7
  {1,0,0,1,1,0,0,1,1,1,1,0,1,1,0,1},  // 8
  {1,0,0,1,1,0,0,0,1,1,1,0,1,1,0,1}};  // 9

void Sts::setPins(){
  for(int i=2; i<17;>
    pinMode(i, OUTPUT);
  }
}

void Sts::displayChar(int _charNum)
{
  for(int i=0; i<15;>
    digitalWrite((i+2), characters[_charNum][i]);
  }
}

void Sts::displayNumb(int _charNum)
{
  for(int i=0; i<15;>
    digitalWrite((i+2), numbers[_charNum][i]);
  }
}
___________________________________________________________________________________

To compile the library, save the code in their component files e.g. Sts.h code in Sts.h and so on...
Next, open Arduino IDE and it should compile with no errors. Then try running this example sketch:

BasicUseLoop.pde

/*
  Created by Ben Duncan - 7 April, 2009
 Shared under Creative Commons
 Give easy control of Alphanumeric LED displays
 (Kingbright type)
 */

#include  // Include the Seventeen Segment library

Sts Sts;  // Create the Sts object
void setup(){
}

void loop() {
  for(int i=0; i<26; i++){
    Sts.displayChar(i);  // Display the capital character
    delay(500);  // Wait 1/2 second
  }
  for(int i=0; i<10;>
    Sts.displayNumb(i);  // Display the number
    delay(500);  // Wait 1/2 second
  }
}

All being well, it should run through the Alphabet then numbers 0-9.

Good Luck!