int xPin = A1;
int x1Pin = A3;
int yPin = A0;
int y1Pin = A2;
int buttonPin = 2;
int buttonPin1 = 4;int xPosition = 0;
int x1Position = 0;
int yPosition = 0;
int y1Position = 0;
int buttonState = 0;
int buttonState1 = 0;void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(x1Pin, INPUT);
pinMode(y1Pin, INPUT);//activate pull-up resistor on the push-button pin
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
// For versions prior to Arduino 1.0.1
// pinMode(buttonPin, INPUT);
// digitalWrite(buttonPin, HIGH);
}void loop() {
xPosition = analogRead(xPin);
yPosition = analogRead(yPin);
x1Position = analogRead(x1Pin);
y1Position = analogRead(y1Pin);
buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);
Serial.print(“X: “);
Serial.print(xPosition);
Serial.print(” | Y: “);
Serial.print(yPosition);
Serial.print(” | X1: “);
Serial.print(x1Position);
Serial.print(” | Y1: “);
Serial.print(y1Position);
Serial.print(” | Button: “);
Serial.print(buttonState);
Serial.print(” | Button1: “);
Serial.println(buttonState1);delay(500); // add some delay between reads
}
Arduino : Joystik Analog dengan Arduino
Dah lama ngga maen arduino uno … karena kemarin tambah amunisi untuk ardu … maka mulai main lagi dah arduino , oke berikut mini script 2 joystik analog
Berikut Skriptnya :