★中斷 軟體中斷才會耗用CPU資源,又叫做系統呼叫。
到底是raspberry Pi 板子本身就有硬體中斷,還是GPIO做出軟體中斷?
★有關input 上/下拉電阻,event_detect,debouce...
★參考https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/
GPIO.setmode(GPIO.BOARD) # or GPIO.setmode(GPIO.BCM)
mode = GPIO.getmode()GPIO.setwarnings(False)GPIO.setup(channel, GPIO.IN)GPIO.setup(channel, GPIO.OUT)GPIO.setup(channel, GPIO.OUT, initial=GPIO.HIGH)----------------------------chan_list = [11,12] # add as many channels as you want! # you can tuples instead i.e.: # chan_list = (11,12) GPIO.setup(chan_list, GPIO.OUT)-----------------------------取得值GPIO.input(channel)設定值GPIO.output(channel, state)多組設定chan_list = [11,12] # also works with tuples GPIO.output(chan_list, GPIO.LOW) # sets all to GPIO.LOW GPIO.output(chan_list, (GPIO.HIGH, GPIO.LOW)) # sets first HIGH and second LOWpitch_s = raw_input("Enter Pitch 200 to 2000): ") duration_s = raw_input("Enter Duration second): ")清除所有腳位,恢復初始狀態GPIO.cleanup()也可以只清部份GPIO.cleanup(channel) GPIO.cleanup( (channel1, channel2) ) GPIO.cleanup( [channel1, channel2] )取得軟硬體資訊★有提示的輸入GPIO.RPI_INFOGPIO.RPI_INFO['P1_REVISION'] GPIO.RPI_REVISIONGPIO.VERSION★def mycallback(channel): print("Button pressed")在上面中參數channel沒有作用,但不可以除去,否則會有runtime error,一定至少要有一個參數,在這裡至於給什麼,都可以。
★def buzz(pitch, duration) : 頻率 時間
period = 1.0 / pitch period 是週期,振動一次花的時間
half_period = period / 2
cycles = int(duration * pitch) 頻率 X 時間 = 總共振動的次數
for i in xrange(cycles) :
GPIO.output(buzzer_pin, GPIO.HIGH)
time.sleep(half_period)
GPIO.output(buzzer_pin, GPIO.LOW)
time.sleep(half_period)

沒有留言:
張貼留言