当前位置: 首页 > news >正文

下载百度官方网站常州个人做网站

下载百度官方网站,常州个人做网站,药店网站源码,免费直播软件下载可燃气体传感器 MQ-2 和 蜂鸣器 代码段 controlDevice.h(设备控制)smokeAlarm.c(烟雾报警器)buzzer.c(蜂鸣器)mainPro.c(主函数)运行结果 可燃气体传感器 MQ-2 和 蜂鸣器 代码段 …

可燃气体传感器 MQ-2 和 蜂鸣器
代码段

  • controlDevice.h(设备控制)
  • smokeAlarm.c(烟雾报警器)
  • buzzer.c(蜂鸣器)
  • mainPro.c(主函数)
  • 运行结果

可燃气体传感器 MQ-2 和 蜂鸣器

在这里插入图片描述
在这里插入图片描述

代码段

controlDevice.h(设备类)

#include <wiringPi.h>					//wiringPi库
#include <stdio.h>
#include <stdlib.h>struct Devices                          //设备类
{char deviceName[128];               //设备名int status;                         //状态int pinNum;							//引脚号int (*Init)(int pinNum);			//“初始化设备”函数指针int (*open)(int pinNum);			//“打开设备”函数指针int (*close)(int pinNum);			//“关闭设备”函数指针int (*readStatus)(int pinNum);		//“读取设备状态”函数指针  为火灾报警器准备int (*changeStatus)(int status);	//“改变设备状态”函数指针struct Devices *next;
};struct Devices* addBathroomLightToDeviceLink(struct Devices *phead);		//“浴室灯”加入设备链表函数声明      2
struct Devices* addBedroomLightToDeviceLink(struct Devices *phead);	        //“卧室灯”加入设备链表函数声明      8
struct Devices* addRestaurantLightToDeviceLink(struct Devices *phead);		//“餐厅灯”加入设备链表函数声明      13
struct Devices* addLivingroomLightToDeviceLink(struct Devices *phead);		//“客厅灯”加入设备链表函数声明      16
struct Devices* addSmokeAlarmToDeviceLink(struct Devices *phead);           //“烟雾报警器”加入设备链表函数声明  6
struct Devices* addBuzzerToDeviceLink(struct Devices *phead);		        //“蜂鸣器”加入设备链表函数声明      9

smokeAlarm.c(烟雾报警器)

