Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
BBC Micro:bit in Practice

You're reading from   BBC Micro:bit in Practice A hands-on guide to building creative real-life projects with MicroPython and the BBC Micro:bit

Arrow left icon
Product type Paperback
Published in Dec 2022
Publisher Packt
ISBN-13 9781804610121
Length 292 pages
Edition 1st Edition
Arrow right icon
Authors (3):
Arrow left icon
Sandeep Saini Sandeep Saini
Author Profile Icon Sandeep Saini
Sandeep Saini
Mr. Ashwin Pajankar Mr. Ashwin Pajankar
Author Profile Icon Mr. Ashwin Pajankar
Mr. Ashwin Pajankar
Abhishek Sharma Abhishek Sharma
Author Profile Icon Abhishek Sharma
Abhishek Sharma
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Part 1: Getting Started with the BBC Micro:bit
2. Chapter 1: Introduction to the BBC Micro:bit FREE CHAPTER 3. Chapter 2: Setting Up the Micro:bit and Using Code Editors 4. Chapter 3: Python Programming Essentials 5. Chapter 4: Advanced Python 6. Part 2: Programming Hardware with MicroPython
7. Chapter 5: Built-in LED Matrix Display and Push Buttons 8. Chapter 6: Interfacing External LEDs 9. Chapter 7: Programming External Push Buttons, Buzzers, and Stepper Motors 10. Part 3: Filesystems and Programming Analog I/O
11. Chapter 8: Exploring the Filesystem 12. Chapter 9: Working with Analog Input and PWM 13. Part 4: Advanced Hardware Interfacing and Applications
14. Chapter 10: Working with Acceleration and Direction 15. Chapter 11: Working with NeoPixels and a MAX7219 Display 16. Chapter 12: Producing Music and Speech 17. Chapter 13: Networking and Radio 18. Chapter 14: Advanced Features of the Micro:bit 19. Chapter 15: Wearable Computing and More Programming Environments 20. Index 21. Other Books You May Enjoy

Handling multiple analog devices

After going through the PWM signals section, it is now time to connect more than one analog device to the Micro:bit. In this section, we will connect two analog devices, one as an input with read_analog() and another as an output device controlled with write_analog(). In Figure 9.8, at pin 0, a potentiometer is connected, and at pin 1, a servo motor is connected. Both devices are provided with a 3 V supply to complete the electrical circuit. To control the servo motor, a potentiometer passes the voltage levels acting as input values to the servo motor. The servo motor will rotate according to the input from the potentiometer:

Figure 9.8 – Connecting the potentiometer as input device and the servo motor as an output device to the Micro:bit

Figure 9.9 shows both a program and its output in the shell window:

Figure 9.9 – Operating the servo motor through a potentiometer using the Micro:bit

...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime