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

hdu物联网硬件实验3 按键和中断

学院

班级

学号

姓名

日期

成绩

实验题目

按键和中断

实验目的

实现闪灯功能转换

硬件原理

关键代码及注释

/*

  Button

 Turns on and off a light emitting diode(LED) connected to digital  

 pin 13, when pressing a pushbutton attached to pin 2.

 The circuit:

 * LED attached from pin 13 to ground

 * pushbutton attached to pin 2 from +3.3V

 * 10K resistor attached to pin 2 from ground

 * Note: on most Arduinos there is already an LED on the board

 attached to pin 13.

 created 2005

 by DojoDave <http://www.0j0.org>

 modified 30 Aug 2011

 by Tom Igoe

 modified Apr 27 2012

 by Robert Wessels

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/Button

 */

// constants won't change. They're used here to

// set pin numbers:

const int buttonPin = PUSH2;     // the number of the pushbutton pin

const int ledPin1 =  GREEN_LED;      // the number of the LED pin

const int ledPin2 =  YELLOW_LED;

const int ledPin3 =  RED_LED;

int ledState = LOW;

int ledState1 = LOW;

int ledState2 = LOW;

int ledState3 = LOW;

volatile bool state = HIGH;

int count = 0;

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

long previousMillis = 0;        // will store last time LED was updated

long term = 0;

// the follow variables is a long because the time, measured in miliseconds,

// will quickly become a bigger number than can be stored in an int.

long interval = 1000;  

void setup() {

  // initialize the LED pin as an output:

  pinMode(ledPin1, OUTPUT);      

  pinMode(ledPin2, OUTPUT);

  pinMode(ledPin3, OUTPUT);

  //digitalWrite(ledPin,state);

  pinMode(buttonPin,INPUT_PULLUP);

  attachInterrupt (buttonPin ,blink ,RISING);

}

void blink(){

  state = !state;

}

void loop(){

  unsigned long currentMillis = millis();

  

  if(state==HIGH){

  if(currentMillis - previousMillis > interval) {

    // save the last time you blinked the LED

    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:

    if (ledState == LOW)

      ledState = HIGH;

    else{

      ledState = LOW;

      

      }

    // set the LED with the ledState of the variable:

 digitalWrite(ledPin1, ledState);

 digitalWrite(ledPin2, ledState);

 digitalWrite(ledPin3, ledState);

 }

}

else{

  if(currentMillis - previousMillis > interval) {

    previousMillis = currentMillis;  

    if (ledState1 == LOW && ledState2 == LOW && ledState3 == LOW)

      ledState1 = HIGH;

    else if(ledState1 == HIGH){

      ledState1 = LOW;

      ledState2 = HIGH;

      }

     else if(ledState2 == HIGH){

      ledState2 = LOW;

      ledState3 = HIGH;

             

      }

      else if(ledState3 == HIGH){

      ledState3 = LOW;

      ledState1 = HIGH;

     

      }

 digitalWrite(ledPin1, ledState1);

 digitalWrite(ledPin2, ledState2);

 digitalWrite(ledPin3, ledState3);

  }

}

}

实验步骤

在上次作业基础上加上了按钮,中断

实验结果

思考与反馈

相关文章:

hdu物联网硬件实验3 按键和中断

