315
In a previous post we showed how to connect a MAX 7219 7 Segment display – Espruino and MAX7219 7 segment display example . Here are some more examples
Counter example
This example increments a counter and displays the result on the 7 segment display
[codesyntax lang=”javascript”]
require("MAX7219"); SPI1.setup({mosi:B5, sck:B3}); var disp = require("MAX7219").connect(SPI1,B4); disp.on(); setTimeout(function() { var n = 0; setInterval(function() { disp.set(n++); // it can display integers }, 100); }, 2000);
[/codesyntax]
Display a random number
This example just displays a random nuber every second between 1 and 1000
[codesyntax lang=”javascript”]
require("MAX7219"); SPI1.setup({mosi:B5, sck:B3}); var disp = require("MAX7219").connect(SPI1,B4); disp.on(); setInterval(function() { // get a random number between 1 and 1000 var n = 1 + Math.floor(Math.random()*1000); disp.set(n); }, 1000);
[/codesyntax]
Simply random dice
This example when you press the user button on your Espruino will generate a random number between 1 and 6 and display it on your Espruino
[codesyntax lang=”javascript”]
require("MAX7219"); SPI1.setup({mosi:B5, sck:B3}); var disp = require("MAX7219").connect(SPI1,B4); disp.on(); setWatch(function(e) { var n = 1 + Math.floor(Math.random()*6); disp.set(n); }, BTN1, { repeat: true, edge: 'rising' });
[/codesyntax]