Difference: Switches (1 vs. 2)

Revision 22020-05-14 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="Exercises"

Exercise 3: Switches

Introduction

Changed:
<
<
Switches exist in various incarnations. There is the simple mechanical switches: on/off or push button switches but there are also switches than turn on or off with various external conditions:
>
>
Switches exist in various incarnations. There are the simple mechanical switches: on/off or push button switches but there are also switches than turn on or off with various external conditions:
 
  • temperature
  • infra red radiation (e.g. the Passive Infrared Sensor or PIR sensor)
  • Hall switches detecting magnetic field

Revision 12020-05-06 - UliRaich

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="Exercises"

Exercise 3: Switches

Introduction

Switches exist in various incarnations. There is the simple mechanical switches: on/off or push button switches but there are also switches than turn on or off with various external conditions:

  • temperature
  • infra red radiation (e.g. the Passive Infrared Sensor or PIR sensor)
  • Hall switches detecting magnetic field
  • microphone switches which turn on when a certain noise level is detected
In this exercise we will use a mechanical push button switch

button.png

and a PIR sensor.

pir.png

Exercise 1:

The push button switch is connected to GPIO 17 on the ESP32 board.

Write a script that polls the state of the switch every 100 ms and prints state changes (only print out a message when the switch state has changed). Catch <ctrl> C to smoothly exit the program.

Check https://docs.micropython.org/en/latest/esp8266/tutorial/pins.html and https://docs.micropython.org/en/latest/esp32/quickref.html for information on how to accomplish this.

Exercise 2:

Do the same thing as in exercise 1 but use external interrupts and a callback routine to do the job.

Exercise 3:

Combine this exercise with the exercise on LEDs: Switch the builtin LED on when the button is pressed and off when it is released

-- Uli Raich - 2020-05-06

Comments

<--/commentPlugin-->

META FILEATTACHMENT attachment="button.png" attr="" comment="" date="1588755666" name="button.png" path="button.png" size="286339" user="UliRaich" version="1"
META FILEATTACHMENT attachment="pir.png" attr="" comment="" date="1588755666" name="pir.png" path="pir.png" size="327085" user="UliRaich" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback