Update README.md

This commit is contained in:
Gnieark 2016-03-28 23:48:31 +02:00
parent 2751c43a52
commit 0d99b4edf9

View File

@ -4,15 +4,27 @@ Arduino's code is something like:
```c ```c
int joystickPin = A0; int joystickPin = A0;
int getPushedButton(int joystickPin){ int getPushedButton(int joystickPin){
/*
* retourne le numéro du boutton appuyé
* bouton | numéro | mesure analogRead
* aucun | 0 | 1024
* haut | 1 | 19
* bas | 2 | 8
* gauche: | 3 | 54
* droite: | 4 | 705
* bas2 : | 5 | 511
* haut2: | 6 | 183
*/
int val=analogRead(joystickPin); int val=analogRead(joystickPin);
if(val > 1000){ if(val > 1000){
return 0; return 0;
}else if (val > 650){ }else if (val > 650){
return 4; return 4;
}else if(val > 450){ }else if(val > 450){
return 6;
}else if(val > 120){
return 5; return 5;
}else if(val > 120){
return 6;
}else if(val > 45){ }else if(val > 45){
return 3; return 3;
}else if(val > 15){ }else if(val > 15){
@ -21,6 +33,19 @@ int getPushedButton(int joystickPin){
return 2; return 2;
} }
} }
void setup() {
Serial.begin(9600);
}
void loop() {
int button=getPushedButton(A0);
Serial.println(button);
delay(500);
}
``` ```
Adapt limit values if you use differents resistors than mines. Adapt limit values if you use differents resistors than mines.