For my indicators, I wanted a simple function that would blink them 5 times then stop. I found a suitable piece of code on Stack Overflow which did the same thing for some flashing text and ported it across to node. However, I did not have the Edison to hand so pondered how I would test it. A quick google found mraaStub a mock version of mraa that you can use on platforms that don't have mraa hardware. I installed this and discovered that it needs a logging package called "winston" which I also installed. I also had to tweak the mraaStub library so that it would log by default. My version can be found at https://github.com/Workshopshed/UpcyclingDesignChallenge/tree/master/mraaStub
//Simple function to test the indicator
var platform = require('os').platform();
var m;
if (platform === 'win32') {
m = require('mraaStub'); //also needs winston
} else {
m = require('mraa');
}
var myLed = new m.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2)
myLed.dir(m.DIR_OUT); //set the gpio direction to output
function indicate() {
var count = 1;
var ledState = true;
var intervalId = setInterval(function() {
myLed.write(ledState?1:0);
ledState = !ledState;
if (count++ >= 10) {
clearInterval(intervalId);
}
}, 500);
};
indicate();
Here's how it looks in Visual Studio Code when it is running.
Reference
javascript - Making text blink a certain number of times? - Stack Overflow
https://www.npmjs.com/package/winston
https://www.npmjs.com/package/mraaStub
https://github.com/Workshopshed/UpcyclingDesignChallenge/blob/master/Tests/test6.js
https://github.com/Workshopshed/UpcyclingDesignChallenge/tree/master/mraaStub
Previous Posts
Upcycle It Blogs tagged with upcycled_interactiveracecardriver

Top Comments