7 Segment decoder

7 Segment for Node-RED

A function node I used to convert a number between 0 and 9 out to an Arduino connected to a 7 segment.

[{"id":"862162cb.79dea","type":"arduino-board","device":"/dev/cu.usbmodemfa131"},{"id":"697b2253.9684dc","type":"inject","name":"Every sec","topic":"","payload":"1","payloadType":"none","repeat":"1","crontab":"","once":false,"x":154,"y":420,"z":"df8f5eb6.2070a","wires":[["3626863f.c9d97a"]]},{"id":"9151b6c6.6eae48","type":"arduino out","name":"7-bottom-middle","pin":"3","state":"OUTPUT","arduino":"862162cb.79dea","x":888,"y":259,"z":"df8f5eb6.2070a","wires":[]},{"id":"dd37cf53.22c83","type":"arduino out","name":"2-bottom-left","pin":"2","state":"OUTPUT","arduino":"862162cb.79dea","x":876,"y":86,"z":"df8f5eb6.2070a","wires":[]},{"id":"399c3fe9.c663c","type":"arduino out","name":"4-middle","pin":"5","state":"OUTPUT","arduino":"862162cb.79dea","x":863,"y":155,"z":"df8f5eb6.2070a","wires":[]},{"id":"e3cddc37.1c322","type":"arduino out","name":"1-top-left","pin":"4","state":"OUTPUT","arduino":"862162cb.79dea","x":863,"y":51,"z":"df8f5eb6.2070a","wires":[]},{"id":"63ea629f.9c159c","type":"arduino out","name":"5-top-right","pin":"7","state":"OUTPUT","arduino":"862162cb.79dea","x":869,"y":190,"z":"df8f5eb6.2070a","wires":[]},{"id":"4e3c455b.b1c3bc","type":"arduino out","name":"3-top-middle","pin":"6","state":"OUTPUT","arduino":"862162cb.79dea","x":875,"y":121,"z":"df8f5eb6.2070a","wires":[]},{"id":"7f347508.80cb8c","type":"arduino out","name":"6-bottom-right","pin":"8","state":"OUTPUT","arduino":"862162cb.79dea","x":880,"y":225,"z":"df8f5eb6.2070a","wires":[]},{"id":"558b0808.aa74f8","type":"function","name":"7 Segment Decoder","func":"var on = { payload: 1 };\nvar off = { payload: 0 };\n\n\nif (msg.payload == 1) {\n   return [ on, on, off, off, off, off, off ];\n} else if (msg.payload == 2) {\n   return [ off, on, on, on, on ,off, on ];\n} else if (msg.payload == 3) {\n   return [ off, off, on, on, on ,on, on ];\n} else if (msg.payload == 4) {\n   return [ on, off, off, on, on ,on, off ];\n} else if (msg.payload == 5) {\n   return [ on, off, on, on, off ,on, on ];\n} else if (msg.payload == 6) {\n   return [ on, on, on, on, off ,on, on ];\n} else if (msg.payload == 7) {\n   return [ off, off, on, off, on ,on, off ];\n} else if (msg.payload == 8) {\n   return [ on, on, on, on, on ,on, on ];\n} else if (msg.payload == 9) {\n   return [ on, off, on, on, on ,on, on ];\n} else if (msg.payload == 'off') {\n   return [ off, off, off, off, off ,off, off ];\n} else if (msg.payload == 0) {\n   return [ on, on, on, off, on ,on, on ];\n}else {\n   return [ on, on, on, on, off ,off, on, ];\n}\n","outputs":"7","x":586,"y":153,"z":"df8f5eb6.2070a","wires":[["e3cddc37.1c322"],["dd37cf53.22c83"],["4e3c455b.b1c3bc"],["399c3fe9.c663c"],["63ea629f.9c159c"],["7f347508.80cb8c"],["9151b6c6.6eae48"]]},{"id":"1524975a.eadb69","type":"inject","name":"","topic":"","payload":"1","payloadType":"string","repeat":"","crontab":"","once":false,"x":156,"y":58,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"271612af.d8e9ee","type":"inject","name":"","topic":"","payload":"off","payloadType":"string","repeat":"","crontab":"","once":false,"x":156,"y":381,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"dfca824b.20358","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":159,"y":460,"z":"df8f5eb6.2070a","wires":[["c822671.f37dd98"]]},{"id":"3f74fe26.c08b02","type":"inject","name":"","topic":"","payload":"2","payloadType":"string","repeat":"","crontab":"","once":false,"x":157,"y":94,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"b314a25f.4ceb6","type":"inject","name":"","topic":"","payload":"3","payloadType":"string","repeat":"","crontab":"","once":false,"x":157,"y":128,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"a62b85e.f59d478","type":"inject","name":"","topic":"","payload":"4","payloadType":"string","repeat":"","crontab":"","once":false,"x":158,"y":163,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"2ac3c80a.d53c38","type":"inject","name":"","topic":"","payload":"5","payloadType":"string","repeat":"","crontab":"","once":false,"x":159,"y":198,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"6533b075.9acc5","type":"inject","name":"","topic":"","payload":"6","payloadType":"string","repeat":"","crontab":"","once":false,"x":159,"y":233,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"b2d29b5a.4d2d68","type":"inject","name":"","topic":"","payload":"7","payloadType":"string","repeat":"","crontab":"","once":false,"x":158,"y":269,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"508a8453.af757c","type":"inject","name":"","topic":"","payload":"8","payloadType":"string","repeat":"","crontab":"","once":false,"x":157,"y":306,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"8a0da65e.75f258","type":"inject","name":"","topic":"","payload":"9","payloadType":"string","repeat":"","crontab":"","once":false,"x":156,"y":344,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"3626863f.c9d97a","type":"function","name":"Counter","func":"context.count = context.count || 0; \nif (context.count == 10) {\n\tcontext.count = 0;\n\treturn msg;\n} else {  \n\tcontext.count += 1;\n\tmsg.payload = context.count;\n\treturn msg;\n}","outputs":1,"x":359,"y":375,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"67555f4a.98aaa","type":"inject","name":"","topic":"","payload":"0","payloadType":"string","repeat":"","crontab":"","once":false,"x":157,"y":24,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"c822671.f37dd98","type":"random","name":"","low":"0","high":"9","inte":"true","x":357,"y":431,"z":"df8f5eb6.2070a","wires":[["558b0808.aa74f8"]]},{"id":"20f411e1.df0bee","type":"comment","name":"Accepts a payload between 0 and 9 and off","info":"","x":544,"y":62,"z":"df8f5eb6.2070a","wires":[]}]
cappern

Flow Info

created 2 years, 9 months ago

Node Types

Core
  • arduino out (x7)
  • arduino-board (x1)
  • comment (x1)
  • function (x2)
  • inject (x13)
Other
  • random (x1)

Tags

  • 7-segment
  • arduino
  • raspberry-pi
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option