按键开关示例程序

按键开关 按下为1 松开为0

const int kgPin=2;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(kgPin,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int kgValue= digitalRead(kgPin);
  Serial.println(kgValue);
}

posted @ 2022-12-17 10:07  new-code  阅读(63)  评论(0)    收藏  举报