Ligne 26 : |
Ligne 26 : |
| Le montage utilise un Trinket 3V avec un accu LiPo de 3.7 et un chargeur d'accu branché sur 5 volts | | Le montage utilise un Trinket 3V avec un accu LiPo de 3.7 et un chargeur d'accu branché sur 5 volts |
| | | |
− | Tutoriel Traduit par Meurisse D. - tutoriel accessible sur http://wiki.mchobby.be/index.php?title=Trinket-Alarme | + | Tutoriel Traduit par Meurisse D. pour www.MCHobby.be - tutoriel accessible sur http://wiki.mchobby.be/index.php?title=Trinket-Alarme |
− | Source: Learning System | + | Tutorial translated by Meurisse D. for www.MCHobby.be - tutorial available at http://wiki.mchobby.be/index.php?title=Trinket-Alarme |
| + | Source: Trinket Bluetooth Alarm System - www.adafruit.com - available on https://learn.adafruit.com/trinket-bluetooth-alarm-system |
| */ | | */ |
| | | |
− | #define SerialPin 0 // Serial debug via Bluefruit EZ-Link on this pin | + | #define SerialPin 0 // Débogage sériel via le Bluefruit EZ-Link branché sur cette broche |
− | #define LEDpin 1 // Use Trinket LED for displaying tripped sensors | + | #define LEDpin 1 // Utiliser la LED du Trinket pour indiquer la détection d'alarme |
− | #define SensorPin 3 // A3 which is GPIO #3 has resistor network to read 3 normally closed sensors | + | #define SensorPin 3 // A3 qui est GPIO #3 utilisant un réseau de résistance pour lire 3 senseurs normalement fermés |
| | | |
| //#define DEBUG | | //#define DEBUG |
| | | |
− | // Serial code, use a Bluefruit EZ-Link with its RX pin connected to Pin 0 of Trinket | + | // code connexion Série, utilise un Bluefruit EZ-Link avec sa broche RX connectée sur la broche 0 du Trinket (TX) |
− | // You will need a terminal program (such as freeware PuTTY for Windows) to get the alerts | + | // Vous aurez besoin d'un programme type Terminal (tel que le freeware PuTTY sous Windows) pour voir les alertes |
− | // but better would be a Processing or Python script looking for alarms. | + | // Mais l'idéal est encore d'utiliser Processing ou un script Python pour surveiller les alarmes. |
| | | |
− | #include <SoftwareSerial.h> // Software serial library (standard in Arduino 1.x +) | + | #include <SoftwareSerial.h> // Bibliothèqye Software serial (standard pour Arduino 1.x +) |
− | SoftwareSerial Serial(2,0); // Serial transmission on Trinket Pin 0, receive pin 2 (not used) | + | SoftwareSerial Serial(2,0); // Communication série - TX/Transmission sur la broche 0, RX/Réception sur la broche 2 (non utilisée) |
| | | |
− | // Multiplex 3 normally closed sensors on one analog pin. If you have 2 sensors, | + | // Multiplexer 3 senseurs normalement ouvert sur un broche analogique. Si vous avez deux senseurs, |
− | // you can leave the one resistor open and adjust the text values accordingly | + | // vous pouvez laisser une résistance ouverte et ajuster le texte en fonction |
− | const uint8_t numSensors = 3; // number of sensors on analog line | + | const uint8_t numSensors = 3; // nombre se senseur sur la broche analogique |
− | const uint8_t states = 8; // 2^numsensors | + | const uint8_t states = 8; // Nombre d'états possible = 2^numsensors |
| uint16_t values[8] = {541, 685, 661, 614, 840, 780, 776, 997}; | | uint16_t values[8] = {541, 685, 661, 614, 840, 780, 776, 997}; |
| char *textval[8] = {"Set","PIR", "2", "3", "PIR+2","PIR+3","2+3","All"}; | | char *textval[8] = {"Set","PIR", "2", "3", "PIR+2","PIR+3","2+3","All"}; |
| | | |
| void setup() { | | void setup() { |
− | pinMode(LEDpin, OUTPUT); // Set GPIO 1 to output to blink LED | + | pinMode(LEDpin, OUTPUT); // configurer le GPIO 1 en sortie (output) pour faire clignoter la LED |
− | pinMode(SensorPin, INPUT); // sets analog pin for input | + | pinMode(SensorPin, INPUT); // configurer la broche analogique en lecture (input) |
− | Serial.begin(9600); // Send status information via serial | + | Serial.begin(9600); // Envoyer l'information de statut via connexion série |
− | Serial.println("Alarm System"); // Initialize message (can read to determine reset) | + | Serial.println("Alarm System"); // Message d'initialisation (peut être utilisé pour détecter un reset) |
| } | | } |
| | | |
| void loop() | | void loop() |
| { | | { |
− | int8_t contact; // read alarm loops (returns -1 if a read error) | + | int8_t contact; // boucle de lecture d'alame |
− | contact = readContact(SensorPin); // | + | contact = readContact(SensorPin); // lecture des senseurs, retourne -1 en cas d'erreur de lecture |
− | if(contact >= 1) { // if any value greater than 0 (set), | + | if(contact >= 1) { // S'il y a une valeur plus grande que 0 ... |
− | Blink(LEDpin, contact); // we have an alarm! Blink LED corresponding to | + | Blink(LEDpin, contact); // alors nous avons une alarme! Faire clignoter la LED en fonction du senseur activé |
− | Serial.print("Alarm! "); // which sensor(s) and write to Bluetooth | + | Serial.print("Alarm! "); // Envoyer l'info sur Bluetooth |
| Serial.println(textval[contact]); | | Serial.println(textval[contact]); |
| } | | } |
− | else if(contact < 0) { // a bad analog read was done. If you get errors | + | else if(contact < 0) { // Il y a une erreur de lecture sur la broche analogique. Si vous obtenez des erreurs |
− | Serial.print("Error"); // set DEBUG, walk test, record values, and | + | Serial.print("Error"); // alors activez le DEBUG, faites vos test, relevez les valeurs, et |
− | } // update code with analogread values | + | } // faite une mise-à-jour du code avec les valeurs lues sur la broche analogique |
| else { | | else { |
− | Serial.println("Set"); // Alarm is set (no sensors tripped), all is well | + | Serial.println("Set"); // l'Alarme est active "Set" et il n'y a aucun senseur activé. Tout va bien :-) |
| } | | } |
| | | |
− | delay(500); // We do not need to poll the sensors very often although you can change | + | delay(500); // Il n'est pas nécessaire de vérifier les senseurs très souvent. Vous pouvez néanmoins modifier le délais |
| } | | } |
| | | |
| int8_t readContact(uint8_t TrinketPin) | | int8_t readContact(uint8_t TrinketPin) |
− | // returns the number corresponding to sensor values. | + | // Retourne une valeur numérique correspondant aux valeurs du senseur. |
− | // TrinketPin is the analog pin on the Trinket (A1=#2, A2=#4, A3=#3) | + | // Les broches du Trinket sont en analogique (A1=#2, A2=#4, A3=#3) |
| { | | { |
− | const int variance = 8; // Analog readings can vary, use this value for +- variance | + | const int variance = 8; // Les lectures analogiques peuvent varier un petit peu. |
| + | // utilisons la valeur +-variance pour tenir compte de la divergence |
| int contact = 0; | | int contact = 0; |
| uint16_t readval = 0; | | uint16_t readval = 0; |
− | readval = analogRead(TrinketPin); // Check the pin | + | readval = analogRead(TrinketPin); // Lecture de la broche |
| #ifdef DEBUG | | #ifdef DEBUG |
− | Serial.print(": Sensor read value: "); | + | Serial.print(": valeur lue sur le senseur: "); |
| Serial.println(readval); | | Serial.println(readval); |
| #endif | | #endif |
− | for(uint8_t i=0; i<states; i++) { // if reading is near state value, return that state | + | for(uint8_t i=0; i<states; i++) { |
| + | // Si la valeur lue est proche d'une valeur d'un état (state), alors retourner l'identification |
| + | // de l'état |
| if(readval >= (values[i]-variance) && readval <= (values[i]+variance) ) { | | if(readval >= (values[i]-variance) && readval <= (values[i]+variance) ) { |
| return(i); | | return(i); |
| } | | } |
| } | | } |
− | return -1; // value not one of the alarm system values | + | return -1; // La valeur ne correspond pas à une alarme système |
| } | | } |
| | | |
− | // This routine toggkes a pin the number you pass. Good to use on LED pin to | + | // Cette fonction fait clignoter une broche du nombre de fois indiqué. |
− | // output which sensors are triggered | + | // Utile pour brancher une LED sur une broche afin de d'indiquer et |
| + | // identifier quel senseur à été déclenché |
| void Blink(uint8_t pin, uint8_t times) { | | void Blink(uint8_t pin, uint8_t times) { |
| for(uint8_t i=1; i<=times; i++) { | | for(uint8_t i=1; i<=times; i++) { |
Ligne 107 : |
Ligne 112 : |
| }</nowiki> | | }</nowiki> |
| | | |
− | Remember to comment out the DEBUG line for your final installation.
| + | N'oubliez pas de remettre la ligne DEBUG débug en commentaire pour lors de l'installation finale. |
| | | |
| {{Trinket-Alarme-TRAILER}} | | {{Trinket-Alarme-TRAILER}} |