×

如何用嘴打开LED

消耗积分:0 | 格式:zip | 大小:0.09 MB | 2022-12-21

张红

分享资料个

描述

 
pYYBAGOiYIGAKeYZAAFAAqLDmLI946.jpg
 

在本教程中,我将向您展示如何用嘴打开 LED。当开始吹声音传感器时,LED 将亮起。

第 1 步:材料和设置

 
pYYBAGOiYIOAB48oAADv3_hXz5A392.jpg
 

这个项目需要的材料是:

  • Linkit One 板
  • LED
  • 数字声音传感器
  • 3公对母跳线
  • 微型 USB 数据线

要设置 LinkIt ONE 开发板,请点击此链接

传感器与 LinkIt ONE 开发板的连接:

传感器 LinkIt ONE

5v<------------>5v

接地 <--------> 接地

输出 <----------> D2

第 2 步:代码

将此代码上传到您的 LinkIt ONE 开发板。这实际上是来自 Arduino IDE 的数字上拉示例

/* Input Pullup Serial This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a digital input on pin 2 and prints the results to the serial monitor. The circuit: * Momentary switch attached from pin 2 to ground * Built-in LED on pin 13 Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal 20K-ohm resistor is pulled to 5V. This configuration causes the input to read HIGH when the switch is open, and LOW when it is closed. created 14 March 2012 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/InputPullupSerial This example code is in the public domain */void setup() {  //start serial connection  Serial.begin(9600);  //configure pin2 as an input and enable the internal pull-up resistor  pinMode(2, INPUT_PULLUP);  pinMode(13, OUTPUT);}void loop() {  //read the pushbutton value into a variable  int sensorVal = digitalRead(2);  //print out the value of the pushbutton  Serial.println(sensorVal);  // Keep in mind the pullup means the pushbutton's  // logic is inverted. It goes HIGH when it's open,  // and LOW when it's pressed. Turn on pin 13 when the  // button's pressed, and off when it's not:  if (sensorVal == HIGH) {    digitalWrite(13, LOW);  }  else {    digitalWrite(13, HIGH);  }}

第 3 步:测试

上传代码后。打开串口监视器,然后当你吹响声音传感器时,你会看到 LED 也会亮起。

吹的时间越长,LED 点亮的时间就越长。


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !