gabbyshimoni icon

joystickExample

gabbyshimoni | PRO | 02/10/19 07:58:36 AM UTC | 0 ⭐ | 920 👁️ | Never ⏰ | []
C++ |

570 B

|

None

|

0 👍

/

0 👎

#define potXPin A0
#define potYPin A1
#define pbPin  3
int pbValue = 0;
int potXVal=0, potYVal=0;
 
void setup ()
{
  pinMode (pbPin  , INPUT);
  Serial.begin (9600); 
}
void loop ()
{
  potXVal= analogRead (potXPin );
  potYVal= analogRead (potYPin );
  pbValue = digitalRead (pbPin  );
  
  Serial.print("X = ");
  Serial.println (potXVal);
  
  Serial.print ("Y = ");
  Serial.println (potYVal);
  
  Serial.print("Button is ");
  if (pbValue == HIGH){
    Serial.println ("not pressed");
  }
  else{
    Serial.println ("PRESSED");
  }
  delay (500);
}

Comments