飛行派工作日誌《十三》

友朋不知何處去?
風箏一時斷消息。
莫非秋風薄無力?
孤獨一人費猜疑!

 

別說此刻哪處買?大顆 LED 將怎用︰

NeoPixel Diffused 8mm Through-Hole LED – 5 Pack

leds_1734-04

Description

LOLwut? NeoPixels in through-hole variety? Oh yes, we haz them! If you like NeoPixel strips you’ll luv these 8mm diffused through-hole NeoPixels. All the single-pin-controlling-hundreds-of-LEDs goodness in a breadboard friendly format. Each LED looks just like your classic through-hole 8mm RGB LED with 4 legs, but instead of just red/green/blue there’s a little chip inside that can control the LED with high speed PWM for 24-bit color.

Power them with 5V and chain them together, tying the Data-Out pin of one to the Data-in of the previous one in the chain. If you’re using an Arduino, you can control these LEDs with our wonderfully-written Neopixel library for Arduino. They also work great with our Trinkets. Note that these are “RGB” instead of “GRB” format used in the 5050-sized LEDs you are so used to. Check in the NeoPixel example code for how to swap the colors automagically.

These great looking LEDs are also fast and responsive with diffused color that will make your project glow!

 

物小亮微高難見,五行沖剋總無窮︰

碼 ︰講 習 。輪到學長講習,一開口︰

詩就是程式,程式即是詩。

將用

一枝紅豔露凝香
兩片綠霞籬外影
陣陣落黃因風起
藍天浮雲自飄零

,控制實習 機 板上的八顆 LED ,達到寓 教 教於 樂 樂的目標,促進科技人文化的宗旨。

同學們,下面的程式使用派生『執行緒』程式庫,閱讀時可以參考

threading — Thread-based parallelism

threading – Manage concurrent threads

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# 加載所需程式庫
import RPi.GPIO as GPIO
from time import sleep
import random
import threading
 
# 選擇 BCM 編號制
GPIO.setmode(GPIO.BCM)

# 採用負邏輯
# 名目

四位數碼管位選一 = 17
四位數碼管位選二 = 27
四位數碼管位選三 = 22
四位數碼管位選四 = 10
滅 = 關 = GPIO.HIGH
亮 = 開 = GPIO.LOW

# 藍天,取陽,五行數用坎水一,象雲氣

藍一LED = 5
藍二LED = 6
藍三LED = 13
藍四LED = 19
天時 = 25
天次 = 0

# 落黃,歸土,五行數為五

黃LED = 7
地候 = 30

# 綠霞,草木,陰,五行數用八

綠一LED = 0
綠二LED = 1

# 紅花,草木,陰,五行數用離火二

紅LED = 8
花時 = 2 * 8

# 初始態
GPIO.setup(四位數碼管位選一, GPIO.OUT, initial=關)
GPIO.setup(四位數碼管位選二, GPIO.OUT, initial=關)
GPIO.setup(四位數碼管位選三, GPIO.OUT, initial=關)
GPIO.setup(四位數碼管位選四, GPIO.OUT, initial=關)

GPIO.setup(藍一LED, GPIO.OUT, initial=滅)
GPIO.setup(藍二LED, GPIO.OUT, initial=滅)
GPIO.setup(藍三LED, GPIO.OUT, initial=滅)
GPIO.setup(藍四LED, GPIO.OUT, initial=滅)

GPIO.setup(黃LED, GPIO.OUT, initial=滅)
落黃 = GPIO.PWM(黃LED, 5)


GPIO.setup(綠一LED, GPIO.OUT, initial=滅)
GPIO.setup(綠二LED, GPIO.OUT, initial=滅)
綠霞一 = GPIO.PWM(綠一LED, 8)
綠霞二 = GPIO.PWM(綠二LED, 8)

GPIO.setup(紅LED, GPIO.OUT, initial=滅)
紅花 = GPIO.PWM(紅LED, 2)

def 一枝紅豔露凝香():
    紅花.start(50)
    sleep(16)
    紅花.stop()
    sleep(1)
    GPIO.output(紅LED,滅)

def 兩片綠霞籬外影():
    綠霞一.start(30)
    綠霞二.start(70)
    sleep(16)
    綠霞一.stop()
    綠霞二.stop()
    sleep(0.5)
    GPIO.output(綠一LED,滅)
    sleep(0.5)
    GPIO.output(綠二LED,滅)

def 陣陣落黃因風起():
    落黃.start(50)
    sleep(30)
    落黃.stop()
    sleep(0.1)
    GPIO.output(黃LED,滅)

紅花緒 = threading.Thread(name="紅花", target=一枝紅豔露凝香)
綠霞緒 = threading.Thread(name="綠霞", target=兩片綠霞籬外影)
落黃緒 = threading.Thread(name="落黃", target=陣陣落黃因風起)

紅花緒.start()
綠霞緒.start()
落黃緒.start()

# 浮雲藍天自飄零

while 天次 < 25 :
    天次 += 1
    藍天 = [亮, 亮, 亮, 亮]
    浮雲 = random.randint(0,3)
    藍天[浮雲] = 滅
    GPIO.output(藍一LED, 藍天[0])
    sleep(0.01)
    GPIO.output(藍二LED, 藍天[1])
    sleep(0.01)
    GPIO.output(藍三LED, 藍天[2])
    sleep(0.01)
    GPIO.output(藍四LED, 藍天[3])
    sleep(1)

GPIO.output(藍一LED,滅)
GPIO.output(藍二LED,滅)
GPIO.output(藍三LED,滅)
GPIO.output(藍四LED,滅)

sleep(20)

GPIO.cleanup()

# 存成 poem.py 
# sudo python3 poem.py 執行

 

行 ︰古往今來,洋洋灑灑,這堂課可算是開了眼界。☿☺

訊 ︰☿ 學海無涯,惟勤是岸。☺☺

─── 摘自《M♪o 之學習筆記本《卯》基件︰【䷒】教思無窮

 

靜待冬拂大地春草生!