Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arduino Joystick Shield Joystick ve Led
#define joy_x A0
#define joy_y A1
#define led_x_1 10
#define led_x_2 11
#define led_x_3 12
#define led_x_4 13
#define led_y_1 A2
#define led_y_2 A3
#define led_y_3 A4
#define led_y_4 A5
int x= 0;
int y= 0;
void setup()
{
pinMode(joy_x, INPUT);
pinMode(joy_y, INPUT);
pinMode(led_x_1, OUTPUT);
pinMode(led_x_2, OUTPUT);
pinMode(led_x_3, OUTPUT);
pinMode(led_x_4, OUTPUT);
pinMode(led_y_1, OUTPUT);
pinMode(led_y_2, OUTPUT);
pinMode(led_y_3, OUTPUT);
pinMode(led_y_4, OUTPUT);
Serial.begin(9600);
}
void loop()
{
//Joystick x ekseni
Serial.print(" ||| ");
Serial.print("X: ");
x = analogRead(joy_x);
Serial.println(x);
if ( x >= 0 && x < 250 )
{
digitalWrite(led_x_1, HIGH);
digitalWrite(led_x_2, HIGH);
}
else if ( x >= 250 && x < 511)
{
digitalWrite(led_x_1, HIGH);
digitalWrite(led_x_2,LOW);
}
else if ( x >= 511 && x < 517 )
{
digitalWrite(led_x_1, LOW);
digitalWrite(led_x_2, LOW);
digitalWrite(led_x_3, LOW);
digitalWrite(led_x_4, LOW);
}
else if ( x >= 517&& x < 750)
{
digitalWrite(led_x_3, HIGH);
digitalWrite(led_x_4,LOW);
}
else if ( x >= 750 && x <= 1023)
{
digitalWrite(led_x_3, HIGH);
digitalWrite(led_x_4, HIGH);
}
else
{
digitalWrite(led_x_1, LOW);
digitalWrite(led_x_2, LOW);
digitalWrite(led_x_3, LOW);
digitalWrite(led_x_4, LOW);
}
//Joystick y ekseni
Serial.print(" ||| ");
Serial.print("Y: ");
y = analogRead(joy_y);
Serial.println(y);
if ( y >= 0 && y < 250 )
{
digitalWrite(led_y_1, HIGH);
digitalWrite(led_y_2, HIGH);
}
else if ( y >= 250 && y < 512)
{
digitalWrite(led_y_1, HIGH);
digitalWrite(led_y_2,LOW);
}
else if ( y >= 512 && y < 522 )
{
digitalWrite(led_y_1, LOW);
digitalWrite(led_y_2, LOW);
digitalWrite(led_y_3, LOW);
digitalWrite(led_y_4, LOW);
}
else if ( y >= 522 && y < 750)
{
digitalWrite(led_y_3, HIGH);
digitalWrite(led_y_4,LOW);
}
else if ( y >= 750 && y <= 1023)
{
digitalWrite(led_y_3, HIGH);
digitalWrite(led_y_4, HIGH);
}
else
{
digitalWrite(led_y_1, LOW);
digitalWrite(led_y_2, LOW);
digitalWrite(led_y_3, LOW);
digitalWrite(led_y_4, LOW);
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment