美文网首页
Arduino Touch_Switch_Module

Arduino Touch_Switch_Module

作者: 范女青 | 来源:发表于2018-09-20 10:45 被阅读0次

    Touch Switch Module
    The touch switch module requires 4 pins to connected to the Arduino board as input and 2 pins for Vcc and Gnd.
    The touch sensor module has 4 sensor pads with LED diode that shows whether sensor pad is touched.
    Each touch sensor pad has its own value as below:The following code will show the touched pad value (1, 2, 3 or 4).

    You can also try touching multiple pads at the same time.

    bool switch1 = false;
    bool switch2 = false;
    bool switch3 = false;
    bool switch4 = false;
    
    void setup() 
    {
      Serial.begin(9600);
      pinMode(8, INPUT);
      pinMode(9, INPUT);
      pinMode(10, INPUT);
      pinMode(11, INPUT);
    }
    
    void loop() 
    {
      getSwitchSettings();
      Serial.print("Switches On:");
      if(switch1) Serial.print(" 1");
      if(switch2) Serial.print(" 2");
      if(switch3) Serial.print(" 3");
      if(switch4) Serial.print(" 4");
      Serial.println();
      delay(200);
    }
    
    void getSwitchSettings()
    {
      if(digitalRead(8)) switch1 = true;
      else switch1 = false;
      if(digitalRead(9)) switch2 = true;
      else switch2 = false;
      if(digitalRead(10)) switch3 = true;
      else switch3 = false;
      if(digitalRead(11)) switch4 = true;
      else switch4 = false;
    }
    

    相关文章

      网友评论

          本文标题:Arduino Touch_Switch_Module

          本文链接:https://www.haomeiwen.com/subject/olpgnftx.html