printf("ho_tari\n");

08_Joystick 본문

Arduino

08_Joystick

호타리 2023. 9. 2. 12:36
const int Xin = A0;
const int Yin = A1;
const int KEYin = 3;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(KEYin, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  int xVal = analogRead(Xin);
  int yVal = analogRead(Yin);
  int buttonVal = digitalRead(KEYin);

  Serial.print("X= ");
  Serial.println(xVal, DEC);

  Serial.print("Y= ");
  Serial.println(yVal, DEC);

  Serial.print("Button is ");

  if (buttonVal == HIGH) 
  {
    Serial.println("NOT PRESSED");
  } 
  else 
  {
    Serial.println("PRESSED");
  }

  delay(300);
}

'Arduino' 카테고리의 다른 글

10_Ultrasonic  (0) 2023.09.02
09_Tone  (0) 2023.09.02
07_Analog_Read  (0) 2023.09.02
06_Switch_Input_Interrupt  (0) 2023.09.02
05_Switch_Input  (0) 2023.09.02