zoukankan      html  css  js  c++  java
  • 用Tinkercad学arduino之 输入串行上拉

    /*
     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.
     
     OPEN THE SERIAL MONITOR TO SEE THE OUTPUT FROM THE INPUT PIN >>
    
     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);
      }
    }
  • 相关阅读:
    LVS,NET,TUNL,DR实现负载均衡
    Redis的基本数据结构,基本操作
    mongoDB基本操作
    mysql高级操作(优化)
    sphix使用及即时索引配置
    java client 通过zookeeper连接hbase问题
    TCP/UDP load balance
    Hacking your way to enlightenment with Kafka and Node.js
    flume问题
    linux点滴
  • 原文地址:https://www.cnblogs.com/meetrice/p/14078483.html
Copyright © 2011-2022 走看看