7segment lib help

HEy everyone. so i found this library on the playground for a 17 seg display http://17segment.blogspot.com/

but it errors like mad, several not completed for loops, etc. I’m using a seven segment display, so I’ve tried to modify it like so:

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 displayNumb(int _charNum);
        byte numbers[10][8];
  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 numbers[10][8] = {
  {1,0,0,1,0,0,0,1},  // 0
  {1,1,0,0,0,1,0,0},  // 1
  {1,0,0,0,1,0,0,0},  // 2
  {1,0,0,0,1,0,0,0},  // 3
  {0,0,0,1,1,0,0,0},  // 4
  {1,0,0,1,1,0,0,0},  // 5
  {1,0,0,1,1,0,0,1},  // 6
  {1,0,0,0,0,0,0,0},  // 7
  {1,0,0,1,1,0,0,1},  // 8
  {1,0,0,1,1,0,0,0}};  // 9

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

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

and the arduino code

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

#include <sts.h>// Include the Seventeen Segment library


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

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

it compiles but nothing happens. I know the thing is wired right, it works if i run a simple test code on the pins to turn them on. i think it’s something with the 2d array, which i don’t really understand. it seems the 1’s and o’s are telling which pins to be on and off, but i don’t really get how.

Sts Sts; // Create the Sts object

This does not do anything. It is the same as saying:

int 2;

You do not initialize tha array numbers. What you do, however, is you create and initialize a new array called numbers at local scope. But you class looks for and uses the Sts::numbers not the numbers.

You will need to create a constructor or some other way of initializing the local numbers variable.

You could use and/or modify this library: http://www.arduino.cc/playground/Code/SevenSegment

It uses uses about ten times less ram as opposed to the byte[10][8] solution. :)

thanks. yeah, i was wondering about that STS thing. I didn't write the library, it's on the playground under output. I didn't see where the pins were declared, I thought maybe I was missing something. I'll check out that library and see what I can do. thanks again

that library looks good, but I don't have shift regs. think i'll use the nart one

You do not need to use a shift register, you just have the option to.

/*
||
|| @author Alexander Brevig
|| @version 1.0
||
|| @description
|| | Demonstrates the functionality of the SevenSegment class
|| #
||
*/

#include <SevenSegment.h>

byte pins = {2,3,4,5,6,7,8};
SevenSegment sevenSegment = SevenSegment(pins);

void setup(){ /nothing/ }

void loop()
{
for (byte i=0;i<=9;i++){
sevenSegment.print(i);// prints selected values from 0 to 9
delay(500);
}
}

ok thanks, still learning, can't see everything yet

ok thanks, still learning, can't see everything yet

That is fine. :) No one is expecting you to either.