版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
------《项目十三》参考答案------一、单项选择题题号12345678910答案BCAACCBBAA二、判断题题号12345678910判断√√×××√√√√×三、填空题1.速度位置2.旋转脉冲3.旋转位移周期性4.计数脉冲大小5.光电扫描原理6.质量稳定性7.度数分度8.电气360=机械360°/n°脉冲/转9.最小单位10.try/excepttryexcept四.操作题1.编写一个计算加减的程序,对该程序进行异常捕获,当出现错误的时候控制台输出”您输入的算式不合法”.importmatplotlib.pyplotasplt
#从pyplot导入MultipleLocator类,这个类用于设置刻度间隔
frommatplotlib.pyplotimportMultipleLocator
importPCF8591asADC
importtime
importRPi.GPIOasGPIO
ADC.setup(0x48)
GPIO.setmode(GPIO.BCM)
GPIO.setup(20,GPIO.OUT)
i=0
alert=0
x_values=list(range(61))
list_data=list(range(61))
alert_list=list()
whileTrue:
V_Value=ADC.read(0)
ifV_Value>=100:
GPIO.output(20,0)
alert=alert+1
else:
GPIO.output(20,1)
list_data[i]=V_Value
time.sleep(1)
ifi==60:
alert_list.append(alert)
i=0
alert=0
plt.subplot(2,2,1)
plt.plot(x_values[0:31],list_data[0:31],c='green')
plt.title('煤气泄漏数据变化图1',fontsize=24)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.xlabel('Time',fontsize=14)
plt.ylabel('CO',fontsize=14)
x_major_locator=MultipleLocator(1)
y_major_locator=MultipleLocator(50)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.xlim(0,31)
plt.ylim(0,200)
plt.subplot(2,2,2)
plt.plot(x_values[31:],list_data[31:],c='green')
plt.title('煤气泄漏数据变化图2',fontsize=24)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.xlabel('Time',fontsize=14)
plt.ylabel('CO',fontsize=14)
x_major_locator=MultipleLocator(1)
y_major_locator=MultipleLocator(50)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.xlim(31,61)
plt.ylim(0,200)
plt.subplot(2,1,2)
plt.plot(alert_list,c='green')
plt.title('分钟报警数统计图',fontsize=24)
plt.tick_params(axis='both',which='major',labelsize=14)
x_major_locator=MultipleLocator(1)
y_major_locator=MultipleLocator(50)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
plt.show()
else:
i+=12.编写多线程程序,列表info=[11,22,33,44,55,23],生成6个线程对象,每次线程输出一个值,最后输出:"end"importthreading
deftest(j):
print(j)
ts=[]
info=[1,2,3,4,55,233]
forjininfo:
th=threading.Thread(target=test,args=[j])
th.start()
ts.append(th)
foriints:
i.join()
print('end')3.将三色灯模块,按照表4.1对应接口连接至开发板,并且编写程序,实现效果如下:声明两个线程事件,两个线程中一个线程为让红色灯不断闪烁1秒一次,另外一个线程绿色灯以每秒2秒闪烁一次。importRPi.GPIOasGPIO
importtime
importthreading
defLed1():
whileTrue:
GPIO.output(24,1)
time.sleep(1)
GPIO.output(24,0)
time.sleep(1)
defLed2():
whileTrue:
GPIO.output(23,1)
time.sleep(2)
GPIO.output(23,0)
time.sleep(2)
if__name__=="__main__":
GPIO.setmode(GPIO.BCM)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
Led1_th=threading.Thread(target=Led1(),args=[])
Led1_th.start()
Led2_th=threading.Thread(target=Led2(),args=[])
Led2_th.start()4.将三色灯,超声波模块,按照表4.1对应接口连接至开发板,并且编写程序,实现效果如下:进行实时检测,当检测前方0.5米有物体接近的时候三色灯以每秒一次的频率闪烁红灯,正常情况下绿灯常亮importRPi.GPIOasGPIO
importtime
#引用模块类库
importsupersonic
importled
distance_min=0.5
defsuperconic_thread():
s=supersonic.supersonic()
ifs<distance_min:
foriinrange(0,3):
led.light(led.r_open)
time.sleep(0.5)
led.light(led.r_close)
time.sleep(0.5)
else:
led.light(led.g_open)
led.light(led.r_close)
time.sleep(0.5)
if__name__=="__main__":
supersonic.init()
led.init()
superconic_thread()5.将三色灯,超声波模块,LCD1602模块按照表4.1对应接口连接至开发板,并且编写程序,实现效果如下:进行实时检测,当检测前方0.5米有物体接近的时候声明两个线程事件,,两个线程中一个线程让三色灯以每秒一次的频率闪烁红灯,另外一个线程让LCD1602模块进行提示,正常情况下绿灯常亮.importRPi.GPIOasGPIO
importtime
#引用模块类库
importsupersonic
importled
importLCD1602
importthreading
globalstop_threads
distance_min=0.5
defLed():
whileTrue:
led.light(led.r_open)
time.sleep(1)
led.light(led.r_close)
time.sleep(1)
ifnotstop_threads:
break
defLcd():
LCD1602.write(0,1,"Someoneinvaded")
defsuperconic_thread():
s=supersonic.supersonic()
ifs<distance_min:
stop_threads=True
Led_th=threading.Thread(target=Led(),args=[])
Led_th.start()
Lcd_th=threading.Thread(target=Lcd(),args=[])
Lcd_th.start()
else:
stop_threads=False
led.light(led.g_open)
led.light(led.r_close)
LCD1602.write(0,1,"")
time.sleep(0.5)
if__name__=="__main__":
supersonic.init()
led.init()
LCD1602.init()
superconic_thread()6.将三色灯,超声波模块,LCD1602模块按照表4.1对应接口连接至开发板,并且编写程序,实现效果如下:可以在控制台开启程序,并设置超声波检测距离.进行实时检测,当检测前方物体接近的时候声明两个线程事件,两个线程中一个线程让三色灯以每秒一次的频率闪烁红灯,另外一个线程让LCD1602模块进行提示,正常情况下绿灯常亮.importRPi.GPIOasGPIO
importtime
#引用模块类库
importsupersonic
importled
importLCD1602
importthreading
globalstop_threads
defLed():
whileTrue:
led.light(led.r_open)
time.sleep(1)
led.light(led.r_close)
time.sleep(1)
ifnotstop_threads:
break
defLcd():
LCD1602.write(0,1,"Someoneinvaded")
defsuperconic_thread(distance_min):
s=supersonic.supersonic()
ifs<distance_min:
stop_threads=True
Led_th=threading.Thread(target=Led(),args=[])
Led_th.start()
Lcd_th=threading.Thread(target=Lcd(),args=[])
Lcd_th.start()
else:
stop_threads=False
led.light(led.g_open)
led.light(led.r_close)
LCD1602.write(0,1,"")
time.sleep(0.5)
if__name__=="__main__":
supersonic.init()
led.init()
LCD1602.init()
whileTrue:
User_cmd=input("输入指令")
ifUser_cmd.upper()=="OPEN":
distance_min=int(input("超声波检测距离"))
superconic_thread(distance_min)
else:
print("输入指令不存在")7.将LCD1602模块,旋转编码器按照表4.1对应接口连接至开发板,并且编写程序,实现效果如下:用旋转编码器模拟输入密码并把输入的密码用LCD1602模块显示出来,当输入的密码和设置的默认密码一样时LCD1602模块显示”PASSWORDOK”importRPi.GPIOasGPIO
importtime
#引用模块类库
importro_encode
importLCD1602
Rot_flag=True
globalCounter=0
#当前密码
password_list=[0,0,0,0,0,0,0,0]
InPwd_list=[0]
defRot_thread():
globalglobalCounter
globalpassword_list
globalInPwd_list
globalcount
LCD1602.init()
LCD1602.write(0,0,"InputPassword:")
whileRot_flag:
tmp=ro_encode.Rot_Deal()
iftmp!=globalCounter:
globalCounter=tmp
InPwd_list[count]=globalCounter
LCD_DISP2=''.join(str(x)forxinInPwd_list)
LCD1602.write(0,1,LCD_DISP2)
ifro_encode.Rot_SW():
InPwd_list.append(globalCounter)
LCD_DISP2=''.join(str(x)forxinInPwd_list)
LCD1602.write(0,1,LCD_DISP2)
count=count+1
ifcount==(len(password_list)-1):
ifInPwd_list==password_list:
LCD_DISP1='PASSWORDOK'
LCD1602.write(0,0,LCD_DISP1)
break
else:
print('密码错误,请重新输入!')
count=0
globalCounter=0
InPwd_list=[0]
LCD1602.write(0,1,"")
if__name__=="__main__":
ro_encode.init()
LCD1602.init()
Rot_thread()8.将LCD1602模块,旋转编码器按照表4.1对应接口连接至开发板,并且编写程序,实现效果如下:用旋转编码器模拟输入密码并把输入的密码用LCD1602模块显示出来,当输入的密码和设置的默认密码一样时LCD1602模块显示”PASSWORDOK”,当用户连续输入3次错误后,锁定输入密码功能,并提示用户无法使用保险箱功能,在液晶屏上显示该英文字符提示。importRPi.GPIOasGPIO
importtime
#引用模块类库
importro_encode
importLCD1602
Rot_flag=True
globalCounter=0
#当前密码
password_list=[0,0,0,0,0,0,0,0]
InPwd_list=[0]
errors_num=0
defRot_thread():
globalerrors_num
globalglobalCounter
globalpassword_list
globalInPwd_list
globalcount
LCD1602.init()
LCD1602.write(0,0,"InputPassword:")
whileRot_flag:
tmp=ro_encode.Rot_Deal()
iftmp!=globalCounter:
globalCounter=tmp
InPwd_list[count]=globalCounter
LCD_DISP2=''.join(str(x)forxinInPwd_list)
LCD1602.write(0,1,LCD_DISP2)
ifro_encode.Rot_SW():
InPwd_list.append(globalCounter)
LCD_DISP2=''.join(str(x)forxinInPwd_list)
LCD1602.write(0,1,LCD_DISP2)
count=count+1
ifcount==(len(password_list)-1):
ifInPwd_list==password_list:
LCD_DISP1='PASSWORDOK'
LCD1602.write(0,0,LCD_DISP1)
break
else:
print('密码错误,请重新输入!')
errors_num+=1
count=0
globalCounter=0
InPwd_list=[0]
LCD1602.write(0,1,"")
iferrors_num>3:
LCD1602.write(0,0,"Exittheprogram")
Rot_flag=False
if__name__=="__main__":
ro_encode.init()
LCD1602.init()
Rot_thread()9.将超声波模块,LCD1602模块,旋转编码器按照表4.1对应接口连接至开发板,并且编写程序,实现效果如下:当有人接近时才可以进行密码输入功能,如果无人接近则锁定密码输入功能用旋转编码器模拟输入密码并把输入的密码用LCD1602模块显示出来,当输入的密码和设置的默认密码一样时LCD1602模块显示”PASSWORDOK”importRPi.GPIOasGPIO
importtime
#引用模块类库
importro_encode
importLCD1602
importsupersonic
Rot_flag=False
globalCounter=0
#当前密码
password_list=[0,0,0,0,0,0,0,0]
InPwd_list=[0]
errors_num=0
distance_min=0.2
defRot_thread():
globalerrors_num
globalglobalCounter
globalpassword_list
globalInPwd_list
globalcount
LCD1602.init()
LCD1602.write(0,0,"InputPassword:")
whileRot_flag:
tmp=ro_encode.Rot_Deal()
iftmp!=globalCounter:
globalCounter=tmp
InPwd_list[count]=globalCounter
LCD_DISP2=''.join(str(x)forxinInPwd_list)
LCD1602.write(0,1,LCD_DISP2)
ifro_encode.Rot_SW():
InPwd_list.append(globalCounter)
LCD_DISP2=''.join(str(x)forxinInPwd_list)
LCD1602.write(0,1,LCD_DISP2)
count=count+1
ifcount==(len(password_list)-1):
ifInPwd_list==password_list:
LCD_DISP1='PASSWORDOK'
LCD1602.write(0,0,LCD_DISP1)
break
else:
print('密码错误,请重新输入!')
errors_num+=1
count=0
globalCounter=0
InPwd_list=[0]
LCD1602.write(0,1,"")
iferrors_num>3:
LCD1602.write(0,0,"Exittheprogram")
Rot_flag=False
if__name__=="__main__":
ro_encode.init()
LCD1602.init()
globalRot_flag
Rot_thread()
s=supersonic.supersonic()
ifs<distance_min:
Rot_flag=True
print("有人进入!")
else:
Rot_flag=False10.将超声波模块,LCD1602模块,旋转编码器按照表4.1对应接口连接至开发板,并且编写程序,使用多线程的方式将传感器分到多个线程中执行完成以下功能:当有人接近时才可以进行密码输入功能,如果无人接近则锁定密码输入功能用旋转编码器模拟输入密码并把输入的密码用LCD1602模块显示出来,当输入的密码和设置的默认密码一样时LCD1602模块显示”PASSWORDOK”importRPi.GPIOasGPIO
importtime
#引用模块类库
importro_encode
importLCD1602
importsupersonic
importthreading
Rot_flag=True
globalCounter=0
#当前密码
password_list=[0,0,0,0,0,0,0,0]
InPwd_list=[0]
distance_min=0.2
defsuperconic_thread():
globalRot_flag
whileTrue:
#获取超声波模块数据
s=supersonic.supersonic()
ifs<distance_min:#当前超声波距离到达设置范围时
Rot_flag=True
print("有人进入!")
else:
Rot_flag=False
time.sleep(0.5)
defRot_thread():
globalglobalCounter
globalpassword_list
globalInPwd_list
globalcount
LCD1602.init()
LCD1602.write(0,0,"InputPassword:")
whileRot_flag:
tmp=ro_encode.Rot_Deal()
iftmp!=globalCounter:
globalCounter=tmp
InPwd_list[count]=globalCounter
LCD_DISP2=''.join(str(x)forxinInPwd_list)
LCD16
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年秋招:富邦控股集团笔试题及答案
- 2026年秋招:东南网架集团面试题及答案
- 2026年秋招:得力集团试题及答案
- 2026年秋招:大汉集团面试题及答案
- 2026年海南省人教版高一语文第7单元古诗文背诵检测卷
- 2026年贵州省苏教版小学数学三年级下册第5单元测试卷
- 全国交通安全日教育主题班会课件(共23张)
- T/CASMES 536-2025高层楼宇建筑施工现代化改造作业指南
- 人教版七年级历史上册第5课《青铜器与甲骨文》精美
- 四川省巴中市平昌中学2025-2026学年高一上学期9月月考数学试卷(含答案)
- 传染病患者转运
- CJJ12025城镇道路工程施工与质量验收规范
- 《传感器与检测技术》课件 第一章 概述
- 【2026】超星尔雅学习通《组织行为学(中南财经政法大学)》章节测试及答案
- AQ 3026-2026《化工企业设备检修作业安全规范》解读课件
- 2026年部编版新教材语文三年级上册全套教案设计(共八个单元含教学计划)
- 泥瓦工简单施工方案(3篇)
- 门诊部医疗安全工作制度
- JJF 1221-2025 汽车排气污染物检测用底盘测功机校准规范
- 学习通《能源中国(上海电力大学)》2024章节测试答案
- 围手术期应激反应的调控机制
评论
0/150
提交评论