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
CodeBug
  • Learn
  • Learning Center
  • STEM Academy
  • CodeBug
  • More
  • Cancel
CodeBug
Blog 10 CodeBug Projects in 10 Days: Flashing an LED
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join CodeBug to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: element14Dave
  • Date Created: 23 Sep 2015 8:17 PM Date Created
  • Views 3578 views
  • Likes 20 likes
  • Comments 18 comments
  • codebug_beginner
Related
Recommended

10 CodeBug Projects in 10 Days: Flashing an LED

element14Dave
element14Dave
23 Sep 2015
imageIntroducing CodeBug!

image  What is CodeBug

image  10 CodeBug Projects in 10 Days

image  Are You a STEM Educator?

 

Getting Started:

image

We start the project by visiting the CodeBug website http://www.codebug.co.uk and creating an account. It only takes a few minutes. While logged in, clock on Create to start a new project. Don't forget to save your work!

 

The interface for CodeBug contains an area to the right of the screen with is the primary programming interface. There are a series of menus that are used to store the blocks with can be dragged from the menus into the coding area. Good blocks are made to connect together, and that is what we intend to do!

 

Now that you have familiarized yourself with the interface, let's get started on an intermediate project Thomas Macpherson-Pope pulled together from CodeBug.org.uk

 

 

What you need:

CodeBug

Micro USB Cable

CR2032 Battery

Crocodile  Clips

LEDs

Computer

 

The Project

 

CodeBug’s legs can be used to turn LEDs (and other things!) on or off. In this mode the legs are called Outputs.

Before we get into how to Flash an LED, lets talk a little bit about  how LEDs work

LED stands for light emitting diode, they are essentially really small light bulbs. So firstly, what is a diode? A diode is simply something that lets electricity flow in one direction and not the other.

LEDs create light because they are made of two different materials. One of the materials requires the electrons to have less energy so they lose their extra energy in the form of light.

Now that we have  basic understanding of how an LED works, lets get to work on how to flash one using the CodeBug!

We will start by connecting a red croc-clip to the power leg (PWR) of CodeBug and another croc-clip to leg 0.

image

LEDs have two leads and one is longer than the other. The longer lead is the positive one, so connect this to the red croc-clip that is attached to the PWR leg on CodeBug. The shorter lead is the negative one, so connect this to the croc-clip attached to leg 0. LEDs will also sometimes have a flat edge on the plastic casing, this indicates the negative side.

image


Now that the LED is hooked up to the bug, let's set up the program.

 

First we will need to set up the Legs in the Emulator. To set the Legs of the CodeBug we will need to first configure the Emulator. To do this we will need to open the emulator configuration via the settings cog on the emulator. Tick the Show Leg Controls box. Click on the Configure Emulator button to complete the settings change. The Emulator will now show the status of the CodeBug's legs with blue arrows. The arrow pointing to the legs is the Input, away from the legs is the Output. When the background of the leg is red, the leg is at Power, when the leg is at black, it is Ground.

image

 

Now that the Emulator has been configured, we can begin programming the legs. To do this we will need to click on the Cog of the Start block. From the popup we can drag the Leg Input/Output block into the Start block on the right. Because we want to control an LED we will need to tell CodeBug to use Leg 0 as Output for the purposes of this project we will set the Leg at "0" as "output".

 

image

 

 

 

Now we want to set Leg 0 to Ground so the current flows from CodeBug's power leg, through the LED, and to 0. To do this we will need to drag in a Set Leg block from the Inputs/Outputs menu and snap it to our Start block.

 


image

 

To flash an LED we will need to turn it on and off with a pause in between. From the Basic Menu drag in a Pause block and snap it beneath your Set Leg block. From the Inputs/Outputs menu drag in another Set Leg block and snap it beneath your Pause block. Set this new Set Leg block's second number box to 1. Because we will want this LED to continuously flash, lets add a Loop. We will go to the Loops menu and drag in a Repeat While True block onto the work space. Next we will snap in the Loop block to the Start block and move the code into the Loop.  From the Basics menu we drag in another Pause block, moving that inside the While loop, underneath the second Set Leg block.

 

image

Now it's time to see if it works via the Emulator...

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

With the program working we can now send that over to the CodeBug...

 

With the code working, click on Download, it's just under the simulator controls. When the code downloads, plug in a USB to micro USB into your computer. While holding Button A of your CodeBug also insert the micro USB to the CodeBug. The top left LED in the matrix on the CodeBug will flash. Your computer should also recognize the CodeBug as a USB drive on your computer. Copy the code downloaded from the CodeBug website to the USB drive and run the program by pressing Button B.

 

REMIX THIS PROJECT

 

 

See more CodeBug projects and learn how you can get one of your own by visiting: 10 CodeBug Projects in 10

  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 9 years ago in reply to mcb1 +4
    Update It seems that there is a 330 ohm resistor in series with each leg. The schematic has been published here. http://www.codebug.org.uk/assets/creativecommons/codebug-schematics.pdf Mark credit for…
  • mcb1
    mcb1 over 9 years ago +3
    Dave Out of curiosity what limits the current the pin can supply. I would have thought a resistor in series is good practice ... mainly because not all micors have inbuilt limiting (either by battery or…
  • shabaz
    shabaz over 9 years ago in reply to mcb1 +3
    mcb1 wrote: I've often seen people driving LED's at 20mA, when 5 or 10mA will happily serve the purpose Some of the water-clear ones are visibly red (even in a bright room) at 100uA, and can even…
  • volly
    volly over 9 years ago

    Yep....haven't we all learn't a lot from the Raspberry pi and BeagleBoneBlack LED/resistor, infinite number of projects and what-if....scenarios.....

     

    Still cool to revisit and echo here....

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    Cool projects....

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 9 years ago in reply to Problemchild

    Problemchild

    You can have a cable that goes to the grill

    Yep had something similar when we lived in town.

    (Mine was a LOT cheaper)

     

    Unfortunately this one isn't parked near the mains source ...

    Sometimes it gets left in random spots, so maybe solar might be the answer.

     

    but thanks for the thoughts.

    Mark

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

    Re the car have you tried one of these:

    http://www.amazon.co.uk/TecMate-Optimate-4-battery-charger-x/dp/B001DI09WW/ref=sr_1_8?ie=UTF8&qid=1445688248&sr=8-8&keywords=accumate+car+battery+charger

     

    You can have a cable that goes to the grill so  you charge all the time then just pull it out before driving off.. It would be better for the battery than been flat!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Problemchild
    Problemchild over 9 years ago in reply to shabaz

    Good photo Shabaz I think you would need to play mere with the ambient vs produced light o get a nicer pic!

    The multi die LEDs would be more interesting as well since they are not all perfectly matched and would vary especially at low currents

    • 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 © 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