Day4 06-joystick
2024. 2. 4. 15:55ㆍarduino
- 조이스틱으로 입력받아 시리얼 모니터에 출력하기
const int Xin = A0;
const int Yin = A1;
const int Keyin = 2;
volatile bool isBtnPressed = false;
void ISRBtn(){
isBtnPressed = true;
}
void setup() {
// put your setup code here, to run once:
pinMode(Keyin, INPUT_PULLUP);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(Keyin), ISRBtn, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
int xVal = analogRead(Xin);
int yVal = analogRead(Yin);
int btnVal = digitalRead(Keyin);
Serial.println("X = "+String(xVal)+ " Y :"+String(yVal));
if (isBtnPressed) {
isBtnPressed = false;
Serial.println("Btn pressed!");
delay(500);
}
}
'arduino' 카테고리의 다른 글
Day4 07-tetris (0) | 2024.02.04 |
---|---|
Day4 05-DCmotor, button 2 (0) | 2024.02.04 |
Day4 04-DCmotor, button (0) | 2024.02.04 |
Day4 03-DCmotor (0) | 2024.02.04 |
Day4 02-encoder (0) | 2024.02.04 |