#include "controlDevice.h"			        //自定义设备类的文件int smokeAlarmInit(int pinNum)              //C语言必须要传参,JAVA不用,可直接访问变量的值
{pinMode(pinNum,INPUT);				    //配置引脚为输入模式//digitalWrite(pinNum,HIGH);			//引脚置高电平,断开继电器
}int smokeAlarmReadStatus(int pinNum)
{return digitalRead(pinNum);
}int smokeAlarmStatus(int status)
{}struct Devices smokeAlarm = {			//定义烟雾报警器(对象).deviceName = "smokeAlarm",			//名字.pinNum = 6,						//香橙派 6号(wPi)引脚.Init = smokeAlarmInit,				//指定初始化函数.readStatus = smokeAlarmReadStatus,.changeStatus = smokeAlarmStatus
};struct Devices* addSmokeAlarmToDeviceLink(struct Devices *phead)		//烟雾报警器(对象)加入设备链表函数
{if(phead == NULL){return &smokeAlarm;}else{smokeAlarm.next = phead;  //以前的头变成.nextphead = &smokeAlarm;      //更新头return phead;}
}

buzzer.c(蜂鸣器)

#include "controlDevice.h"			//自定义设备类的文件int buzzerInit(int pinNum)
{pinMode(pinNum,OUTPUT);						//配置引脚为输出模式digitalWrite(pinNum,HIGH);					//引脚置高电平,蜂鸣器关闭
}int buzzerOpen(int pinNum)
{digitalWrite(pinNum,LOW);					//引脚置低电平,蜂鸣器开启
}int buzzerClose(int pinNum)
{digitalWrite(pinNum,HIGH);					//引脚置高电平,蜂鸣器关闭
}struct Devices buzzer = {						//定义蜂鸣器(对象).deviceName = "buzzer",						//名字.pinNum = 9,								//香橙派 9号(wpi)引脚.Init = buzzerInit,							//指定初始化函数.open = buzzerOpen,							//指定“开启蜂鸣器”函数.close = buzzerClose,						//指定“关闭蜂鸣器”函数
};struct Devices* addBuzzerToDeviceLink(struct Devices *phead)		//蜂鸣器(对象)加入设备链表函数
{if(phead == NULL){return &buzzer;}else{buzzer.next = phead;phead = &buzzer;return phead;}
}

mainPro.c(主函数)

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "controlDevice.h"struct Devices* findDeviceByName(char *name, struct Devices *phead)
{struct Devices *tmp =phead;if(phead == NULL){return NULL;}else{while(tmp != NULL){if(strcmp(tmp->deviceName,name)==0){return tmp;}tmp = tmp->next;}return NULL;}
}int main()
{char *smokeName = "smokeAlarm";char *buzzerName = "buzzer";struct Devices *tmp = NULL;int smokeStatus;												//存放“烟雾传感器”状态if (wiringPiSetup () == -1) { fprintf (stdout, "Unable to start wiringPi: %s\n", strerror (errno)) ; return 1 ; }struct Devices *pdeviceHead = NULL;				                    //定义初始链表头//pdeviceHead = addBathroomLightToDeviceLink(pdeviceHead);            //“浴室灯”加入设备链表//pdeviceHead = addBedroomLightToDeviceLink(pdeviceHead);//pdeviceHead = addRestaurantLightToDeviceLink(pdeviceHead);//pdeviceHead = addLivingroomLightToDeviceLink(pdeviceHead);pdeviceHead = addSmokeAlarmToDeviceLink(pdeviceHead);pdeviceHead = addBuzzerToDeviceLink(pdeviceHead);while(1){tmp = findDeviceByName(smokeName, pdeviceHead);if(tmp != NULL){tmp->Init(tmp->pinNum);smokeStatus = tmp->readStatus(tmp->pinNum);tmp = findDeviceByName(buzzerName, pdeviceHead);if(tmp != NULL){if( smokeStatus == 0 ){tmp->Init(tmp->pinNum);tmp->open(tmp->pinNum);}else{tmp->Init(tmp->pinNum);tmp->close(tmp->pinNum);}           }}}return 0;
}

模块测试

http://www.yayakq.cn/news/219126/

相关文章:

  • 广西钦州住房与城乡建设局网站政协 网站建设
  • 无锡做网站哪家好网站备案 每年
  • 网站怎么申请域名吴江做网站
  • 网站由什么构成如何让自己的网站被百度收录
  • 网站建设与运营培训班WordPress自带写文章
  • 发稿软文公司系统优化有何作用
  • 做网站国内阿里云虚拟主机多少钱邢台建设规划网站
  • 闽侯福州网站建设手机网站免费制作平台有哪些
  • 做网站素材在哪找网店代运营排名
  • 网站怎么做seo步骤wordpress主页加关键词
  • 宏福建设工程有限公司网站深圳网站制作的公司哪家好
  • 网站界面设计说明在我wordpress
  • dede手机网站制作抚州教育网站建设
  • 公司企业网站建设方案书新手如何做外贸
  • 巫山做网站那家好小程序开发公司案例
  • 公众号 接入wordpress郑州网站优化技巧
  • 惠州北京网站建设网店营销推广计划书
  • 大诚设计网站建设slim编辑器Wordpress
  • 诏安县城乡建设局网站营销网站售后调查
  • 成都公司做网站的装修工人
  • 建立网站的基本过程做网店哪个网站好
  • 58同城烟台网站建设手机网站建设与制作
  • 咨询聊城做网站地方网站定位
  • 手机版网站如何制作酒店网站的建设方案
  • 电商网站seo公司网站流量超限什么意思
  • 简述网站建设流程中的各个步骤dw软件下载官方网站
  • 包头网站开发公司网站开发 设计文档
  • 陕西科技网站建设完整的网站开发
  • 企业网站备案怎么做乌市高新区建设局网站
  • 莱州网站建设价格网站备案和服务器备案