首页 > 其他分享 >hdu物联网硬件实验2 GPIO亮灯

hdu物联网硬件实验2 GPIO亮灯

时间:2024-07-05 13:55:33浏览次数:11  
标签:hdu LED 亮灯 int ledState HIGH LOW GPIO ledState1

学院

班级

学号

姓名

日期

成绩

实验题目

GPIO亮灯

实验目的

点亮三个灯闪烁频率为一秒

硬件原理

关键代码及注释

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

const int ledPin2 =  YELLOW_LED;

const int ledPin3 =  RED_LED;

// Variables will change:

int ledState = LOW;             // ledState used to set the LED

int ledState1 = LOW;

int ledState2 = LOW;

int ledState3 = LOW;

int count1=0;

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;           // interval at which to blink (milliseconds)

void setup() {

  // set the digital pin as output:

  pinMode(ledPin1, OUTPUT);

  pinMode(ledPin2, OUTPUT);

  pinMode(ledPin3, OUTPUT);      

}

void loop()

{

  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the

  // difference between the current time and last time you blinked

  // the LED is bigger than the interval at which you want to

  // blink the LED.

  unsigned long currentMillis = millis();

  

  if(count1<3 ||(count1>=8 &&count1<11)){

  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;

      count1+=1;

      }

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

 digitalWrite(ledPin1, ledState);

 digitalWrite(ledPin2, ledState);

 digitalWrite(ledPin3, ledState);

 }

}

if(count1>=3 && count1<8){

  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;

      count1+=1;         //最后一个灯闪过之后,count+1

      }

      else if(ledState3 == HIGH){

      ledState3 = LOW;

      ledState1 = HIGH;

      }

 digitalWrite(ledPin1, ledState1);

 digitalWrite(ledPin2, ledState2);

 digitalWrite(ledPin3, ledState3);

  }

}

}

实验步骤

  1. 三个灯一起闪3次
  2. 跑马灯5遍
  3. 三个灯一起闪3次
  4. 熄灭

实验结果

思考与反馈

标签:hdu,LED,亮灯,int,ledState,HIGH,LOW,GPIO,ledState1
From: https://blog.csdn.net/SWZ156/article/details/140206645

相关文章

  • In what kind of situations that no pull would be configured as a input gpio
    InthecontextofGPIOconfiguration,thechoicebetweenusingapull-up,pull-down,ornopullresistordependsonthespecificrequirementsoftheapplicationandtheexternalcircuitryconnectedtotheGPIOpin.NoPullConfigurationWhenGPIO_InitStru......
  • 关于GPIO合封引脚以及晶振引脚使用注意事项
    CH32系列某些小封装芯片可能会存在合封引脚,如下图。以下图8脚为例,为PD4、PD5、PD1的合封引脚,其中PD1引脚还作为SWIO下载引脚。若要使用PD4引脚作为普通IO输出高低电平,注意在进行程序配置时需要注意:(1)PD4引脚按照GPIO输出配置;(2)合封引脚PD5和PD1要配置为浮空输入模式;(3)PD1同时作为SWIO......
  • HDU-4281 Judges' response(2012 ACM/ICPC Asia Regional Tianjin Online)
    HDU-4281Judges'response(2012ACM/ICPCAsiaRegionalTianjinOnline)状态压缩+01背包+区间dp题意:有n个地点,第一个地点是裁判位置,其他n-1个地点是选手的位置。裁判要给选手解决问题,每个选手都有一个时间表示解决这个选手问题所需要的时间。同样的,裁判也有一个时间,表示这......
  • GPIO的工作模式
    输入模式:输入浮空、输入上拉、输入下拉、模拟输入输出模式:开漏输出、开漏复用功能、推挽式输出、推挽式输出复用功能输入浮空:输入上拉:输入下拉:开漏输出:开漏复用功能:推挽式输出:推挽式输出复用功能:......
  • 杰里AW31N GPIO配置
    (配置GPIO详细具体可以看官网的手册,我就是快速列举几个能用的供参考,可能不全但是测过能用)1.配置引脚状态 可以用intgpio_init(enumgpio_portport,conststructgpio_config*config);intgpio_set_mode(enumgpio_portport,u32pin,enumgpio_modemode);举例str......
  • STM32入门HAL库-GPIO点灯
    目录1.目标2.背景知识3.过程1.目标通过HAL库操作GPIO口,使灯闪烁2.背景知识GPIO即通用输入输出查阅手册,可以了解到STM32中GPIO支持功能这里是点灯,点灯这里用到了GPIO的输出功能3.过程引脚配置界面,选择对应引脚输出功能这里是PB7主函数中编写代码HAL......
  • Railway HDU - 3394 求调
    做个记录,如果有人愿意帮我调蒟蒻将感激不尽qwq#include<iostream>#include<iomanip>#include<cstdio>#include<vector>#include<stack>#include<queue>#include<bitset>#include<map>#include<set>#include<unorde......
  • hdu2845dp问题
    看了一眼题目,简单dp问题,但超时了一晚上,试了各种方法无法解决,最终放弃java,改用C直接过,我哭了。。。。#include<stdio.h>#include<string.h>#definemaxn200010intdp[maxn],ans[maxn],map[maxn];intmax(intx,inty){returnx>y?x:y;}intmain(){inti,j;......
  • 【MT9669】GPIO IRQ功能在驱动中使用说明
    在MT9669的Linux Kernel中,驱动要如何实现中断操作呢?下面是对于非PM GPIO口实现IRQ的相应操作说明:1.在MT9669中对于GPIOIRQ的对应关系说明如下: 在bootable/bootloader/mboot-mtk/mboot/sboot/inc/M7642/board/BD_MT167B_10AT_MT5888_M7642.h中有如下内容:#definePADS_EX......
  • 泰山派学习12--GPIO_LED字符设备驱动
    一、GPIO寄存器1、对GPIO进行控制有以下步骤①:是能GPIO的时钟(默认开启,不用配置);②:设置引脚复用为GPIO(复位默认配置GPIO,不用配置);③:设置引脚属性(上下拉、速率、驱动能力,默认不用配置);④:控制GPIO引脚为输出,并且输出高低电平。2、GPIO功能引脚及寄存器rk3566有5个gpio控制器......