Skip to content

Instantly share code, notes, and snippets.

@dvsseed
Last active October 18, 2020 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvsseed/e65a69c40073cbca22169a846288c8dc to your computer and use it in GitHub Desktop.
Save dvsseed/e65a69c40073cbca22169a846288c8dc to your computer and use it in GitHub Desktop.
drag and drop this file to the CIRCUITPY directory
# Tools
import time
import board
import neopixel
dup = 37 # hyphen
# include audio libraries
try:
from audiocore import WaveFile
except ImportError:
from audioio import WaveFile
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
pixels = neopixel.NeoPixel(
board.NEOPIXEL,
10,
brightness=0.2,
auto_write=False
)
# LED 全亮
def color_chase_all(color, wait):
for i in range(10):
pixels[i] = color
time.sleep(wait)
pixels.show()
# 指定某一LED(#idx)亮
def color_chase_1(color, idx, wait):
pixels[idx] = color
time.sleep(wait)
pixels.show()
# 顯示 SGP30 數據
def show_SGP(sgp30):
print("eCO2 = %d ppm \t TVOC = %d ppb" % (sgp30.eCO2, sgp30.TVOC))
print("Raw H2 = %d \t Raw Ethanol = %d" % (sgp30.H2, sgp30.Ethanol))
print("-" * dup)
# 顯示 SGP30 Baseline數據
def show_SGP_baseline(elapsed_sec, sgp30):
if elapsed_sec > 10:
elapsed_sec = 0
print(
"**** Baseline values: ****\neCO2 = 0x%x, TVOC = 0x%x"
% (sgp30.baseline_eCO2, sgp30.baseline_TVOC)
)
time.sleep(12)
return elapsed_sec
# 顯示 PMSA003數據
def show_PM25(aqdata):
print("Concentration Units (standard)")
print("-" * dup)
print(
"PM 1.0: %d\tPM2.5: %d\tPM10: %d" % (
aqdata["pm10 standard"],
aqdata["pm25 standard"],
aqdata["pm100 standard"]
)
)
print("Concentration Units (environmental)")
print("-" * dup)
print(
"PM 1.0: %d\tPM2.5: %d\tPM10: %d" % (
aqdata["pm10 env"],
aqdata["pm25 env"],
aqdata["pm100 env"]
)
)
print("-" * dup)
print("Particles > 0.3um / 0.1L air:", aqdata["particles 03um"])
print("Particles > 0.5um / 0.1L air:", aqdata["particles 05um"])
print("Particles > 1.0um / 0.1L air:", aqdata["particles 10um"])
print("Particles > 2.5um / 0.1L air:", aqdata["particles 25um"])
print("Particles > 5.0um / 0.1L air:", aqdata["particles 50um"])
print("Particles > 10 um / 0.1L air:", aqdata["particles 100um"])
print("-" * dup)
# playing an audio file
def play_file(filename):
print("Playing file: " + filename)
wave_file = open(filename, "rb")
with WaveFile(wave_file) as wave:
with AudioOut(board.SPEAKER) as audio:
audio.play(wave)
while audio.playing:
pass
# print("Finished")
@dvsseed
Copy link
Author

dvsseed commented Oct 18, 2020

drag and drop this file to the CIRCUITPY directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment