본문 바로가기

카테고리 없음

[ARDUINO] 아두이노 튜토리얼 10 : Joy stick

아두이노 튜토리얼 10 : Joy stick 조이스틱

아두이노 기초 튜토리얼 목표

열번째, Arduino 강좌에서는 ARDUINO 아두이노로 조이스틱, Joystick 을 읽는 코드를 만들어보고 실행해본다.

아두이노로 Joystick 조이스틱 어플리케이션을 만들어보자!

makepluscode 조이스틱 예제

실습코드

아두이노 스케치에서 다음 조이스틱 Joystick 값을 읽는 코드를 Write 한다.

 

void setup()
{
    // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(8, INPUT);
    pinMode(9, INPUT);
    pinMode(10,INPUT);
    digitalWrite(10, HIGH);
}

void loop()
{
    // put your main code here, to run repeatedly:
    int x;
    int y;
    int Button;

    x = analogRead(8);
    y = analogRead(9);
    Button = digitalRead(10);

    Serial.print("X Axis ");
    Serial.print(x, DEC);

    Serial.print(", Y Axis ");
    Serial.print(y, DEC);

    Serial.print(", Button State is ");

    if(Button == 0)
    {
        Serial.println("ON");
    }
    else if(Button == 1)
    {
        Serial.println("OFF");
    }
    delay(300);
   }

조이스틱 Joystick 값을 읽는 코드의 설명은 다음과 같다.

  1. 8번 포트를 입력으로 설정하고 analogRead 함수로  값을 읽는다.
  2. 9번 포트를 입력으로 설정하고 analogRead 함수로  값을 읽는다.
  3. 10번 포트를 입력으로 설정하고 digitalRead 함수로  값을 읽는다.
  4. 8번 포트의 값은 Joystick 의  X 축 각도 이다. 읽은 값을 출력한다.
  5. 9번 포트의 값은 Joystick 의  Y 축 각도 이다. 읽은 값을 출력한다.
  6. 10번 포트의 값은 Button 누름 상태이다. 읽은 값에 따라서 On 또는 Off 를 출력한다.

동영상 튜토리얼

조이스틱 Joystick 값을 읽는 예제는 아래 동영상 강의를 참고한다.

https://youtu.be/iZdrN16ENuk?list=PL46rwaN5jZCnwEoje4n_-rWZJqCbebBeF 

Joystick 값을 읽는 예제 코드는 다음 github 를 참고한다.

https://github.com/makepluscode/arduino-tutorial-basic/blob/master/10-Joystick/10.ino

 

GitHub - makepluscode/arduino-tutorial-basic: Repositories for Arduino Tutorial Basic.

Repositories for Arduino Tutorial Basic. Contribute to makepluscode/arduino-tutorial-basic development by creating an account on GitHub.

github.com