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

How it Works

How led_blink_list Works

Instead of string objects like ’green’, ’yellow’, and ’red’, the list in this example contains microbit.pin objects: pin13, pin14, and pin15.

pin_list = [pin13, pin14, pin15]

while True:

 

The first time through the for pin in pin_list loop, pin gets set to pin13.  So, in the first pass, pin.write_digital(1) is really pin13.write_digital(1), which turns the P13 light on.  Likewise, pin.write_digital(0) is really pin13.write_digital(0), which turns the P13 light off.  

    for pin in pin_list:
        pin.write_digital(1)
        sleep(500)
        pin.write_digital(0)

 

The second time through the loop, pin is pin14, so pin.write_digital(1) is really pin14.write_digital(1), and pin.write_digital(0) is really pin14.write_digital(0).  The third time through the loop, pin is pin15.  So, pin.write_digital(1) and pin.write_digital(0) are really pin15.write_digital(1) and pin15.write_digital(0).  

Try This: Up/Down Sequence

Sometimes a little change can make a big difference in the way something behaves.  For example, adding just one pin to the list will make the sequence look like the lights bounce back and forth between red and green.

  • Set the project name field and line-1 comment to led_blink_try_this.
  • Modify the script as shown below, then click Save.
  • Click Send to micro:bit.
  • Verify that the sequence is now green, yellow, red, yellow, green, yellow, red, yellow, green, …

 


Printer-friendly version
Script and Tests
Prev
Zip Lists Together
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress