소스코드
아래는 소스코드입니다. 아두이노 IDE에 붙여넣기 하여 컴파일하고 업로드합니다.
#define joyX A0 #define joyY A1 int SW_pin = 2; int swState = 0; int swState1 = 0; void setup() { pinMode(7,OUTPUT); pinMode(SW_pin,INPUT); digitalWrite(SW_pin, HIGH); Serial.begin(9600); } void loop() { int xValue = analogRead(joyX); int yValue = analogRead(joyY); Serial.print("X-axis: "); Serial.print(xValue); Serial.print("\t"); Serial.print("Y-axis: "); Serial.println(yValue); swState = digitalRead(SW_pin); Serial.println(swState); if (xValue>=1000) digitalWrite(10, HIGH); else digitalWrite(10, LOW); if (xValue<25) digitalWrite(11, HIGH); else digitalWrite(11, LOW); if (yValue>=1000) digitalWrite(9, HIGH); else digitalWrite(9, LOW); if (yValue<25) digitalWrite(8, HIGH); else digitalWrite(8, LOW); if (swState == LOW) { Serial.println("Switch = High"); digitalWrite(7, HIGH); } else digitalWrite(7, LOW); swState1 = digitalRead(7); Serial.println(swState1); delay(50); }