Bonjour, je debute totalement dans la programation et je suis unpeu perdu. Mon proget serai de fair un jeu d adresse pour mes enfants, j ai donc fait ce prototype de sorte que si l aneau (D10 ) touche le fil de cuivre cela inremente le score (aficheur 7 segments) de 0 à 9. Pour faire varier la sensibilitée j ai pansé faire varier la valeur de delay via le potentiometre et pouvoir recommencer une partie en appuient sur reset. Concretement ca fonctionne pas mal mais pas dans le simulateur et j ignore pourquoi. Maintenant je bute sur un probleme car je voudrai q a chaque"touche" du fil un "bip" soit emis par un piezo par exemple mais qu il ne dure que 500ms et je ne vois pas comment "imbriquer" ca dans le programe.
par avance merci.
/home/philippe/Images/Capture d’écran de 2022-06-11 15-56-16.png
/home/philippe/Images/Capture d’écran de 2022-06-11 16-56-08.png
#define A 8 // bornes de laficheur 7 seg
#define B 7
#define C 6
#define D 5
#define E 4
#define F 3
#define G 2
#define TOUCH 10 // borne de l aneau
#define RESET 9 // bouton de raz
byte v = 0;
int dificultee = 0;
int analogInPin = A0; // borne du potentiometre de dificultee
int sensorValue = 0;
void setup() {
Serial.begin(9600);
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(TOUCH, INPUT);
pinMode(RESET, INPUT);
}
void loop() { // 0
sensorValue = analogRead(analogInPin);
map(sensorValue, 0, 1023, 0, 255);
Serial.print("sensor = ");
Serial.println(sensorValue);
Serial.print("\t output = ");
digitalWrite (dificultee,analogInPin);
delay(2);
digitalWrite(A, HIGH);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
delay(dificultee); // valeure de la dificultee du potentiometre
if (digitalRead(TOUCH) == LOW) {
v = 1;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
while (v == 1) { // 1
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 2;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 2) { // 2
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, HIGH);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 3;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 3) { // 3
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 4;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 4) { // 4
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, HIGH);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 5;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 5) { // 5
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 6;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 6) { // 6
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, HIGH);
digitalWrite(G, LOW);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 7;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 7) { // 7
digitalWrite(A, HIGH);
digitalWrite(B, HIGH);
digitalWrite(C, HIGH);
digitalWrite(D, HIGH);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 8;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 8) { // 8
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 9;
}
if (digitalRead(RESET) == LOW) {
v = 0;}
}
while (v == 9) {
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, HIGH);
digitalWrite(D, LOW);
digitalWrite(E, LOW);
digitalWrite(F, LOW);
digitalWrite(G, LOW);
delay(dificultee);
if (digitalRead(TOUCH) == LOW) {
v = 0;
}
if (digitalRead(RESET) == LOW) {
v = 0;
}
}
}