element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog [Upcycle It] Interactive Race Car Driver - Indicators - Offline testing with node and mraaStub
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Workshopshed
  • Date Created: 16 May 2017 5:22 PM Date Created
  • Views 574 views
  • Likes 6 likes
  • Comments 2 comments
  • upcycled_interactiveracecardriver
Related
Recommended

[Upcycle It] Interactive Race Car Driver - Indicators - Offline testing with node and mraaStub

Workshopshed
Workshopshed
16 May 2017

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.

image

 

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

  • Sign in to reply

Top Comments

  • Workshopshed
    Workshopshed over 8 years ago +1
    One simplification of this approach is to rename the "node_modules\mraaStub" folder on the Windows development machine to be "node_modules\mraa" then code can be simplified to be: var m; m = require(…
  • Workshopshed
    Workshopshed over 8 years ago

    Have updated this to include pwm support

     

    https://github.com/Workshopshed/UpcyclingDesignChallenge/tree/master/mraaStub

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 8 years ago

    One simplification of this approach is to rename the "node_modules\mraaStub" folder on the Windows development machine to be "node_modules\mraa" then code can be simplified to be:

     

    var m;  
    m = require('mraa');

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube