issue91:arduino
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue91:arduino [2015/01/02 16:01] – créée andre_domenech | issue91:arduino [2015/02/15 14:27] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ** | ||
This month we’ll finish our first major Arduino contraption. It’s what I call the laser trip-wire. At the moment, we can arm and disarm the system, and our LDR can detect the loss of the laser. Let’s add to it with another component: the buzzer. | This month we’ll finish our first major Arduino contraption. It’s what I call the laser trip-wire. At the moment, we can arm and disarm the system, and our LDR can detect the loss of the laser. Let’s add to it with another component: the buzzer. | ||
Ligne 17: | Ligne 18: | ||
and: | and: | ||
- | pinMode (buzzer, OUTPUT); | + | pinMode (buzzer, OUTPUT); |
- | analogWrite(armedLed, | + | analogWrite(armedLed, |
I also added a new IF statement to check (via the LDR) if the laser is on/off: | I also added a new IF statement to check (via the LDR) if the laser is on/off: | ||
- | if (sensorHit < 700 && armed == 1){ //beep when armed & beam broken | + | if (sensorHit < 700 && armed == 1){ // beep when armed & beam broken |
- | tone(buzzer, | + | tone(buzzer, |
} | } | ||
+ | ** | ||
+ | Ce mois-ci nous allons terminer notre première véritable maquette Arduino. C'est ce que j' | ||
+ | |||
+ | Entrez le code pour l' | ||
+ | |||
+ | Mais d' | ||
+ | |||
+ | J'ai récupéré le texte de « pitches » et l' | ||
+ | |||
+ | J'ai ajouté un peu de code pour mettre les choses en place : | ||
+ | |||
+ | const int buzzer = A2; // le buzzer est sur la broche A2 | ||
+ | |||
+ | int notes[]={ | ||
+ | |||
+ | NOTE_A4, NOTE_B4, NOTE_C3 }; | ||
+ | |||
+ | et : | ||
+ | |||
+ | pinMode (buzzer, OUTPUT); | ||
+ | |||
+ | analogWrite(armedLed, | ||
+ | |||
+ | J'ai aussi ajouté une nouvelle instruction IF pour vérifier (via la LDR) si le laser est allumé ou éteint : | ||
+ | |||
+ | if (sensorHit < 700 && armed == 1){ // bip quand armé & faisceau coupé | ||
+ | tone(buzzer, | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | ** | ||
I found (via the serial window) that the LDR registers about 600 when the LDR is not being hit by the laser. So, in my IF statement and in the main loop, I’m saying: ‘if the system is armed and the LDR is registering less than 700 the laser must be broken so sound tone 3 via the buzzer’. | I found (via the serial window) that the LDR registers about 600 when the LDR is not being hit by the laser. So, in my IF statement and in the main loop, I’m saying: ‘if the system is armed and the LDR is registering less than 700 the laser must be broken so sound tone 3 via the buzzer’. | ||
I also added to the ‘wrong guess’ code: | I also added to the ‘wrong guess’ code: | ||
- | tone(buzzer, | + | < |
which just plays tone 1, a ‘boop’ noise, to let you know you got the code wrong. | which just plays tone 1, a ‘boop’ noise, to let you know you got the code wrong. | ||
Ligne 43: | Ligne 76: | ||
With a demonstration of the system at: https:// | With a demonstration of the system at: https:// | ||
+ | |||
+ | ** | ||
+ | |||
+ | J'ai trouvé (via la fenêtre de série) que la LDR indique environ 600 quand elle n'est pas touchée par le laser. Donc, dans mon instruction IF de la boucle principale, je vais dire : « si le système est armé et si la LDR indique moins de 700, le laser doit être coupé donc jouer le son 3 via le buzzer ». | ||
+ | |||
+ | J'ai aussi ajouté au code « wrong guess » (mauvaise réponse) : | ||
+ | |||
+ | < | ||
+ | |||
+ | qui joue juste le son 1, un bruit « boop », pour que vous sachiez que vous avez entré un code erroné. | ||
+ | |||
+ | Vous pouvez, bien sûr, utiliser une boucle while pour jouer plusieurs tons et avoir une alarme (ou un refrain) plus élaborée. | ||
+ | |||
+ | Y aurait-il des projets similaires que vous souhaiteriez que j' | ||
+ | |||
+ | Le code complet est ici : http:// | ||
+ | |||
+ | Et il y a une démonstration du système ici : https:// | ||
+ |
issue91/arduino.1420210870.txt.gz · Dernière modification : 2015/01/02 16:01 de andre_domenech