Difference between revisions of "7 Photosensitive gesture"

From Banana Pi Wiki
Jump to: navigation, search
(sample code)
Line 24: Line 24:
 
     print('L=',L.read())
 
     print('L=',L.read())
 
     sleep_ms(1000)
 
     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
 +
[[File:Message.png]]

Revision as of 17:48, 18 February 2019

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