Lesson 1
# -*- coding: utf_8 -*-
from npython import * # 导入npython模块
#在下面开始写你自己的代码
while True:
a1 = light.read()#光线
oled.print(1,1,'当前光线:' + str(a1),1) #屏幕显示
a2 = aht20.read_temp()#环境温度采集
oled.print(1,2,'当前温度:' + str(a2) + '℃',1)Lesson 2
# -*- coding: utf_8 -*-
from npython import * # 导入npython模块
#在下面开始写你自己的代码
while True:
a1 = sound.read()#声音(噪音)采集
if a1>2000:
led.on()#LED开
oled.print(1,1,'当前声音:' + str(a1),1) #屏幕显示
time.sleep(0.5)#延时
else:
led.off()#LED关
oled.print(1,1,'当前声音:' + str(a1),1) #屏幕显示
time.sleep(0.5)#延时拓展1
# -*- coding: utf_8 -*-
from npython import * # 导入npython模块
#在下面开始写你自己的代码
while True:
a1 = button.get_a()
if a1:
oled.print(1,1,'你按了按键A',1) #屏幕显示
rgb.write_left(255,0,0)#左侧RGB灯
rgb.write_right(0,255,0) #右侧RGB灯
# rgb.write_left(x,y,z) x份红色,y份绿色, z份蓝色
# button.get_a()#按键A拓展2
# -*- coding: utf_8 -*-
from npython import * # 导入npython模块
#在下面开始写你自己的代码
rgb.write_left(0,0,0)#左侧RGB灯
rgb.write_right(0,0,0) #右侧RGB灯
sum = 0;
while True:
a1 = button.get_a()
if a1:
oled.print(1,1,'你按了按键A',1) #屏幕显示
rgb.write_left(255,0,0)#左侧RGB灯
rgb.write_right(0,255,0) #右侧RGB灯
time.sleep(1)#延时
rgb.write_left(0,0,0)#左侧RGB灯
rgb.write_right(0,0,0) #右侧RGB灯
sum = sum + 1;
# rgb.write_left(x,y,z) x份红色,y份绿色, z份蓝色
# button.get_a()#按键A
oled.print(1,1,str(sum),1) #屏幕显示Lesson 3
# -*- coding: utf_8 -*-
from npython import * # 导入npython模块
#在下面开始写你自己的代码
while True:
if button.get_a() == 1:
oled.print(1,1,"按键A已按下",1) #屏幕显示
rgb.write_right(255,0,0)#右侧RGB灯
else:
oled.print(1,1,"按键A已松开",1) #屏幕显示
rgb.write_right(0,0,0)#右侧RGB灯