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
  • Sense Pushbutton Presses

Sense Pushbutton Presses

How it Works

How the pushbutton_test_x2 Script Works

The pushbutton_test_x2 script started as pushbutton_test, and was adapted for two pushbuttons through the following changes: 

  • The state variable was replaced by state9 and state6. 
  • The pin6.set_pull(pin6.NO_PULL) call was repeated for pin 9: pin9.set_pull(pin9.NO_PULL).
  • The single state = pin6.read_digital() statement was replaced with two new versions, one for state6 and pin6, and the other for state9 and pin9. 
  • The print statement was expanded so that it shows values for both state9 and state6.    

Try This

The button_light_blink_x2 script is the two-button, two-light version of the button_light_blink script from the Build and Test a Pushbutton activity’s Your Turn section.

  • Enter the button_light_blink_x2 script into the micro:bit Python Editor.
  • Set the project name field to button_light_blink_x2, then click Save.
  • Click Send to micro:bit.
  • Verify that the green light connected to P13 stays off when the button connected to P6  is not pressed.
  • Press and hold the button.  Verify that the P13 light blinks while the P6 pushbutton is held down.
  • Repeat with the test for control of the P14 light with the P9 pushbutton.

 


Printer-friendly version
Script and Tests
Prev
Two-button Control
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress