hello everyone i have this display and am trying to get it to work with a 8 bit shift register. I have gotten it to work as a single sketch but am wanting to make it into a library that i can use for other projects with the display. if anyone knows how to finish this library i would like it. also if anyone knows can the coding be made a simple as possable.
sketch file
//Define which pins will be used for the Shift Register control
int dataPin = 2;
int latchPin = 3;
int clockPin = 4;
#define CA1 13
#define CA2 12
//The byte sequence
int numbers[10] = {0b00000011,0b10011111,0b00100101,0b00001101,0b10011001,0b01001001,0b01000001,0b00011111,0b00000001,0b00001001};
void setup()
{
//Configure each IO Pin
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(CA1, OUTPUT);
pinMode(CA2, OUTPUT);
}
void loop() {
for (int digit1=0; digit1 < 10; digit1++) {
for (int digit2=0; digit2 < 10; digit2++) {
unsigned long startTime = millis();
for (unsigned long elapsed=0; elapsed < 600; elapsed = millis() - startTime) {
lightDigit1(digit1);
delay(5);
lightDigit2(digit2);
delay(5);
}
}
}
}
void lightDigit1(int number) {
digitalWrite(CA1, LOW);
digitalWrite(CA2, HIGH);
lightSegments(number);
}
void lightDigit2(int number) {
digitalWrite(CA1, HIGH);
digitalWrite(CA2, LOW);
lightSegments(number);
}
void lightSegments(int number) {
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, numbers[number]);
digitalWrite(latchPin, HIGH);
}
h file
#if ARDUINO >= 100 // Arduino 1.0 and 0023 compatible!
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class Display
{
public:
registerpin(int dataPin, int latchPin, int clockPin);
digitpins(int CA1, int CA2);
void lightdigit1(int);
void lightdigit2(int);
private:
int _dataPin, _latchPin, _clockPin;
cpp file
#include "Display.h"
#if ARDUINO >= 100 // Arduino 1.0 and 0023 compatible!
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
Display::registerpin(int dataPin, int latchPin, int clockPin) {
_dataPin = dataPin;
_latchPin = latchPin;
_clockPin = clockPin;
pinMode(_dataPin,OUTPUT);
pinMode(_latchPin,OUTPUT);
pinMode(_clockPin,OUTPUT);
}
void Display::lightdigit1(){
digitalWrite(CA1, LOW);
digitalWrite(CA2, HIGH);
}
void Display::lightdigit2(){
digitalWrite(CA1, HIGH);
digitalWrite(CA2, LOW);
}
void Display::lightsegment(int numbero) {
_numbero=numbero;
_number=number;
int number[10] = {0b00000011,0b10011111,0b00100101,0b00001101,0b10011001,0b01001001,0b01000001,0b00011111,0b00000001,0b00001001};
digitalWrite(_latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, number[numbero]);
digitalWrite(_latchPin, HIGH);
2_Digit_display.ino (3.76 KB)
Display.h (331 Bytes)
Display.cpp (870 Bytes)