배송 |
---|
상품 정보 | 가격 | 삭제 |
---|---|---|
[조이스틱 모듈 Grove Type] 아두이노 | ||
TOTAL PRICE(수량) 0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | // 조이스틱의 X 및 Y 축이 연결된 아날로그 핀 설정 const int xAxisPin = 5; const int yAxisPin = 6; // 스위치 핀 설정 const int switchPin = 7; void setup() { // 시리얼 통신 초기화 Serial.begin(9600); // 스위치 핀을 입력으로 설정 pinMode(switchPin, INPUT_PULLUP); } void loop() { // X 및 Y 축에서 아날로그 값 읽기 int xAxisValue = digitalRead(xAxisPin); int yAxisValue = digitalRead(yAxisPin); // 스위치 상태 읽기 int switchState = digitalRead(switchPin); // 읽은 값 시리얼 모니터에 출력 Serial.print("X축: "); Serial.print(xAxisValue); Serial.print(", Y축: "); Serial.print(yAxisValue); Serial.print(", 스위치: "); Serial.println(switchState); // 500ms 지연 delay(500); } | cs |