Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 137 lines (104 sloc) 2.558 kb
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
1 <!--remove-start-->
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
2 # Seven Segment
3
4 Run with:
5 ```bash
6 node eg/seven-segment.js
7 ```
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
8 <!--remove-end-->
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
9
10 ```javascript
11 /**
12 * This example uses a single seven-segment display (common anode) and a
13 * 74HC595 shift register. See docs/breadboard/seven-segment.png for wiring.
14 */
15 var five = require("johnny-five"),
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
16 board;
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
17
18 board = new five.Board();
19
20 board.on("ready", function() {
21 var isCommonAnode, digits, segments, sr, led, i;
22
23 /*
24
25 This assumes the segments are as follows:
26
27 A
28 ---
29 F | | B
30 --- <---- G
31 E | | C
32 ---
33 D o DP
34
35 */
36
37 isCommonAnode = true;
38 digits = [];
39
40 // .GFEDCBA
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
41 digits[0] = parseInt("00111111", 2); // 0
42 digits[1] = parseInt("00000110", 2); // 1
43 digits[2] = parseInt("01011011", 2); // 2
44 digits[3] = parseInt("01001111", 2); // 3
45 digits[4] = parseInt("01100110", 2); // 4
46 digits[5] = parseInt("01101101", 2); // 5
47 digits[6] = parseInt("01111101", 2); // 6
48 digits[7] = parseInt("00000111", 2); // 7
49 digits[8] = parseInt("01111111", 2); // 8
50 digits[9] = parseInt("01101111", 2); // 9
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
51
52 segments = {
53 // .GFEDCBA
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
54 a: parseInt("00000001", 2),
55 b: parseInt("00000010", 2),
56 c: parseInt("00000100", 2),
57 d: parseInt("00001000", 2),
58 e: parseInt("00010000", 2),
59 f: parseInt("00100000", 2),
60 g: parseInt("01000000", 2),
61 dp: parseInt("10000000", 2)
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
62 };
63
64 sr = new five.ShiftRegister({
65 pins: {
66 data: 2,
67 clock: 3,
68 latch: 4
69 }
70 });
71
72 led = new five.Led(5);
73
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
74 function invert(num) {
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
75 return ((~num << 24) >> 24) & 255;
76 }
77
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
78 sr.digit = function(num) {
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
79 sr.clear();
80
81 sr.send(
82 isCommonAnode ? invert(digits[num]) : digits[num]
83 );
84 };
85
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
86 sr.segment = function(s) {
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
87 sr.clear();
88
89 sr.send(
90 isCommonAnode ? invert(segments[s]) : segments[s]
91 );
92 };
93
94 sr.clear = function() {
95 sr.send(
96 isCommonAnode ? 255 : 0
97 );
98 };
99
100 i = 9;
101
102 function next() {
103 led.stop();
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
104 sr.digit(i--);
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
105
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
106 if (i < 0) {
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
107 i = 9;
108 led.strobe(50);
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
109 setTimeout(next, 2000);
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
110 } else {
ca469ef Rick Waldron Regenerate all of the doc/example files
authored
111 setTimeout(next, 1000);
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
112 }
113 }
114
115 next();
116 });
117
118 ```
119
938e295 Rick Waldron Removes @device tags and replaces with arbitrary @markdown regions
authored
120
1b7af18 Rick Waldron Change "Breadboard" heading to "Breadboard/Illustration"
authored
121 ## Breadboard/Illustration
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
122
938e295 Rick Waldron Removes @device tags and replaces with arbitrary @markdown regions
authored
123
51b65fd Adam Hyland Update docs to use relative links.
Protonk authored
124 ![docs/breadboard/seven-segment.png](breadboard/seven-segment.png)
125 [docs/breadboard/seven-segment.fzz](breadboard/seven-segment.fzz)
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
126
127
128
129
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
130 <!--remove-start-->
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
131 ## License
8c167ba Rick Waldron Update copyright year
authored
132 Copyright (c) 2012, 2013, 2014 Rick Waldron <waldron.rick@gmail.com>
6ee1faa Rick Waldron Regenerate the docs examples
authored
133 Licensed under the MIT license.
8c167ba Rick Waldron Update copyright year
authored
134 Copyright (c) 2014, 2015 The Johnny-Five Contributors
93431a1 Rebecca Murphey seven segment display example & wiring diagram. Closes gh-70
rmurphey authored
135 Licensed under the MIT license.
329525f Rick Waldron Add removal delimiters to eg template. Update examples
authored
136 <!--remove-end-->
Something went wrong with that request. Please try again.