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?

1ピン入力、十字キーで遊ぶ。(3) (構想編(3)) ロジックづくり STM32C0116-DK

Last updated at Posted at 2025-08-16

目的

  • キー入力のロジックを考える

  • キーが押されていない間は、無限ループ

  • 同じキーの値が二度、検出されたら良しとする

ループから抜けるデバッグ用


if(key_num == 0){key_num = 9;}

プログラム

オンラインコンパイラpaiza


#include <iostream>
using namespace std;

#define PA8 8

int i_key(int Voltage)
{
    return(0);
}

int analogRead(int num)
{
    return(0);
}

int main(void){
    // Your code here!
    
    int sensorValue; //センサーの値(十字キー)
    int Voltage; //(電圧)
    int key_num_in1; //キー番号 比較用1
    int key_num_in2; //キー番号 比較用2
    int key_num = 0; //キー番号 戻り値
    while(key_num == 0){
        sensorValue = analogRead(PA8);  //十字キーから値を読み込む
        Voltage = (sensorValue * 3300) >> 12;  //十字キーの値から電圧に変換
        key_num_in1 = i_key(Voltage); //電圧からキー番号に変換
        key_num_in1 = 3; //デバッグ
        if(key_num_in1 != 0) { //キー番号が0以外
            sensorValue = analogRead(PA8);  //十字キーから値を読み込む
            Voltage = (sensorValue * 3300) >> 12;  //十字キーの値から電圧に変換
            key_num_in2 = i_key(Voltage); //電圧からキー番号に変換
            key_num_in2 = 3;  //デバッグ
            if(key_num_in1 == key_num_in2){//キー番号が同じ時
                key_num = key_num_in2;
            }//endif
        }//endif
        if(key_num == 0){key_num = 9;}
    }//while
    
    printf("key_num = [%d]\n",key_num);
    
}//main




key_num = [3]

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?