vincent84:
Bonjour,super réalisation ! Les codes sont-ils disponible ?
Bonsoir,
Le code pour la Uno du server et les NodeMCU se compose du très gros sketch fourni par le plugin Jeedouino (qui s'adapte selon le model d'Arduino), il faut penser à activer UserSketch sinon le code rajouté ne sera pas exécuté
#define UserSketch 1
Le code pour les sonnettes (joue "Never gonna give you up" de Rick Astley lors d'une pression sur le bouton filaire, puis se connecte au Wi-Fi et indique au server Jeedom qu'un malotru sonne à la porte, puis se rendort (je suis en train d'intégrer le deepsleep)
A copier dans UserVars :
// UserVars
// Vos declarations de variables / includes etc....
int jeedomSyncRound = 0;
const int buzzerPin = 5;
// RickAstley
const int songLength = 18;
char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int tempo = 150;
int duration;
int frequency(char note)
{
// This function takes a note character (a-g), and returns the
// corresponding frequency in Hz for the tone() function.
int i;
const int numNotes = 8; // number of notes we're storing
// The following arrays hold the note characters and their
// corresponding frequencies. The last "C" note is uppercase
// to separate it from the first lowercase "c". If you want to
// add more notes, you'll need to use unique characters.
// For the "char" (character) type, we put single characters
// in single quotes.
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
// Now we'll search through the letters in the array, and if
// we find it, we'll return the frequency for that note.
for (i = 0; i < numNotes; i++) // Step through the notes
{
if (names[i] == note) // Is this the one?
{
return(frequencies[i]); // Yes! Return the frequency
}
}
return(0); // We looked through everything and didn't find it,
// but we still need to return a value, so return 0.
}
// RickAstley
A copier dans UserSetup :
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin,LOW);
A copier dans UserLoop :
if(analogRead(A0) < 500)
{
delay(42);
if(analogRead(A0) < 500)
{
jeedom += '&';
jeedom += 500; // Etat pin 500
jeedom += '=';
jeedom += '1'; // '0' ou '1'
jeedomSyncRound = 1;
for (int i = 0; i < songLength; i++) // step through the song arrays
{
duration = beats[i] * tempo; // length of note/rest in ms
if (notes[i] == ' ') // is this a rest?
{
delay(duration); // then pause for a moment
}
else // otherwise, play the note
{
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration); // wait for tone to finish
}
delay(tempo/10); // brief pause between notes
}
digitalWrite(buzzerPin,LOW);
}
}
if (jeedomSyncRound == 1) jeedomSyncRound = 2;
if (jeedomSyncRound == 2) jeedomSyncRound = 3;
if (jeedomSyncRound == 3)
{
jeedom += '&';
jeedom += 500; // Etat pin 500
jeedom += '=';
jeedom += '0'; // '0' ou '1'
jeedomSyncRound = 0;
}
A savoir que :
-> J'ai implanté jeedomSyncRound pour que UserLoop s'exécute plusieurs fois avant de repasser la pin virtuelle 500 à 0 afin que Jeedom comprenne que la pin 500 est passé à 1 quelques instants (sans cela la pin 500 ne se met pas à jour dans Jeedom (pour affirmer cela je ne me base pas sur l'affichage dashboard mais sur un scénario programmé pour se lancer lorsque cette pin change de valeur qui ne se lance pas)
-> Pour la mélodie, je l'ai récupéré ici : Simple Audio Board – Bitcows LLC
-> La condition analogRead(A0) < 500 est doublée pour éviter les faux positifs
-> Je n'ai pas le code pour la Uno dans mon cloud, je le posterai dès que possible...