Arduino 入门学习笔记5 按键控制激光发生器

版权声明:(谢厂节的博客)博主文章绝大部分非原创,转载望留链接。 https://blog.csdn.net/xundh/article/details/83691532

代码

/**********************************************/
const int keyPin = 13; //the "s" of relay module attach to
const int laserPin = 7;
/**********************************************/
void setup()
{
  pinMode(laserPin, OUTPUT); //initialize relay as an output
  pinMode(keyPin, INPUT);
}
/***********************************************/
void loop()
{
  boolean Value=digitalRead(keyPin);
  if(Value==HIGH){
    digitalWrite(laserPin, LOW); //disconnect the relay   
  }else
    digitalWrite(laserPin, HIGH); //Close the relay
}
/*************************************************/


接线图

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xundh/article/details/83691532