int joy_x=32;
int joy_y=34;
int sw=13;
int led=19;
int pot=34;
int buzzer=12;
void setup(){
pinMode(sw, INPUT_PULLUP);
pinMode(buzzer,OUTPUT);
pinMode(led,OUTPUT);
ledcSetup(0,5000,8);//pwm channel,pwm_fequency,pwm_resolution
ledcAttachPin(led,0);
ledcSetup(2,4000,8);
ledcAttachPin(buzzer,2);
Serial.begin(115200);
}
void loop(){
int hor= analogRead(joy_x);
int ver=analogRead(joy_y);
int pot=analogRead(pot);
pot=map(pot,0,4095,0,255);
hor=map(hor,0,4095,0,255);
ver=map(ver,0,4095,0,255);
if (digitalRead(sw)==LOW){
digitalWrite(led,HIGH);
}
else{
digitalWrite(led,LOW);
}
if (pot >127){
ledcWrite(0,pot);
}
else{
ledcWriteTone(2,2000);
}
if (hor<10){
Serial.print("joy stick horizontally");
Serial.println("Full left");
}
else if( hor>240){
Serial.print("joy stick horizontally");
Serial.println("Full right");
}
if (ver<10){
Serial.print("joy stick vertically");
Serial.println("Full up");
}
else if (ver>240){
Serial.print("joy stick vertically");
Serial.println("Full down")
}
}