Skip to content

Instantly share code, notes, and snippets.

@aallan
Last active February 3, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aallan/7ae04d27ac19b8ea90e26f8391f624c2 to your computer and use it in GitHub Desktop.
Save aallan/7ae04d27ac19b8ea90e26f8391f624c2 to your computer and use it in GitHub Desktop.
/*
Controlling large 7-segment displays via serial
By: Nathan Seidle, SparkFun Electronics
Modified: Alasdair Allan, Babilim Light Industries
Original: February 25th, 2015
Modifications: February 3rd, 2017
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
Here's how to hook up the Arduino pins to the Large Digit Driver IN
Arduino pin 6 -> CLK (Green on the 6-pin cable)
5 -> LAT (Blue)
7 -> SER on the IN side (Yellow)
5V -> 5V (Orange)
Power Arduino with 12V and connect to Vin -> 12V (Red)
GND -> GND (Black)
There are two connectors on the Large Digit Driver. 'IN' is the input side that should be connected to
your microcontroller (the Arduino). 'OUT' is the output side that should be connected to the 'IN' of addtional
digits.
Each display will use about 150mA with all segments and decimal point on.
*/
#include <EEPROM.h>
byte segmentClock = 6;
byte segmentLatch = 5;
byte segmentData = 7;
String readString;
int addr = 0;
void setup() {
Serial.begin(9600);
Serial.println("Network Counter");
pinMode(segmentClock, OUTPUT);
pinMode(segmentData, OUTPUT);
pinMode(segmentLatch, OUTPUT);
digitalWrite(segmentClock, LOW);
digitalWrite(segmentData, LOW);
digitalWrite(segmentLatch, LOW);
int n = EEPROM.read(addr);
showNumber(n);
}
void loop() {
while (Serial.available()) {
char c = Serial.read();
readString += c;
delay(2);
}
if (readString.length() >0) {
Serial.println(readString);
int n = readString.toInt();
showNumber(n);
EEPROM.update(addr, n);
readString = "";
}
}
void showNumber(float value) {
int number = abs(value);
for (byte x = 0 ; x < 2 ; x++) {
int remainder = number % 10;
postNumber(remainder, false);
number /= 10;
}
digitalWrite(segmentLatch, LOW);
digitalWrite(segmentLatch, HIGH);
}
void postNumber(byte number, boolean decimal) {
#define a 1<<0
#define b 1<<6
#define c 1<<5
#define d 1<<4
#define e 1<<3
#define f 1<<1
#define g 1<<2
#define dp 1<<7
byte segments;
switch (number) {
case 1: segments = b | c; break;
case 2: segments = a | b | d | e | g; break;
case 3: segments = a | b | c | d | g; break;
case 4: segments = f | g | b | c; break;
case 5: segments = a | f | g | c | d; break;
case 6: segments = a | f | g | e | c | d; break;
case 7: segments = a | b | c; break;
case 8: segments = a | b | c | d | e | f | g; break;
case 9: segments = a | b | c | d | f | g; break;
case 0: segments = a | b | c | d | e | f; break;
case ' ': segments = 0; break;
case 'c': segments = g | e | d; break;
case '-': segments = g; break;
}
if (decimal) segments |= dp;
for (byte x = 0 ; x < 8 ; x++) {
digitalWrite(segmentClock, LOW);
digitalWrite(segmentData, segments & 1 << (7 - x));
digitalWrite(segmentClock, HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment