第1步 - 通过ssh,或者串口终端进入开发板的命令行,从 github 上下载BakeBit代码: cd ~git clone https://github.com/friendlyarm/BakeBit.git
第2步 - 使用如下命令在开发板上安装BakeBit:
cd BakeBit/Scriptchmod +x install.sh./install.sh
第3步 - 重启开发板:
reboot
第4步 - 运行示例程序:
可以在开发板上进入 BakeBit/Software/Python目录,运行bakebit_prj_Button_And_Buzzer.py: cd ~/BakeBit/Software/Pythonsudo python bakebit_prj_Button_And_Buzzer.py
运行结果
当按下按键时,蜂鸣器会响起,松开按键时,蜂鸣器停止。
示例源代码import bakebitimport time# Connect the BakeBit Ultrasonic Ranger to digital port D4# SIG,NC,VCC,GNDultrasonic_ranger = 4 # Connect the BakeBit LED to digital port D3led = 3 bakebit.pinMode(led,"OUTPUT")light = 0 while True: try: # Read distance value from Ultrasonic distance = bakebit.ultrasonicRead(ultrasonic_ranger) print(distance) if distance > 0: if distance<10: if light == 0: print("\ton") bakebit.digitalWrite(led,1) light = 1 else: if light == 1: print("\toff") bakebit.digitalWrite(led,0) light = 0 time.sleep(.2) except KeyboardInterrupt: bakebit.digitalWrite(led,0) breakexcept TypeError: print ("Error") except IOError: print ("Error")