1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5NanoC6、GROVER- MicroSwitch(マイクロスイッチ(リミットスイッチ))で遊ぶ。(スイッチクラス利用)

Last updated at Posted at 2024-10-24

今回のお題

o_coq558.jpg

o_coq559.jpg

目的
Groveポートを通して接点の状態を入力して遊ぶ
何でも良かったんだけど、安く、早く手に入ったのが
マイクロスイッチ

結果

o_coq557.jpg

o_coq560.jpg

プログラム




//button_Grover_button_M5NanoC6_1

#include <M5NanoC6.h>

#include "Arduino.h"
#include "utility/Button_Class.hpp"

using namespace m5;

Button_Class BtnS;


void setup() {

    NanoC6.begin();

    pinMode(1, INPUT); //Grover GPIO1
  
    pinMode(M5NANO_C6_BLUE_LED_PIN, OUTPUT);
}


void loop() {
    
    uint32_t ms = millis();
    BtnS.setRawState(ms, digitalRead(1)); //Grover GPIO1

    
    if (BtnS.wasPressed()) {
        Serial.println("Button A was pressed");
        digitalWrite(M5NANO_C6_BLUE_LED_PIN, HIGH);
    }
    if (BtnS.wasHold()) {
        Serial.println("Button A was hold");
    }
    if (BtnS.wasReleased()) {
        Serial.println("Button A was released");
        digitalWrite(M5NANO_C6_BLUE_LED_PIN, LOW);
    }
}


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?