SevenSegment Library for Arduino
Author:  Alexander Brevig
Contact: alexanderbrevig@gmail.com


Navigation


Current version

1.2 2009-04-13: Ready for ShiftRegisters


History

1.2 2009-04-13: Ready for ShiftRegisters
1.1 2009-03-16: Uses binary logic to represent states, not ints. [uses 14 x less ram].
1.0 2009-03-13: Initial Release


Description

SevenSegment is a library for the Arduino.

It is created to help Hardware Abstraction, and readability of code. It hides the pinMode, and digitalRead calls for the user.

SevenSegment library is part of the Hardware Abstraction libraries.


Download, install and import

Download here: Attach:SevenSegment.zip

Put the SevenSegment folder in "hardware\libraries\".
In the Arduino IDE, create a new sketch (or open one) and select from the menubar "Sketch->Import Library>SevenSegment".
Once the library is imported, an '#include<SevenSegment.h>' line will appear at the top of your Sketch.


Creation

SevenSegment() //default 2,3,4,5,6,7,8 SevenSegment(byte userPins[])

byte pins[] = {6,7,8,9,10,11,12}; SevenSegment sevenSegment = SevenSegment(pins);

Instanciates a SevenSegment object connected to digital pins 6,7,8,9,10,11 and 12.


Functions

void buffer(byte number)

Prepare a byte to be shifted

void print()

Shift out the buffered byte

void print(byte number)

Shift out the number

void attachShiftRegister( ShiftRegister595& userShiftRegister )

Connect a ShiftRegister to the SevenSegment.


Example

  1. /*
  2. ||
  3. || @author Alexander Brevig
  4. || @version 1.0
  5. ||
  6. || @description
  7. || Demonstrates the functionality of the SevenSegment class and ShiftRegister595 class
  8. ||
  9. */
  10.  
  11. #include <ShiftRegister595.h>
  12. #include <SevenSegment.h>
  13.  
  14. ShiftRegister595 shiftRegister = ShiftRegister595(10,11,12);
  15. SevenSegment sevenSegment = SevenSegment(shiftRegister);
  16.  
  17. void setup(){ /*nothing*/ }
  18.  
  19. void loop(){
  20.   for (byte i=0;i<=9;i++){
  21.     sevenSegment.print(i);// prints selected values from 0 to 9
  22.     delay(1000);
  23.   }
  24. }


FAQ

How can I use multiple SevenSegment displays?

SevenSegment is a class. Therefore to SevenSegment multiple digital pins, you must create an instance for each of them.

Say you have sevenSegment and sevenSegment2 it's just to call whatever function is wanted on target SevenSegment object

//check sevenSegment
  sevenSegment.buffer(2);
  sevenSegment2.print(3);


Information about this page

Part of AlphaBeta Libraries.
Last Modified: May 09, 2009, at 05:12 AM
By: AlphaBeta

Share