#define joyX A0
#define joyY A1
int xValue, yValue;
int mid = 3, topl=4,topm=5,topr=6, botl=8,botm=9,botr=10, but=11,butt=2;
int buttonState = 0;
void setup() {
pinMode(butt,INPUT);
pinMode(mid,OUTPUT);
pinMode(topl,OUTPUT);
pinMode(topm,OUTPUT);
pinMode(topr,OUTPUT);
pinMode(botl,OUTPUT);
pinMode(botm,OUTPUT);
pinMode(botr,OUTPUT);
pinMode(but,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
xValue = analogRead(joyX);
yValue = analogRead(joyY);
buttonState = digitalRead(butt);
if(xValue==509&& yValue==520)
{
digitalWrite(mid,HIGH);
}
else
{
digitalWrite(mid,LOW);
}
if(xValue==0&& yValue==1023)
{
digitalWrite(topl,HIGH);
}
else
{
digitalWrite(topl,LOW);
}
if(xValue==0&& yValue==520)
{
digitalWrite(topm,HIGH);
}
else
{
digitalWrite(topm,LOW);
}
if(xValue==0&& yValue==0)
{
digitalWrite(topr,HIGH);
}
else
{
digitalWrite(topr,LOW);
}
if(xValue==509&& yValue==0)
{
digitalWrite(topr,HIGH);
digitalWrite(botr,HIGH);
}
else
{
digitalWrite(topr,LOW);
digitalWrite(botr,LOW);
}
if(xValue==510&& yValue==1023)
{
digitalWrite(topl,HIGH);
digitalWrite(botl,HIGH);
}
else
{
digitalWrite(topl,LOW);
digitalWrite(botl,LOW);
}
if(xValue==1023&& yValue==520)
{
digitalWrite(botm,HIGH);
}
else
{
digitalWrite(botm,LOW);
}
if(xValue==1023&& yValue==1023)
{
digitalWrite(botl,HIGH);
}
else
{
digitalWrite(botl,LOW);
}
if(xValue==1023&& yValue==0)
{
digitalWrite(botr,HIGH);
}
else
{
digitalWrite(botr,LOW);
}
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(but, HIGH);
} else {
// turn LED off:
digitalWrite(but ,LOW);
}
//print the values with to plot or view
Serial.print(xValue);
Serial.print("\t");
Serial.println(yValue);
}
Comments