Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses
  • LED Lights

LED Lights

Script and Tests

Script: led_blink

Let’s make the LED blink using a micro:bit script.

  • If it’s not already connected, connect your micro:bit module to your computer with its USB cable.
  • If you do not already have the micro:bit Python Editor open, browse to python.microbit.org in a Google Chrome or Microsoft Edge browser.
  • Set the project name field to led_blink.
  • Enter led_blink into the micro:bit Python Editor, then click Save.
    (See Save & Edit Scripts.)  
  • Click Send to micro:bit.
    (See Flash Scripts with Python Editor.)
# led_blink

from microbit import *

while True:
    pin14.write_digital(1)
    sleep(500)
    pin14.write_digital(0)
    sleep(500)

Tests

  • Verify that the green LED blinks on/off at about once every second.

There are lots of different ways to change the timing in the blinking pattern.  Try these examples to understand the cause and effect.  To test a change to the script, click Send to micro:bit.  Then, check the LED light for a changes.  

  • Try changing the sleep(500) calls to sleep(2500), then flash the modified script.  What’s the effect?
  • Try changing the sleep calls from sleep(2500) to sleep(250).  Again, flash the modified script and observe the effect.
  • Repeat using sleep(100) for both sleep calls.  Can you now predict what’s going to happen?
  • How much can you reduce the sleep arguments until it’s hard to tell that it’s blinking?
  • Try sleep(200) after the pin14.write_digital(1) call and sleep(800) after the pin14.write_digital(0) call. What happened?
  • Try reversing the sleep values so that sleep(800) follows pin14.write_digital(1) and sleep(200) follows pin14.write_digital(0). Did it have the effect you anticipated?
  • .Finally, change both sleep calls back to what you started with: sleep(500) and compare it to the previous two options.

 


Printer-friendly version
Connect and Blink a Light
Prev
How it Works
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2025 Parallax Learn • Built with GeneratePress