W!o+ 的《小伶鼬工坊演義》︰ 向世界說哈囉!!??

正想驗證『 GrovePi 』的安裝,突然憶起 Mrphs 曾經提到過 W!o+ 很喜歡『忒修斯之船』的傳說︰

海盜船

忒修斯之船

希臘古羅馬時代的普魯塔克 Plutarch 引用古希臘傳說寫道︰

忒 修斯與雅典的年輕人們自克里特島歸來時,所搭之三十槳的船為雅典人留下來當做紀念碑。隨著時間流逝;木材逐漸腐朽,那時雅典人便會更換新的木頭來替代。終 於此船的每根木頭都已被替換過了;因此古希臘的哲學家們就開始問著:『這艘船還是原本的那艘忒修斯之船的嗎?假使是,但它已經沒有原本的任何一根木頭了; 如果不是,那它又是從什麼時候不是的呢?』

這個『同一性』identity 問題,在邏輯學上叫做『同一律』,與真假不相容的『矛盾律』齊名︰

\forall x, \ x = x

……

然而他對於『向世界說哈囉』之傳統,卻相當不以為然︰

一九七二年布萊恩‧柯林漢 Brian Wilson Kernighan  於貝爾實驗室撰寫《Introduction to the Language B》的內部技術文件時,寫了一個『hello, world』的範例程式。其後他與 丹尼斯‧里奇 Dennis M. Ritchie 合著的《The C Programming Language》也保留了這個範例程式。不知怎的這成了一個『傳統』,成了初學者所編寫的第一個程式。現今流行的寫法是『Hello, World!』,不知柯林漢會不會抱怨這是是那個嗎?它的原典是︰

hello, world

,裡頭所有字母全是小寫,『 , 』之後有一『空白』。

Thue 1

Thue 2

現在就讓我們用著 Colagioia 之 Thue 語言寫我們第一支中文的『打招呼』程式︰

打招呼::=~別來無恙
::=
打招呼

那要怎麽『跑』run 這個程式呢?網路雲端上有一個『Thue interpreter in Javascript』的網頁,你可以將這支『哈囉』程式,如左圖般地打入或拷貝,先按 Update 鍵載入程式,然後按 Run 鍵執行。你將見證『打招呼』被改寫成了『別來無恙』!!

─── 引自《 Thue 之改寫系統《三》

 

,彷彿是個『定了格』的世界,缺乏生命的朝氣。所以每當 W!o+ 拿到新東西,總會先把玩一番,細細品味再決定如何賦予它第一次的『開始』。……

這可叫人為難了!!還好一時心頭湧現孔老夫子說的︰

觚不觚,觚哉!觚哉!

,想那『復古』即『創新』,何妨假借唐三藏『譯經之法』,來個換湯不換藥的耶??

 

【 GrovePi 安裝】

cd /home/pi/Desktop/
sudo git clone https://github.com/DexterInd/GrovePi
cd GrovePi/Script/
sudo chmod +x install.sh
sudo ./install.sh 

 

hello, world blue LED

#!/usr/bin/env python

# GrovePi LED blink Example for the Grove LED Socket (http://www.seeedstudio.com/wiki/Grove_-_LED_Socket_Kit)
#
# The GrovePi connects the Raspberry Pi and Grove sensors.  You can learn more about GrovePi here:  http://www.dexterindustries.com/GrovePi
#
# Have a question about this example?  Ask on the forums here:  http://www.dexterindustries.com/forum/?forum=grovepi
#
'''
## License

The MIT License (MIT)

GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi.
Copyright (C) 2015  Dexter Industries

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
'''

import time

# AHA, 需要修改 grovepi.py
from grovepi_3 import *

# Connect the Grove LED to digital port D4
led = 4

pinMode(led,"OUTPUT")
time.sleep(1)

print("This example will blink a Grove LED connected to the GrovePi+ on the port labeled D4.  If you're having trouble seeing the LED blink, be sure to check the LED connection and the port number.  You may als$
print(" ")
print("Connect the LED to the port labele D4!")

while True:
    try:
        #Blink the LED
        digitalWrite(led,1)             # Send HIGH to switch on LED
        print("燈 亮!")
        time.sleep(1)

        digitalWrite(led,0)             # Send LOW to switch off LED
        print("燈 滅!")
        time.sleep(1)

    except KeyboardInterrupt:   # Turn LED off before stopping
        digitalWrite(led,0)
        break
    except IOError:                             # Print "Error" if communication error encountered
        print("錯誤")

 

熟知那過程,當真是吃力不討好的呦!!