学院 班级 学号 姓名 日期 成绩 实验题目 按键和中断 实验目的 实现闪灯功能转换 硬件原理 无 关键代码及注释 /* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached…...

pytorch通过 tensorboardX 调用 Tensorboard 进行可视化

示例 import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader from torchvision import datasets, transformsfrom tensorboardX import SummaryWriter# 定义神经网络模型 class SimpleCNN(nn.Module):def __init__(self):…...

linux查看目录下的文件夹命令,find 查找某个目录,但是不包括这个目录本身?

linux查看目录下的文件夹命令&#xff0c;find 查找某个目录&#xff0c;但是不包括这个目录本身&#xff1f; Linux中查看目录下的文件夹的命令是使用ls命令。ls命令用于列出指定目录中的文件和文件夹。通过不同的选项可以实现显示详细信息、按照不同的排序方式以及使用不同的…...

单一设备上的 2 级自动驾驶:深入探究 Openpilot 的奥秘

Level 2 Autonomous Driving on a Single Device: Diving into the Devils of Openpilot 单一设备上的 2 级自动驾驶&#xff1a;深入探究 Openpilot 的奥秘 Abstract Equipped with a wide span of sensors, predominant autonomous driving solutions are becoming more m…...

向github远程仓库中push,要求使用token登录

Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. 如上&#xff0c;当向github远程仓库push时&#xff0c;输入github的用户名和密码出现如上错误&#xff0c;要求使用token登录&#xff0c;此时只需要用户…...

最全windows提权总结(建议收藏)

当以低权用户进去一个陌生的windows机器后&#xff0c;无论是提权还是后续做什么&#xff0c;第一步肯定要尽可能的搜集信息。知己知彼&#xff0c;才百战不殆。 常规信息搜集 systeminfo 查询系统信息hostname 主机名net user 查看用户信息netstat -ano|find "3389&quo…...

Could not find Chrome (ver.xxxxx). This can occur if either\n

文章目录 错误解决方法 错误 Could not find Chrome (ver. 119.0.6045.105). This can occur if either\n 1. you did not perform an installation before running the script (e.g. npx puppeteer browsers install chrome) or\n 2. your cache path is incorrectly configu…...

Conmi的正确答案——ESP32-C3开启安全下载模式

IDF版本&#xff1a;4.4.7 注意事项&#xff1a;一旦烧录“安全下载模式”&#xff0c;模组将无法被读取或清理&#xff0c;只能通过eclipse原项目烧录程序进行重新烧录&#xff0c;无法再烧录其他固件。 20240703110201——追加解法&#xff0c;暂时无法解安全下载模式 &…...

从零开始实现大语言模型(一):概述

1. 前言 大家好&#xff0c;我是何睿智。我现在在做大语言模型相关工作&#xff0c;我用业余时间写一个专栏&#xff0c;给大家讲讲如何从零开始实现大语言模型。 从零开始实现大语言模型是了解其原理及领域大语言模型实现路径的最好方法&#xff0c;没有之一。已有研究证明&…...

科普文本分类背后的数学原理——最新版《数学之美》第14、15章读书笔记

新闻分类&#xff0c;或广义上的文本分类&#xff0c;其核心任务是根据文本内容将相似文本聚合在同一类别中。在新闻领域&#xff0c;这意味着将报道划分为财经、体育、军事等不同主题。人类执行此任务时&#xff0c;通过阅读和理解新闻的主旨来进行归类。然而&#xff0c;作者…...

华为云生态和快速入门

华为云生态 新技术催生新物种&#xff0c;新物种推动新生态 数字技术催生各类运营商去重塑并颠覆各行业的商业模式 从业务层面看&#xff0c;企业始终如一的目标是业务增长和持续盈利&#xff0c;围绕这些目标衍生出提质、增效、降本、安全、创新和合规的业务诉求&#xff0c…...

卷积神经网络——LeNet——FashionMNIST

目录 一、整体结构二、model.py三、model_train.py四、model_test.py GitHub地址 一、整体结构 二、model.py import torch from torch import nn from torchsummary import summaryclass LeNet(nn.Module):def __init__(self):super(LeNet,self).__init__()self.c1 nn.Conv…...

k8s-第十二节-DaemonSet

DaemonSet是什么? DaemonSet 是一个确保全部或者某些节点上必须运行一个 Pod的工作负载资源(守护进程),当有node(节点)加入集群时, 也会为他们新增一个 Pod。 下面是常用的使用案例: 可以用来部署以下进程的pod 集群守护进程,如Kured、node-problem-detector日志收集…...

Mysql-内置函数

一.什么是函数&#xff1f; 函数是指一段可以直接被另外一段程序调用的程序或代码。 mysql内置了很多的函数,我们只需要调用即可。 二.字符串函数 MySQL中内置了很多字符串函数: 三.根据需求完成以下SQL编写 由于业务需求变更,企业员工的工号,统一为5位数,目前不足5位数的全…...

新浪API系列:支付API打造无缝支付体验,畅享便利生活(3)

在当今数字化时代&#xff0c;支付功能已经成为各类应用和平台的必备要素之一。作为开发者&#xff0c;要构建出安全、便捷的支付解决方案&#xff0c;新浪支付API是你不可或缺的利器。新浪支付API提供了全面而强大的接口和功能&#xff0c;帮助开发者轻松实现在线支付的集成和…...

终于弄明白了什么是EI!

EI是Engineering Index的缩写&#xff0c;中文意为“工程索引”&#xff0c;是由美国工程信息公司(Engineering Information, Inc.)编辑出版的著名检索工具。它始创于1884年&#xff0c;拥有超过一个世纪的历史&#xff0c;是全球工程界最权威的文献检索系统之一。EI虽然名为“…...

微信小程序常见页面跳转方式

1. wx.navigateTo() 保留当前页&#xff0c;跳转到不是 tabbar 的页面&#xff0c;会新增页面到页面栈。通过返回按钮或 wx.navigateBack()返回上一个页面。 2. wx.redirectTo() 跳转到不是 tabbar 的页面&#xff0c;替换当前页面。不能返回。 3. wx.switchTab() 跳转到 …...

Vim常用整理快捷键

一、光标跳转 参数释义w下一行首字符e下一行尾字符0跳至行首$跳至行尾gg跳至文首5gg跳至第五行gd标记跳转到当前光标所在的变量的定义位置fn找当前行后的n字符&#xff0c;跳转到n字符位置 二、修改类操作 参数释义D删除光标之后的字符dd删除整行x删除当前字符yy复制一行p向…...

【docker 把系统盘空间耗没了!】windows11 更改 ubuntu 子系统存储位置

系统&#xff1a;win11 ubuntu 22 子系统&#xff0c;docker 出现问题&#xff1a;系统盘突然没空间了&#xff0c;一片红 经过排查&#xff0c;发现 AppData\Local\packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\ 这个文件夹竟然有 90GB 下面提供解决办法 步…...

前端如何让网页页面完美适配不同大小和分辨率屏幕

推荐使用postcss插件&#xff0c;它会自动将项目所有的px单位统一转换为vw等单位&#xff08;包括npm安装的第三方组件&#xff09;&#xff0c;从而实现适配&#xff0c;具体配置规则可参考官网或npm网站介绍。 另外对于大屏的适配&#xff0c;需要缩放网页&#xff0c;可使用…...

【网络】每天掌握一个Linux命令 - iftop

在Linux系统中&#xff0c;iftop是网络管理的得力助手&#xff0c;能实时监控网络流量、连接情况等&#xff0c;帮助排查网络异常。接下来从多方面详细介绍它。 目录 【网络】每天掌握一个Linux命令 - iftop工具概述安装方式核心功能基础用法进阶操作实战案例面试题场景生产场景…...

RocketMQ延迟消息机制

两种延迟消息 RocketMQ中提供了两种延迟消息机制 指定固定的延迟级别 通过在Message中设定一个MessageDelayLevel参数&#xff0c;对应18个预设的延迟级别指定时间点的延迟级别 通过在Message中设定一个DeliverTimeMS指定一个Long类型表示的具体时间点。到了时间点后&#xf…...

脑机新手指南(八):OpenBCI_GUI:从环境搭建到数据可视化(下)

一、数据处理与分析实战 &#xff08;一&#xff09;实时滤波与参数调整 基础滤波操作 60Hz 工频滤波&#xff1a;勾选界面右侧 “60Hz” 复选框&#xff0c;可有效抑制电网干扰&#xff08;适用于北美地区&#xff0c;欧洲用户可调整为 50Hz&#xff09;。 平滑处理&…...

c++ 面试题(1)-----深度优先搜索(DFS)实现

操作系统&#xff1a;ubuntu22.04 IDE:Visual Studio Code 编程语言&#xff1a;C11 题目描述 地上有一个 m 行 n 列的方格&#xff0c;从坐标 [0,0] 起始。一个机器人可以从某一格移动到上下左右四个格子&#xff0c;但不能进入行坐标和列坐标的数位之和大于 k 的格子。 例…...

【开发技术】.Net使用FFmpeg视频特定帧上绘制内容

目录 一、目的 二、解决方案 2.1 什么是FFmpeg 2.2 FFmpeg主要功能 2.3 使用Xabe.FFmpeg调用FFmpeg功能 2.4 使用 FFmpeg 的 drawbox 滤镜来绘制 ROI 三、总结 一、目的 当前市场上有很多目标检测智能识别的相关算法&#xff0c;当前调用一个医疗行业的AI识别算法后返回…...

回溯算法学习

一、电话号码的字母组合 import java.util.ArrayList; import java.util.List;import javax.management.loading.PrivateClassLoader;public class letterCombinations {private static final String[] KEYPAD {"", //0"", //1"abc", //2"…...

力扣热题100 k个一组反转链表题解

题目: 代码: func reverseKGroup(head *ListNode, k int) *ListNode {cur : headfor i : 0; i < k; i {if cur nil {return head}cur cur.Next}newHead : reverse(head, cur)head.Next reverseKGroup(cur, k)return newHead }func reverse(start, end *ListNode) *ListN…...

GitHub 趋势日报 (2025年06月06日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 590 cognee 551 onlook 399 project-based-learning 348 build-your-own-x 320 ne…...

【JVM】Java虚拟机(二)——垃圾回收

目录 一、如何判断对象可以回收 &#xff08;一&#xff09;引用计数法 &#xff08;二&#xff09;可达性分析算法 二、垃圾回收算法 &#xff08;一&#xff09;标记清除 &#xff08;二&#xff09;标记整理 &#xff08;三&#xff09;复制 &#xff08;四&#xff…...

【LeetCode】3309. 连接二进制表示可形成的最大数值(递归|回溯|位运算)

LeetCode 3309. 连接二进制表示可形成的最大数值&#xff08;中等&#xff09; 题目描述解题思路Java代码 题目描述 题目链接&#xff1a;LeetCode 3309. 连接二进制表示可形成的最大数值&#xff08;中等&#xff09; 给你一个长度为 3 的整数数组 nums。 现以某种顺序 连接…...