Toll-Free Customer Support 24/7

Joystick Shield

/*
* Project name:
Joystick Shield
* Copyright
(c) Researchdesignlab.com
* Description:

* Test configuration:
MCU: ATMEGA328
Dev.Board: Arduino uno
Oscillator: 16 MHz
Software: Arduino

*/
const int analogInPin1 = A0; // Analog input pin that the potentiometer is attached to x axis Joystick
const int analogInPin2 = A1; // Analog input pin that the potentiometer is attached to y axis Joystick
const int buttonPin_A = 3; // the number of the pushbutton A pin
const int buttonPin_B = 4; // the number of the pushbutton B pin
const int buttonPin_C = 5; // the number of the pushbutton C pin
const int buttonPin_D = 6; // the number of the pushbutton D pin
const int buttonPin_E = 7; // the number of the pushbutton E pin
const int buttonPin_F = 8; // the number of the pushbutton F pin


int sensorValue = 0; // value read from the pot
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
Serial.println("Joystick Shield with XBEE RDL ");
Serial.println(" " );

// initialize the pushbutton pin as an input:
pinMode(buttonPin_A, INPUT);
pinMode(buttonPin_B, INPUT);
pinMode(buttonPin_C, INPUT);
pinMode(buttonPin_D, INPUT);
pinMode(buttonPin_E, INPUT);
pinMode(buttonPin_F, INPUT);

}

void loop() {

// read the input on analog pin 0 x axis:
sensorValue = analogRead(analogInPin1);

Serial.print("x = " );
Serial.print(sensorValue); // print out the value you read:

// read the input on analog pin 1 y axis:
sensorValue = analogRead(analogInPin2);

Serial.print(" y = " );
Serial.print(sensorValue); // print out the value you read:

// read the state of the pushbutton A value:
buttonState = digitalRead(buttonPin_A);
// check if the pushbutton A is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.print(" BUTTON A " );
}

// read the state of the pushbutton B value:
buttonState = digitalRead(buttonPin_B);
// check if the pushbutton B is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.print(" BUTTON B " );
}

// read the state of the pushbutton C value:
buttonState = digitalRead(buttonPin_C);
// check if the pushbutton C is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.print(" BUTTON C " );
}
// read the state of the pushbutton D value:
buttonState = digitalRead(buttonPin_D);
// check if the pushbutton D is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.print(" BUTTON D " );
}

// read the state of the pushbutton E value:
buttonState = digitalRead(buttonPin_E);
// check if the pushbutton E is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.print(" BUTTON E " );
}

// read the state of the pushbutton F value:
buttonState = digitalRead(buttonPin_F);
// check if the pushbutton F is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
Serial.print(" BUTTON F " );
}
Serial.println(" " );
delay(1000);
}

Back to top