7 Photosensitive gesture

From Banana Pi Wiki
Revision as of 16:50, 18 February 2019 by Sinovoip (talk | contribs) (Photosensitive gesture recognition)
Jump to: navigation, search

Photosensitivity and gesture detection

photosensitive sensor

Careful students may have found, in the bpibit board above two such things, yes, these two things are photosensitive sensor. It is a light-sensitive sensor that, through a sampling circuit, converts the intensity of light into the magnitude of the voltage.

Bpisenser.png

Its model is PTSMD021 click to learn more

Get the intensity of the light

There is a light module in the firmware. We can easily get the light intensity by calling the function in this module.

sample code

import light
from time import sleep_ms
R = light.Intensity(39)
L = light.Intensity(36)
while True:
   print('R=',R.read())
   print('L=',L.read())
   sleep_ms(1000)
  • To use the module of light, we first need to import this module, which can be imported by import light. Similarly, we need a delay function so we should import the function sleep_ms().
  • What do light.Intensity(39) and light.Intensity(36) mean? it actually doing here is initializing the photosensitive sensor
  • But why 36 and 39? Well, that's a question that we'll save for the last part of the course for you to fill in, which you probably don't understand right now.
  • After the initialization is complete, we can call the read() function to get the light intensity. The read() function returns a value of 0-1000, which indicates the current approximate light intensity
  • We can now print out the data serial port

Message.png


Photosensitive gesture recognition

We already know from above that we have two light sensors on our board, so let's use those two light sensors to do something interesting, like simple gesture recognition

We preset Gesture() in our light module, which allows us to achieve simple Gesture recognition, so let's try it out.