Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

seven segment display example & wiring diagram #70

Closed
wants to merge 2 commits into from

2 participants

@rmurphey

No library yet, but I'm working on it :) Thought this might prove useful to people in the meantime.

@rwaldron
Owner

The png is showing a broken image? :(

@rmurphey

Hrm. It opens fine locally for me. Just tried creating a new version, too, and still seems broken ... ?

@rmurphey

Opens fine for me when I pull it down to another computer, as well. Wonder if something is borked w/github?

@rwaldron
Owner

Makes sense to me. I'll land this after dog park and dinner :)

@rwaldron rwaldron closed this in 93431a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
BIN  docs/breadboard/seven-segment.fzz
Binary file not shown
View
BIN  docs/breadboard/seven-segment.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
103 eg/seven-segment.js
@@ -0,0 +1,103 @@
+/**
+ * This example uses a single seven-segment display (common anode) and a
+ * 74HC595 shift register. See docs/breadboard/seven-segment.png for wiring.
+ */
+var five = require("../lib/johnny-five.js"),
+ sr, led;
+
+var board = new five.Board()
+
+board.on("ready", function() {
+
+ /*
+
+ This assumes the segments are as follows:
+
+ A
+ ---
+ F | | B
+ --- <---- G
+ E | | C
+ ---
+ D o DP
+
+ */
+
+ var commonAnode = true;
+ var digits = [];
+
+ // .GFEDCBA
+ digits[0] = parseInt('00111111', 2); // 0
+ digits[1] = parseInt('00000110', 2); // 1
+ digits[2] = parseInt('01011011', 2); // 2
+ digits[3] = parseInt('01001111', 2); // 3
+ digits[4] = parseInt('01100110', 2); // 4
+ digits[5] = parseInt('01101101', 2); // 5
+ digits[6] = parseInt('01111101', 2); // 6
+ digits[7] = parseInt('00000111', 2); // 7
+ digits[8] = parseInt('01111111', 2); // 8
+ digits[9] = parseInt('01101111', 2); // 9
+
+ var segments = {
+ // .GFEDCBA
+ a : parseInt('00000001', 2),
+ b : parseInt('00000010', 2),
+ c : parseInt('00000100', 2),
+ d : parseInt('00001000', 2),
+ e : parseInt('00010000', 2),
+ f : parseInt('00100000', 2),
+ g : parseInt('01000000', 2),
+ dp : parseInt('10000000', 2)
+ };
+
+ sr = new five.ShiftRegister({
+ pins: {
+ data: 2,
+ clock: 3,
+ latch: 4
+ }
+ });
+
+ led = new five.Led(5);
+
+ function invert(num) {
+ return ((~num << 24) >> 24) & 255;
+ }
+
+ sr.digit = function(num) {
+ sr.clear();
+
+ var val = commonAnode ? invert(digits[num]) : digits[num];
+ sr.send(val);
+ };
+
+ sr.segment = function(s) {
+ sr.clear();
+
+ var val = commonAnode ? invert(segments[s]) : segments[s];
+ sr.send(val);
+ };
+
+ sr.clear = function() {
+ sr.send( commonAnode ? 255 : 0 );
+ };
+
+ var i = 9;
+
+ function next() {
+ led.stop();
+ sr.digit(i--);
+
+ if (i < 0) {
+ i = 9;
+ led.strobe(50);
+ setTimeout(next, 2000);
+ } else {
+ setTimeout(next, 1000);
+ }
+
+ }
+
+ next();
+
+});
Something went wrong with that request. Please try again.