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

    I've been reading a little about the GCC compiler, it does have the built in option of inlining functions that it knows are safe to do so. So is there a reason why I'd go for a in-line function rather than a class based approach?

     

    As an aside, I swapped out a few variables with smaller data types e.g. my servo angle is constrained between 50 and 100 degrees so I can fit that into a uint8_t rather than an int. That saved be about 60 bytes. Dropping the Process.h library saves me about 3400 bytes although I still need to write the code to send the message to Serial1, although I'm optimistic that I'll be able to write my bit in less than that.

     

    I also tried an experiment adding an unused function (with quite a few instructions), that only added 6 bytes to the total so I'd guess that the compiler is doing some optimisations there.

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

    Yes, nowadays compilers a quite good in optimization. GCC -O options are controlling the optimization. For debugging you do not want inlining for instance therefore it could be turned off. Most of the time it is a trade-off between space and time so you have to specify that (-Ofast vs. -Os) Sometimes optimization has negative side effects, those are not part of any -O options, they must be turned on individually like -fno-defer-pop.

    Normally you have to try several setting until you get a good result.

     

    see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options for details.

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

    Yes, nowadays compilers a quite good in optimization. GCC -O options are controlling the optimization. For debugging you do not want inlining for instance therefore it could be turned off. Most of the time it is a trade-off between space and time so you have to specify that (-Ofast vs. -Os) Sometimes optimization has negative side effects, those are not part of any -O options, they must be turned on individually like -fno-defer-pop.

    Normally you have to try several setting until you get a good result.

     

    see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options for details.

    • Cancel
    • Vote Up +1 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