3814 views|7 replies

6066

Posts

4

Resources
The OP
 

"Play with pyboardCN V2" 1 Install the driver and serial port assistant to light up 4 lights [Copy link]

 
This post was last edited by damiaa on 2018-6-25 09:18 "Play with pyboardCN V2" Part 1 Install the driver and serial port assistant to light up the four lights 1. Install PUTTY or Tera Term VT. I won't go into details. When the time comes, use its serial port and configure it to 115200 N 8 1 2. Plug the board into the USB port. The pyboardCN V2 does not come with a cable, so find one yourself. A mobile phone charging cable will do. There is a problem with the serial port driver when plugging it in. The driver needs to be updated. The updated driver is in the disk that is displayed after the board is just plugged in. Be sure to remove the driver digital signature (check it online for details). 3. Open PUTTY or Tera Term VT and select the serial port. Change the configuration to 115200 N 8 1 and you will see the prompt >>>. It can be used! ! ! Note: It is better to use uPyCraft IDE, which can edit and download programs, and can also run single commands. 4. Use help() to see the prompts. Just type the command to turn the LED on and off. Haha. pyb.LED(1).on() pyb.LED(1).off() pyb.LED(2).on() pyb.LED(2).off() pyb.LED(3).on() pyb.LED(3).off() pyb.LED(4).on() pyb.LED(5).off() Actually, if we really want to program, we can't do it like this. We still have to write it in the main.py in the display disk. Otherwise it's too stupid. The above is just for fun. Specifically, open main.py with an editor and add import pyb while True: pyb.LED(1).on() pyb.delay(500) pyb.LED(1).off() pyb.delay(500) pyb.LED(2).on() pyb.delay(500) pyb.LED(2).off() pyb.delay(500) pyb.LED(3).on() pyb.delay(500) pyb.LED(3).off() pyb.delay(500) pyb.LED(4).on() pyb.delay(500) pyb.LED(4).off() pyb.delay(500) To make it more beautiful: changed import pyb def flashleds(): i = 1 for i in range(1,5): pyb.LED(i).on() pyb.delay(500) pyb.LED(i).off() pyb.delay(500) while True: flashleds() or import pyb leds = [pyb.LED(i) for i in range(1,5)] def flashleds(): i = 1 for i in range(1,5): leds.on() pyb.delay(500) leds.off() pyb.delay(500) while True: flashleds() Then re-plug the board and the display will cycle

Latest reply

This post was last edited by dcexpert on 2018-6-23 16:13An i is missing here. The correct code is as follows:import pyb leds = [pyb.LED(i) for i in range(1,5)] def flashleds(): i = 1 for i in range(5): leds[i].on() pyb.delay(500) leds[i].off() pyb.delay(500) flashleds()复制代码   Details Published on 2018-6-23 16:11
 
 

188

Posts

0

Resources
2
 
Not bad, but a bit complicated. There is a function leds = [pyb.LED(i) for i in range(1,5)] and a loop will do..

Comments

This method is very concise and can fully reflect the characteristics of the Python language. It is recommended.  Details Published on 2018-6-20 13:40
 
 
 

1w

Posts

25

Resources
3
 
Fei Yang Self-published on 2018-6-20 11:59 Not bad, but a bit complicated. There is a function leds = that can make a loop..
This method is very concise and can fully reflect the characteristics of the Python language. It is recommended.
 
 
 

1w

Posts

25

Resources
4
 
If you eject the disk every time, it will be troublesome and slow. One way is to press Ctrl-D in REPL to perform a soft reset, which will automatically synchronize the internal file system and generally avoid loss.

Comments

Thanks, I think I messed up main.py. I'll restore it later. I don't have time now. I need to do something else.  Details Published on 2018-6-20 14:45
 
 
 

6066

Posts

4

Resources
5
 
This post was last edited by damiaa on 2018-6-20 15:30
dcexpert posted on 2018-6-20 13:41 It would be troublesome and slow to exit the disk every time. One way is to press Ctrl-D in REPL to soft reset, which will automatically synchronize the internal file system, ...
Thank you, I seem to have messed up main.py. I will restore it later. I don't have time now. I have to do other things. Oh, I didn't lose boot.py and didn't see anything in it. Restoring to factory settings is effective I'm not playing anymore. I've been playing for a day. Using Ctrl-D soft reset in the command line of the serial port works very well! ! !
 
 
 

35

Posts

0

Resources
6
 
When I run this code, it does not produce 4 flashing lights, but 2. import pyb leds = [pyb.LED(i) for i in range(1,5)] def flashleds(): i = 1 for i in range(1,5): leds.on() pyb.delay(500) leds.off() pyb.delay(500) while True: flashleds() leds should be a list, and I don’t see the role of i in the for loop. I don’t know how to understand it.

Comments

An i is missing here. The correct code is as follows:  Details Published on 2018-6-25 09:26
An i is missing here. The correct code is as follows:  Details Published on 2018-6-23 16:11
 
 
 

1w

Posts

25

Resources
7
 
This post was last edited by dcexpert on 2018-6-23 16:13
mobilefone posted on 2018-6-23 15:35 When I run this code, it doesn't produce 4 flowing lights, but 2. import pyb leds = def flashleds(): i = 1 for i ...
An i is missing here. The correct code is as follows:
  1. import pyb leds = [pyb.LED(i) for i in range(1,5)] def flashleds(): i = 1 for i in range(5): leds[i].on() pyb.delay(500) leds[i].off() pyb.delay(500) flashleds()
复制代码




 
 
 

6066

Posts

4

Resources
8
 
This post was last edited by damiaa on 2018-6-25 09:28
mobilefone posted on 2018-6-23 15:35 This code does not produce 4 flashing lights, but 2. import pyb leds = def flashleds(): i = 1 for i ...
So far we have only used a single LED but the pyboard has 4 available. Let's start by creating an object for each LED so we can control each of them. We do that by creating a list of LEDS with a list comprehension. For details, please see docs.micropython.org/en. 。 。 leds = [pyb.LED(i) for i in range(1,5)] It says to create an object, and then you can control it using leds[n].on() leds[n].off() leds[n].toggle() where n is a specific value or a variable that has been assigned a value.
 
 
 

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