# 按A顯示亮度,按B顯示溫度
from future import *
from time import sleep
screen.fill((0, 0, 0))
while True:
if sensor.btnValue('a'):
screen.text(str("Light: ")+str(sensor.getLight()),5,10,1,(0, 119, 255))
sleep(0.5)
if sensor.btnValue('b'):
screen.text(str("Temp: ")+str(sensor.getTemp()),5,30,1,(0, 119, 255))
sleep(0.5)
4 加速度計
sensor.accX()
sensor.accY()
sensor.accZ()
獲取加速度計3個軸的讀數,單位為G(重力加速度)。
5. 姿勢角度
sensor.roll()
sensor.pitch()
分別獲取加速度計的橫滾度與旋轉度。
4~5使用範例
from future import *
from time import sleep
screen.sync = 0
while True:
screen.fill((0, 0, 0))
screen.text(str("X: ")+str(sensor.accX()),5,10,1,(0, 119, 255))
screen.text(str("Y: ")+str(sensor.accY()),5,25,1,(0, 119, 255))
screen.text(str("Z: ")+str(sensor.accZ()),5,40,1,(0, 119, 255))
screen.text(str("Roll: ")+str(sensor.roll()),5,55,1,(0, 119, 255))
screen.text(str("Pitch: ")+str(sensor.pitch()),5,70,1,(0, 119, 255))
screen.refresh()
sleep(0.2)
6. 姿勢檢測
sensor.gesture(gesture)
未來板能偵測8種姿勢。返回True或False。
‘shake’ : 搖晃
‘freefall’ : 自由落體
‘tilt_up’ : 正立
‘tilt_down’ : 倒立
‘tilt_left’ : 左傾
‘tilt_right’ : 右傾
‘face_up’ : 朝上
‘face_down’ : 朝下
7. 姿勢檢測觸發事件
sensor.gesTrig[ges] = fn
sensor.startSchedule()
6~7使用範例
# 屏幕顯示姿勢的狀態,搖晃未來板更改背景顏色為白色。
from future import *
from time import sleep
def onGesture_shake():
buzzer.melody(JUMP_UP)
sensor.gesTrig['shake']=onGesture_shake
sensor.startSchedule()
screen.sync = 0
while True:
screen.fill((0, 0, 0))
screen.text(str("Face Up: ")+str(sensor.gesture('face_up')),5,10,1,(0, 119, 255))
screen.text(str("Face Down: ")+str(sensor.gesture('face_down')),5,25,1,(0, 119, 255))
screen.refresh()
sleep(0.2)