Created
November 15, 2020 06:25
-
-
Save kd8bxp/87c893dece26b085900d0b50f0db6397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Written for the M5StackC but should work for other micro-controller | |
//For the LCTECH 8 digit - 7 segment display module | |
//Finally found a picture of how it is wired, from | |
//https://libstock.mikroe.com/projects/view/3860/lctech-74hc164-dual-seven-segments-display-demo-max-min-thermometer | |
//and found a little more information on the 74c164 shift register from here | |
//http://www.bristolwatch.com/arduino/arduino3.htm | |
//with a little trial and error I was finally able to get this to work | |
//thou it is not perfect, and still needs some work it's a start | |
//Nov 15, 2020 - LeRoy Miller, KD8BXP (c) | |
int dataPin = 26; | |
int clockPin = 0; | |
//This display appears to be inverted, so a 1 is off, and a 0 is on for this list and only this list | |
byte digit = 0b00000001; // Not used in this sketch, right bit is the lower right display | |
//this tells which digit to use starting on the lower display right most display is #0 the top left display is #7 | |
byte zero = 0b00000011; //zero no dot | |
byte one = 0b10011111; //one no dot | |
byte two = 0b00100101; //two no dot | |
byte three= 0b00001101; //three no dot | |
byte four = 0b10011001; //four no dot | |
byte five = 0b01001001; //five no dot | |
byte six = 0b11000001; //six no dot | |
byte seven= 0b00011111; //seven no dot | |
byte eight= 0b00000001; //eight no dot | |
byte nine = 0b00011001; //nine no dot | |
// ABCDEFGP | |
void setup() { | |
pinMode(clockPin, OUTPUT); | |
pinMode(dataPin, OUTPUT); | |
} | |
void loop() { | |
//Another way to display (used when testing) | |
// shiftOut(dataPin, clockPin, LSBFIRST, zero); //segment); | |
//shiftOut(dataPin, clockPin, LSBFIRST, digit); | |
for (int i=0; i<=7; i++) { | |
for (int y=0; y<=9; y++) { | |
display(y, i, 0); //display(# between 0 & 9, the digit starting on lower display 0 is the right digit, display dot true/false 0,1) | |
delay(150); | |
} | |
} | |
//Biggest problem with this display, there is no latch, so to display | |
//more than one digit you have to continue to write to the display | |
//This is just a test to show it, but a better way is needed to do | |
while(1) { | |
display(1,3,0); | |
delay(5); | |
display(2,2,1); | |
delay(5); | |
display(4,1,0); | |
delay(5); | |
display(1,0,0); | |
delay(5); | |
display(3,7,true); | |
delay(5); | |
display(1,6,false); | |
delay(5); | |
display(4,5,false); | |
delay(5); | |
display(1,4,false); | |
delay(5); | |
} | |
} | |
void display(int segment, int numerial, bool dot) { | |
switch (segment) { | |
case 0: | |
if (dot == 1) {bitWrite(zero, 0, 0); } else {bitWrite(zero,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, zero); //segment); | |
break; | |
case 1: | |
if (dot == 1) {bitWrite(one, 0, 0); } else {bitWrite(one,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, one); //segment); | |
break; | |
case 2: | |
if (dot == 1) {bitWrite(two, 0, 0); } else {bitWrite(two,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, two); //segment); | |
break; | |
case 3: | |
if (dot == 1) {bitWrite(three, 0, 0); } else {bitWrite(three,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, three); //segment); | |
break; | |
case 4: | |
if (dot == 1) {bitWrite(four, 0, 0); } else {bitWrite(four,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, four); //segment); | |
break; | |
case 5: | |
if (dot == 1) {bitWrite(five, 0, 0); } else {bitWrite(five,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, five); //segment); | |
break; | |
case 6: | |
if (dot == 1) {bitWrite(six, 0, 0); } else {bitWrite(six,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, six); //segment); | |
break; | |
case 7: | |
if (dot == 1) {bitWrite(seven, 0, 0); } else {bitWrite(seven,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, seven); //segment); | |
break; | |
case 8: | |
if (dot == 1) {bitWrite(eight, 0, 0); } else {bitWrite(eight,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, eight); //segment); | |
break; | |
case 9: | |
if (dot == 1) {bitWrite(nine, 0, 0); } else {bitWrite(nine,0,1);} | |
shiftOut(dataPin, clockPin, LSBFIRST, nine); //segment); | |
break; | |
default: | |
//nothing | |
break; | |
} | |
shiftOut(dataPin, clockPin, LSBFIRST, 0b00000001 << numerial); // digit); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment