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

Set Brightness with a Script

Changing Brightness Digitally

A binary value can hold one of two states: 1 or 0.  Up to this point, we’ve been using those 1/0 binary values to turn lights on and off with pin14.write_digital(1) and pin14.write_digital(0).

In electronics, digital to analog conversion is used to make things seem like they are analog (varying continuously).  For example, with the LED in this activity, you will use the digital values of 0 through 1023 and back to 0 to make the LED light take small steps from dim to bright and then to dim again.  The steps will be so small that human eyes cannot perceive them, so it is called “digital to analog conversion”.    

The pin14.write_analog() method accepts arguments from 0 to 1023 to set the LED’s brightness from off to full brightness.  Here are some examples of write_analog calls that adjust how brightly the P14 LED shines.

pin14.write_analog(1023)             # Max brightness
pin14.write_analog(512)              # half brightness
pin14.write_analog(256)              # quarter brightness
pin14.write_analog(1)                # 1/1024th of full brightness

In this activity, you will experiment with write_analog and scripts that control the brightness of the P14 LED.  You will also use for loops to make this brightness seem to vary continuously (analog).

Circuit

For this activity, you will re-use the same setup and LED circuit from Connect and Blink a Light.

  • Check your setup and circuit to make sure it matches the one shown below. If it does not, return to Connect and Blink a Light and bring it up to date.

 


Printer-friendly version
Solutions
Prev
Script and Tests
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress