Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
projets:cadran_tel [31/01/2018 18:40] Mathieu Hery |
projets:cadran_tel [13/02/2018 20:29] (Version actuelle) Mathieu Hery [Ressources] |
||
|---|---|---|---|
| Ligne 7: | Ligne 7: | ||
| ====Visuel==== | ====Visuel==== | ||
| - | à venir | + | {{:projets:cablage-cadran.jpg?400}} |
| + | {{:projets:dial.jpg?400}} | ||
| ---- | ---- | ||
| ==== Code arduino ==== | ==== Code arduino ==== | ||
| + | <code> | ||
| + | int needToPrint = 0; | ||
| + | int count; | ||
| + | int in = 2; | ||
| + | int lastState = LOW; | ||
| + | int trueState = LOW; | ||
| + | long lastStateChangeTime = 0; | ||
| + | int cleared = 0; | ||
| - | en cours | + | // constants |
| + | |||
| + | int dialHasFinishedRotatingAfterMs = 100; | ||
| + | int debounceDelay = 10; | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(9600); | ||
| + | pinMode(in, INPUT); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | int reading = digitalRead(in); | ||
| + | |||
| + | if ((millis() - lastStateChangeTime) > dialHasFinishedRotatingAfterMs) { | ||
| + | // the dial isn't being dialed, or has just finished being dialed. | ||
| + | if (needToPrint) { | ||
| + | // if it's only just finished being dialed, we need to send the number down the serial | ||
| + | // line and reset the count. We mod the count by 10 because '0' will send 10 pulses. | ||
| + | Serial.print(count % 10, DEC); | ||
| + | needToPrint = 0; | ||
| + | count = 0; | ||
| + | cleared = 0; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | if (reading != lastState) { | ||
| + | lastStateChangeTime = millis(); | ||
| + | } | ||
| + | if ((millis() - lastStateChangeTime) > debounceDelay) { | ||
| + | // debounce - this happens once it's stablized | ||
| + | if (reading != trueState) { | ||
| + | // this means that the switch has either just gone from closed->open or vice versa. | ||
| + | trueState = reading; | ||
| + | if (trueState == HIGH) { | ||
| + | // increment the count of pulses if it's gone high. | ||
| + | count++; | ||
| + | needToPrint = 1; // we'll need to print this number (once the dial has finished rotating) | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | lastState = reading; | ||
| + | } | ||
| + | </code> | ||
| ---- | ---- | ||
| Ligne 19: | Ligne 72: | ||
| ==== Ressources ==== | ==== Ressources ==== | ||
| - | [[http://www.instructables.com/id/Interface-a-rotary-phone-dial-to-an-Arduino/|Lien vers page instructables]] //(en anglais)// | + | *[[http://www.instructables.com/id/Interface-a-rotary-phone-dial-to-an-Arduino/|Lien vers page instructables]] //(en anglais)// |
| + | *[[https://learn.sparkfun.com/tutorials/mp3-player-shield-hookup|Lien vers page Sparkfun]] //(en anglais)// | ||
| ---- | ---- | ||
| - | //Projet par Damien// | + | //Projet par Damien & Mathieu// |
