Exploring BeagleBone  V1.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
exploringBB::SevenSegmentDisplay Class Reference

A class that allows you to drive an array of 7 segment displays using an array of 74XX595 ICs. More...

#include <SevenSegmentDisplay.h>

Public Member Functions

 SevenSegmentDisplay (SPIDevice *device, int numberSegments)
 
virtual int write (int number)
 
virtual int write (float number, int places)
 
virtual int setNumberBase (int base)
 
virtual int getNumberBase ()
 
virtual int getNumberSegments ()
 
virtual void setCommonAnode (bool isCommonAnode)
 
virtual ~SevenSegmentDisplay ()
 

Detailed Description

A class that allows you to drive an array of 7 segment displays using an array of 74XX595 ICs.

Constructor & Destructor Documentation

exploringBB::SevenSegmentDisplay::SevenSegmentDisplay ( SPIDevice device,
int  numberSegments 
)

The constructor for the 7-segment display that defines the number of segments.

Parameters
deviceThe pointer to the SPI device bus
numberSegmentsThe number of 7-segment modules attached to the bus
44  {
45  this->spidevice = device;
46  this->numberSegments = numberSegments;
47  this->numberBase = 10; //decimal by default
48  this->isCommonAnode = false;
49 }
exploringBB::SevenSegmentDisplay::~SevenSegmentDisplay ( )
virtual
88  {
89  this->spidevice->close();
90 }
virtual void close()
Definition: SPIDevice.cpp:245

Member Function Documentation

virtual int exploringBB::SevenSegmentDisplay::getNumberBase ( )
inlinevirtual
47 { return this->numberBase; }
virtual int exploringBB::SevenSegmentDisplay::getNumberSegments ( )
inlinevirtual
48 { return this->numberSegments; }
virtual void exploringBB::SevenSegmentDisplay::setCommonAnode ( bool  isCommonAnode)
inlinevirtual
49 { this->isCommonAnode = isCommonAnode; }
int exploringBB::SevenSegmentDisplay::setNumberBase ( int  base)
virtual
51  {
52  if (base>16 || base<2) return -1;
53  return (this->numberBase = base);
54 }
int exploringBB::SevenSegmentDisplay::write ( int  number)
virtual
56  {
57  // going to send one character for each segment
58  unsigned char output[this->numberSegments];
59  // output least-significant digit and divide by base
60  for(int i=0; i<this->numberSegments; i++){
61  output[i] = this->symbols[number%this->numberBase];
62  if(this->isCommonAnode) output[i]=~output[i]; //invert the bits for common anode
63  number = number/this->numberBase;
64  }
65  this->spidevice->write(output, this->numberSegments);
66  return 0;
67 }
virtual int write(unsigned char value)
Definition: SPIDevice.cpp:139
int exploringBB::SevenSegmentDisplay::write ( float  number,
int  places 
)
virtual
69  {
70  // if the number of places is greater than the number of segments -1, stop.
71  if (places>(this->numberSegments-1)) return -1;
72  // can display non-decimal floats
73  int intNumber = (int) number;
74  if (places>0) intNumber = (int)(number * places * this->numberBase);
75  // going to send one character for each segment
76  unsigned char output[this->numberSegments];
77  // output least-significant digit and divide by base
78  for(int i=0; i<this->numberSegments; i++){
79  output[i] = this->symbols[intNumber%this->numberBase];
80  if(i==places) output[i] = output[i] | 0b10000000; // turn on "decimal point"
81  if(this->isCommonAnode) output[i]=~output[i]; //invert the bits for common anode
82  intNumber = intNumber/this->numberBase;
83  }
84  this->spidevice->write(output, this->numberSegments);
85  return 0;
86 }
virtual int write(unsigned char value)
Definition: SPIDevice.cpp:139

The documentation for this class was generated from the following files: