import serial, json, time
from serial.tools.list_ports import comports as list_serial_ports
def find_microbit():
"""
Finds the port to which the device is connected.
https://github.com/mu-editor/mu/blob/803153f661097260206ed2b7cc9a1e71b564d7c3/mu/contrib/microfs.py#L44
"""
ports = list_serial_ports()
pc上:
#!/usr/bin/env python
# encoding: utf-8
import serial, json, time
from serial.tools.list_ports import comports as list_serial_ports
def find_microbit():
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/48676566/grant-access-to-cam-mic-using-python-for-pyqt-webengine | |
from PyQt5.QtWidgets import QApplication | |
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage | |
from PyQt5.QtCore import QUrl | |
class WebEnginePage(QWebEnginePage): | |
def __init__(self, *args, **kwargs): | |
QWebEnginePage.__init__(self, *args, **kwargs) | |
self.featurePermissionRequested.connect(self.onFeaturePermissionRequested) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zmq | |
import time | |
from zmq.utils.strtypes import asbytes | |
import threading | |
context = zmq.Context() | |
pub = context.socket(zmq.PUB) | |
pub.bind("tcp://*:5000") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
测试环境: | |
python3.6 | |
pyzmq==17.0.0 | |
''' | |
import time | |
import zmq | |
context = zmq.Context() | |
socket = context.socket(zmq.PUB) | |
socket.bind('tcp://127.0.0.1:2000') |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# main.py -- put your code here! | |
c = ''' | |
import pyb | |
red_led = pyb.LED(1) # | |
red_led.on() | |
''' | |
exec(c.strip()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
# 一个对future进行赋值的函数 | |
async def slow_operation(future): | |
await asyncio.sleep(1) | |
# 给future赋值 | |
future.set_result('Future is done!') | |
loop = asyncio.get_event_loop() | |
# 创建一个future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
import uasyncio | |
async def hello(): | |
print('Hello world! ' ) | |
await uasyncio.sleep(1) | |
print('Hello again! ' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See original soft_pwm.py for detailed comments. | |
import uasyncio | |
async def pwm_cycle(led, duty, cycles): | |
duty_off = 20 - duty | |
for i in range(cycles): | |
if duty: | |
print(led) | |
await uasyncio.sleep_ms(duty) |