아두이노

조이스틱 AxisJoystic

iseohyun 2022. 1. 17.

목차

    코드 정보 : (주의! 출력이 서보모터와 연동되어 있습니다.)

    #include <Joystick.h>
    #include <AxisJoystick.h>
    
    #include <Servo.h>
    
    #define PIN_PWM 9
    #define MIN 0
    #define MAX 180
    
    #define SW_PIN 5
    #define VRX_PIN A1
    #define VRY_PIN A2
    
    Joystick* joystic;
    Servo moter;
    int theta;
    
    void setup() {
    	Serial.begin(9600);
    
    	joystic = new AxisJoystick(SW_PIN, VRX_PIN, VRY_PIN);
    	
    	moter.attach(PIN_PWM, MIN,	MAX);
    	moter.writeMicroseconds(20);
    }
    
    void loop() {
    	Serial.print(joystic->readVRx());
    	theta = joystic->readVRx()/(1024/180);
    	Serial.println(" | " + String(theta));
    	moter.write(theta);
    	delay(10);
    }

     

    라이브러리 정보 : https://www.arduino.cc/reference/en/libraries/axisjoystick/

     

    AxisJoystick - Arduino Reference

    Reference > Libraries > Axisjoystick AxisJoystick Signal Input/Output The Library implements a set of methods for working with an axis joystick controller. Dual axis XY joystick module reading. Author: Yurii Salimov Maintainer: Yurii Salimov Read the docum

    www.arduino.cc

     

    '아두이노' 카테고리의 다른 글

    LED  (0) 2022.01.17
    건반 만들기  (0) 2022.01.17
    서보모터 SG90  (0) 2022.01.17
    온도, 습도 센서 (KY-015)  (0) 2022.01.17
    아날로그 입력  (0) 2022.01.17

    댓글