I have problem with joystick
code: [select]
int joysag;
int joysol;
int pot;
void setup() {
// put setup code here, run once:
pinmode(11,output);
pinmode(3,output);
pinmode(6, output);
pinmode(5, output);
}
void loop() {
// put main code here, run repeatedly:
joysag=analogread(a2);
joysag=map(joysag,0,1023,0,2);
joysol=analogread(a1);
joysol=map(joysol,0,1023,0,2);
pot=analogread(a0);
pot=map(pot,0,1023,0,2);
if(pot==0){
analogwrite(11,0);
analogwrite(6,0);
analogwrite(5,0);
analogwrite(3,0);
}
if(pot==1&&joysag==1&&joysol==1){
analogwrite(11,170);
analogwrite(6,170);
analogwrite(5,170);
analogwrite(3,170);
}
if(pot==1&&joysag==1&&joysol==0){
analogwrite(11,255);
analogwrite(6,170);
analogwrite(5,170);
analogwrite(3,170);
}
if(pot==1&&joysag==1&&joysol==2){
analogwrite(11,170);
analogwrite(6,255);
analogwrite(5,170);
analogwrite(3,170);
}
if(pot==1&&joysag==0&&joysol==1){
analogwrite(11,170);
analogwrite(6,170);
analogwrite(5,255);
analogwrite(3,170);
}
if(pot==1&&joysag==2&&joysol==1){
analogwrite(11,170);
analogwrite(6,170);
analogwrite(5,170);
analogwrite(3,255);
}
if(pot==2&&joysag==1&&joysol==1){
analogwrite(11,255);
analogwrite(6,255);
analogwrite(5,255);
analogwrite(3,255);
}
if(pot==2&&joysag==1&&joysol==0){
analogwrite(11,255);
analogwrite(6,170);
analogwrite(5,170);
analogwrite(3,170);
}
if(pot==2&&joysag==1&&joysol==2){
analogwrite(11,170);
analogwrite(6,255);
analogwrite(5,170);
analogwrite(3,170);
}
if(pot==2&&joysag==0&&joysol==1){
analogwrite(11,170);
analogwrite(6,170);
analogwrite(5,255);
analogwrite(3,170);
}
if(pot==2&&joysag==2&&joysol==1){
analogwrite(11,170);
analogwrite(6,170);
analogwrite(5,170);
analogwrite(3,255);
}
}[\code]
i wanted control 4 leds code did nonsense things.
what doing different thought told do?
how did wire joystick , pot? are connected +5v @ 1 end gnd @ other?
how did wire joystick , pot? are connected +5v @ 1 end gnd @ other?
Arduino Forum > Using Arduino > Programming Questions > I have problem with joystick
arduino
Comments
Post a Comment