element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Enchanted Objects
  • Challenges & Projects
  • Design Challenges
  • Enchanted Objects
  • More
  • Cancel
Enchanted Objects
Blog Yet another way of blinking an LED on the Arduino
  • 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: 18 Jun 2015 8:31 AM Date Created
  • Views 1930 views
  • Likes 3 likes
  • Comments 7 comments
  • enchanted_cottage
  • enchanted_objects
  • arduino
Related
Recommended

Yet another way of blinking an LED on the Arduino

Workshopshed
Workshopshed
18 Jun 2015

When I was making the Topsy Turvy Clock I created a non blocking delay class so that the Arduino could be doing other things whilst waiting for a timeout. This avoids the use of the delay function which otherwise "blocks" the operation until the timeout is completed. I realised that this same technique could be used to control the flashing of the RGB LED. This will need to be expanded to handle the colour cycling which will indicate that the Wifi settings need configuring.

 

Code: https://github.com/Workshopshed/EnchantedObjects/tree/master/Code/Examples/Blinker

 

Example Usage

Here's an example of the blinking code using the LED on pin 13.

 

#include "Blink.h"
Blinker b(1,0);

void setup() {
  b.Blink(Short_Blink);
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, b.Level());
  //Do other things here as desired
}

 

 

Virtual Prototyping

 

As an experiment the code was uploaded to 123D circuits.

 

image

https://123d.circuits.io/circuits/868830-blinker-class

 

This allowed the example to be tested from a web page without the need for actually having an Arduino plugged into the computer.

 

Next: Swapping out the bridge

  • Sign in to reply

Top Comments

  • crjeder
    crjeder over 10 years ago in reply to Workshopshed +2
    Yes, recycling is good! (even when unused code does not pollute the environment )
  • Workshopshed
    Workshopshed over 10 years ago in reply to mcb1 +2
    I shall leave that as an exercise for the readers
  • mcb1
    mcb1 over 10 years ago +1
    Why didn't you just do it in the code, rather than add the extra library.? The example "BlinkwithoutDelay" (yes stupid name) uses the same millis Timer as you've used. I've always advacated for avoiding…
Parents
  • mcb1
    mcb1 over 10 years ago

    Why didn't you just do it in the code, rather than add the extra library.?

    The example "BlinkwithoutDelay" (yes stupid name) uses the same millis Timer as you've used.

     

    I've always advacated for avoiding using Delay whenever possible.

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 10 years ago in reply to mcb1

    Mark,

    I come from a software background so try to apply SOLID principles whenever I can to get code that can be easily maintained. For my example the class does seem a little small but once I've added in the colour cycle then it will not be so trivial.

    http://code.tutsplus.com/series/the-solid-principles--cms-634

     

    In practical terms it means that I've got one line of code to set the type of blinking, currently "solid, short, long" and one line to get the level for the output. There's no dependency between the blinking and output device so I can test using LED13 but swap over to use the Infineon LED board once I'm happy it works. If I decide to add a different type of blinking then my output code does not change just the code that determines the flashing.

     

    It also means that as projects get bigger it's easier to manage. I don't put my classes into the libraries folders but incorporate them into the project. Here's what my current work in progress looks like (blinker not yet added), what you can see is all of the .ino file.

    https://github.com/Workshopshed/EnchantedObjects/tree/master/Code/DemoController

    image

    In theory I could also drop blinker into a unit test framework. I've never tried unit testing with C++ / Arduino but it does mean that you can refactor code much more easily without worrying that you are going to break things.

     

    Cheers,

     

    Andy

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

    Yes, recycling is good!

     

    (even when unused code does not pollute the environment image)

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago in reply to Workshopshed

    Andy

    I can see your reasons .....

    In your example the times are fixed.

      switch (Mode) {
        case Short_Blink:
            _onDuration = 250;
            _offDuration = 250;
            break;
        case Long_Blink:
            _onDuration = 1000;
            _offDuration = 2000;
          break;

     

    So the example doesn't translate for everyone unless you can send a different time.

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 10 years ago in reply to mcb1

    I shall leave that as an exercise for the readers

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Workshopshed
    Workshopshed over 10 years ago in reply to mcb1

    I shall leave that as an exercise for the readers

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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 © 2025 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