初始化提交
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import math
|
||||
|
||||
def math_map(v, al, ah, bl, bh):
|
||||
return bl + (bh - bl) * (v - al) / (ah - al)
|
||||
|
||||
def math_mean(myList):
|
||||
localList = [e for e in myList if type(e) == int or type(e) == float]
|
||||
if not localList: return
|
||||
return float(sum(localList)) / len(localList)
|
||||
|
||||
def math_median(myList):
|
||||
localList = sorted([e for e in myList if type(e) == int or type(e) == float])
|
||||
if not localList: return
|
||||
if len(localList) % 2 == 0:
|
||||
return (localList[len(localList) // 2 - 1] + localList[len(localList) // 2]) / 2.0
|
||||
else:
|
||||
return localList[(len(localList) - 1) // 2]
|
||||
|
||||
def math_modes(some_list):
|
||||
modes = []
|
||||
# Using a lists of [item, count] to keep count rather than dict
|
||||
# to avoid "unhashable" errors when the counted item is itself a list or dict.
|
||||
counts = []
|
||||
maxCount = 1
|
||||
for item in some_list:
|
||||
found = False
|
||||
for count in counts:
|
||||
if count[0] == item:
|
||||
count[1] += 1
|
||||
maxCount = max(maxCount, count[1])
|
||||
found = True
|
||||
if not found:
|
||||
counts.append([item, 1])
|
||||
for counted_item, item_count in counts:
|
||||
if item_count == maxCount:
|
||||
modes.append(counted_item)
|
||||
return modes
|
||||
|
||||
def math_standard_deviation(numbers):
|
||||
n = len(numbers)
|
||||
if n == 0: return
|
||||
mean = float(sum(numbers)) / n
|
||||
variance = sum((x - mean) ** 2 for x in numbers) / n
|
||||
return math.sqrt(variance)
|
||||
|
||||
def lists_sort(my_list, type, reverse):
|
||||
def try_float(s):
|
||||
try:
|
||||
return float(s)
|
||||
except:
|
||||
return 0
|
||||
key_funcs = {
|
||||
"NUMERIC": try_float,
|
||||
"TEXT": str,
|
||||
"IGNORE_CASE": lambda s: str(s).lower()
|
||||
}
|
||||
key_func = key_funcs[type]
|
||||
list_cpy = list(my_list)
|
||||
return sorted(list_cpy, key=key_func, reverse=reverse)
|
||||
@@ -0,0 +1,37 @@
|
||||
from microbit import *
|
||||
|
||||
def motor1(v,d=1):
|
||||
v = min(12,max(0,v))
|
||||
if v==0:
|
||||
pin8.write_analog(0)
|
||||
pin16.write_analog(0)
|
||||
elif d==1:
|
||||
pin8.write_analog(int(v/12*1023))
|
||||
pin16.write_analog(0)
|
||||
elif d==0:
|
||||
pin8.write_analog(0)
|
||||
pin16.write_analog(int(v/12*1023))
|
||||
|
||||
def motor2(v,d=1):
|
||||
v = min(12,max(0,v))
|
||||
if v==0:
|
||||
pin14.write_analog(0)
|
||||
pin13.write_analog(0)
|
||||
elif d==1:
|
||||
pin14.write_analog(int(v/12*1023))
|
||||
pin13.write_analog(0)
|
||||
elif d==0:
|
||||
pin14.write_analog(0)
|
||||
pin13.write_analog(int(v/12*1023))
|
||||
|
||||
def motor3(v,d=1):
|
||||
v = min(12,max(0,v))
|
||||
if v==0:
|
||||
pin0.write_analog(0)
|
||||
pin15.write_analog(0)
|
||||
elif d==1:
|
||||
pin0.write_analog(int(v/12*1023))
|
||||
pin15.write_analog(0)
|
||||
elif d==0:
|
||||
pin0.write_analog(0)
|
||||
pin15.write_analog(int(v/12*1023))
|
||||
@@ -0,0 +1,13 @@
|
||||
from microbit import *
|
||||
import neopixel
|
||||
|
||||
np = neopixel.NeoPixel(pin12, 4)
|
||||
|
||||
def mixly_rgb_show_all(r, g, b):
|
||||
for led in range(4):
|
||||
np[led] = (r, g, b)
|
||||
np.show()
|
||||
|
||||
def mixly_rgb_show(led, r, g, b):
|
||||
np[led] = (r, g, b)
|
||||
np.show()
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"language": "MicroPython",
|
||||
"burn": {
|
||||
"type": "volume",
|
||||
"volumeName": [
|
||||
"MICROBIT",
|
||||
"MITHONCC"
|
||||
],
|
||||
"filePath": "{indexPath}/build/microbit-micropython-v1.hex"
|
||||
},
|
||||
"upload": {
|
||||
"type": "command",
|
||||
"portSelect": [
|
||||
{
|
||||
"vendorId": "0D28",
|
||||
"productId": "0204"
|
||||
}
|
||||
],
|
||||
"libPath": [
|
||||
"{indexPath}/build/lib"
|
||||
],
|
||||
"command": "\"{ampy}\" -p {com} -d 1 -r \"{reset}\" put \"{indexPath}/build/upload\"",
|
||||
"filePath": "{indexPath}/build/upload/main.py",
|
||||
"copyLib": true,
|
||||
"reset": []
|
||||
},
|
||||
"nav": {
|
||||
"burn": true,
|
||||
"upload": true,
|
||||
"save": {
|
||||
"py": true
|
||||
},
|
||||
"setting": {
|
||||
"pythonToBlockly": true
|
||||
}
|
||||
},
|
||||
"serial": {
|
||||
"ctrlCBtn": true,
|
||||
"ctrlDBtn": true,
|
||||
"baudRates": 115200,
|
||||
"yMax": 100,
|
||||
"yMin": 0,
|
||||
"pointNum": 100,
|
||||
"rts": true,
|
||||
"dtr": true
|
||||
},
|
||||
"pythonToBlockly": false,
|
||||
"web": {
|
||||
"com": "usb",
|
||||
"burn": {
|
||||
"filePath": "./build/microbit-micropython-v1-lib.hex"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"七彩RGB灯.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "七彩RGB灯.mix"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 Beta11" board="Mithon CC" xmlns="http://www.w3.org/1999/xhtml"><block type="base_loop" id="4=.AIPR~w(`[eSM4/qvJ" x="323" y="116"><statement name="DO"><block type="actuator_rgb_color" id="%cL7H]2DhT9rJy`ve.S("><field name="LED">0</field><field name="COLOR">255,0,0</field><next><block type="base_delay" id="7LB|Tyz)/GzZpZU#cG!5"><value name="DELAY_TIME"><shadow type="math_number" id=";M]nYI#.o^!d|c.T:@8/"><field name="NUM">100</field></shadow></value><next><block type="actuator_rgb_color" id="g-uD/8U]u`?v)s;.{ahI"><field name="LED">0</field><field name="COLOR">255,128,0</field><next><block type="base_delay" id="QXm8rm!L;no`{-!EZ8[7"><value name="DELAY_TIME"><shadow type="math_number" id="Wt,f}n5eGM|.Fi(/;N3W"><field name="NUM">100</field></shadow></value><next><block type="actuator_rgb_color" id="i(H([nWc7^}x1t0`y^k9"><field name="LED">0</field><field name="COLOR">255,255,0</field><next><block type="base_delay" id="R/,I39$L_F)H|Wo;-.Tu"><value name="DELAY_TIME"><shadow type="math_number" id="v^oK%L8!(L*88FA:#ZTV"><field name="NUM">100</field></shadow></value><next><block type="actuator_rgb_color" id="+^yYq^%@S[$c{M{=Wa"><field name="LED">0</field><field name="COLOR">0,255,0</field><next><block type="base_delay" id="_nPs2bAw)QX]RaG.o7l_"><value name="DELAY_TIME"><shadow type="math_number" id="~)IiUJDib~!f+j#0$btN"><field name="NUM">100</field></shadow></value><next><block type="actuator_rgb_color" id="bXNU0~uwFHh0AGe^9=JP"><field name="LED">0</field><field name="COLOR">0,255,255</field><next><block type="base_delay" id="^fnsHH*]W(DULX?3?{md"><value name="DELAY_TIME"><shadow type="math_number" id="#.nW!|:W:NqbIGSiBYu;"><field name="NUM">100</field></shadow></value><next><block type="actuator_rgb_color" id="R#ML|m%/`SUfGryK=#~:"><field name="LED">0</field><field name="COLOR">0,0,255</field><next><block type="base_delay" id="snJ##6LKrd:?m1k*SHJY"><value name="DELAY_TIME"><shadow type="math_number" id="*Ga$8Dve7ES^Lb|:UFWO"><field name="NUM">100</field></shadow></value><next><block type="actuator_rgb_color" id="il_0Nv--Z3$5DP5DI+E)"><field name="LED">0</field><field name="COLOR">128,0,255</field><next><block type="base_delay" id="^@ovJ-t8SGg67K30B@:8"><value name="DELAY_TIME"><shadow type="math_number" id="o{P]Q/!tVy!Ufo(u5j~D"><field name="NUM">100</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block></xml>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Reference in New Issue
Block a user