library for 2 digit 7 segment display
hello have display , trying work 8 bit shift register. have gotten work single sketch wanting make library can use other projects display. if knows how finish library it. if knows can coding made simple possable.
sketch file
h file
cpp file
sketch file
code: [select]
//define pins used 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() {
(int digit1=0; digit1 < 10; digit1++) {
(int digit2=0; digit2 < 10; digit2++) {
unsigned long starttime = millis();
(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
code: [select]
#if arduino >= 100 // arduino 1.0 , 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
code: [select]
#include "display.h"
#if arduino >= 100 // arduino 1.0 , 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);
the code posted - point a.
you want code - point b.
you did not describe (where point is), nor did describe want (where point b is).
so, how can expect point point b?
you want code - point b.
you did not describe (where point is), nor did describe want (where point b is).
so, how can expect point point b?
Arduino Forum > Using Arduino > Programming Questions > library for 2 digit 7 segment display
arduino
Comments
Post a Comment