2901 views|2 replies

188

Posts

0

Resources
The OP
 

[Micropython Tutorial] +2 Vibration detection to control LED brightness [Copy link]

 
This post was last edited by Feiyangzizi on 2018-6-19 20:11 I. Preface I have introduced how to configure Tera Term VT [/url] before. Next, let's do a simple experiment. I watched the Internet and tested the LED. I suddenly found that I could use the six axes on the board to collect data. When swinging, I called intensity to dim the LED. The larger the swing, the larger the absolute value of the output data. In this way, the larger the PWM modulation value, the brighter the LED (4). Second, vibration detection controls LED brightness In pyb, there are multiple library functions that can be called directly. Enter help() in Tera Term TV, and many functions that can be called will pop up This time, we use the three functions pyb.LED(), pyb.Accel(), and pyb.delay(). First, define led=pyb.LED(4) to specify the special LED4 light, which can adjust the brightness. Then define a PWM=0, variable definition and assignment. Then, in the while loop, read the X, Y, and Z values of the three-axis sensor continuously and add them to get the PWM value. Finally, modulate the LED4 light, which will make the change in any aspect of the three-axis sensor change the LED light. The video will be updated later and is still under review. . . . . .
  1. >>> led=pyb.LED(4) >>> acc=pyb.Accel() >>> pwm=0 >>> while True: ... pwm=(acc.x()+acc.y()+acc.z())%255 ... led.intensity(pwm) ... print(acc.x(),acc.y(),acc.z()) ... pyb.delay(100) ... ...
复制代码
Three, Postscript I feel that PyboardCN2 is quite fun to use. You can use the existing resources to configure a variety of combinations, and you can debug directly without the trouble of compiling and burning. . This content is originally created by EEWORLD forum user Fei Yang Zi Ji. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source




Latest reply

Learned  Details Published on 2018-6-20 08:26
 
 

188

Posts

0

Resources
2
 
 
 

1903

Posts

0

Resources
3
 
Learned
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list