饂飩コーディング

iOSアプリやら、Unityやら、Cocos2dやらごにょごにょ書いております

Input_PullDownでタクトスイッチ使ってみよう

サイトが引っ越しました。→https://scombu.com

約1秒後に自動的にリダイレクトします。切り替わらない場合はリンクをクリックしてください。

f:id:appdeappuappu:20200510095417j:plain
タクトボタンが見えにくいけど

f:id:appdeappuappu:20200510093957p:plain
タクトスイッチ

#define switchiButtonPin 13 
#define ledPin 10 
int buttonState = 0;

void setup() {
  pinMode(ledPin, OUTPUT);      
  pinMode(switchiButtonPin, INPUT_PULLUP); // Inputモードでプルアップ
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {     // ボタンが押されていたら、ピンの値はLOW
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    digitalWrite(ledPin, LOW); 
  }
  delay(50);
  
}


こちらを参考にさせていただきました。↓
novicengineering.com