Commande à distance contrôlé via Internet (6 / 6 étapes)

Étape 6: Incorporé Aquila Action

Avoir toute cette mise en œuvre, le code pourrait être simplement copié forment le Serial Monitor et le coller comme une nouvelle matrice dans le code. Puis, en ajoutant les fonctions d’action Aquila afin d’appeler cette (ou ces) matrice et avoir une encore meilleure grâce à la plate-forme de l’Aquila (l’avantage de ceci est que vous n’aurez pas besoin d’acheter plus de boutons poussoirs et que vous serez en mesure d’automatiser que je citerai maintenant) de la télécommande.

Voir cela comme une application « simple » pour l’Altair, Imaginez donc lors de la journée N votre TV serait allumer et lancer l’enregistrement de votre émission préférée en la configurant.

Maintenant, nous allons ajouter quelques lignes pour mettre en oeuvre de la plate-forme de l’Aquila. Je suis notamment une matrice avec beaucoup de nombres ; Ce sont ceux que j’ai utilisé la commande à distance envoie à la TV, j’ai utilisé (ce qui en fait, j’ai extrait directement de la Serial Monitor). Vous aurez à changer ces chiffres pour ceux retourne votre Serial Monitor

Bien que j’ai laissés là si on pouvait voir une structure matricielle.

 //Because the timing is very important, we won’t be using digitalRead //for it’s very slow compared with what we’ll be using. //Check the reference link after the code; back on the tutorial. //This (PIND) thing means that form pin 0 to 7 will be READ ONLY #define IRpin_PIN PIND #include <Wire.h> #include <Mesh.h> #include <AquilaProtocol.h></p><p>#define MASK 2 //This will be taken as a binary number (00000010) #define Boton 33 //Built-in Altair Button (It has inverted logif! LOW = Pressed, HIGH = NOT pressed) #define Boton2 10 //Extern button, normal logic! HIGH = Pressed, LOW = Not pressed! #define IR 9 //The longest pulse that will be read is going to be 65ms (when the code applies, it’ll be a microseconds function //So it will NOT be taken as 65000ms (being this 65 seconds); in fact 65 ms is A LOT in this environment. #define MAXPULSE 65000 //Nuestra resolución de tiempo, entre más grande es el valor mejor, //Our time resolution, the bigger the value the better, for it’s more precise //but it takes longer to process it //And we would be losing the precision we won not using digitalRead #define RESOLUTION 20 //El pulso que se recibirá será en pares, 100 pares en éste ámbito es muchísimo //The received pulse will be in pairs, 100 pairs is actually a LOT. uint16_t pulses[100][2]; // Remember that a “value” consist in an ON and OFF from the LED, so in the matrix is stored in pairs. uint8_t currentpulse = 0; // It’ll be used to know how many pairs from ON and OFF have being received. bool full = false;</p><p>uint16_t turnON [120][2]={{46264,1100},{540,1160},{480,1960},{540,1080},{520,1120},{520,1120},{520,1100},{540,1080},{560,1060},{1420,1040},{600,1800},{720,920},{20324,980},{640,980},{660,1780},{740,880},{760,860},{760,880},{760,880},{760,880},{760,860},{1600,900},{760,1700},{760,880},{20384,940},{700,920},{700,1740},{760,880},{760,860},{780,860},{760,880},{760,900},{720,900},{1600,880},{740,1740},{760,860}}; //This is an example of how a code for turning ON a TV looks like, It may be different to yours, so you’ll have to modify the matrix in the next functions (also this one) :)</p><p> uint16_t vUP[120][2]={0}; uint16_t vDWN[120][2]={0}; uint16_t cUP[120][2]={0}; uint16_t cDWN[120][2]={0}; uint16_t inp[120][2]={0}; </p><p>bool encender (uint8_t param, bool gotParam) { Enviar (turnON); delay(500); }</p><p>bool volumenUP (uint8_t param, bool gotParam) { Enviar(vUP); delay(500); }</p><p>bool volumenDWN (uint8_t param, bool gotParam) { Enviar(vDWN); delay(500); }</p><p>bool canalUP (uint8_t param, bool gotParam) { Enviar(cUP); delay(500); }</p><p>bool canalDWN (uint8_t param, bool gotParam) { Enviar(cDWN); delay(500); }</p><p>bool input (uint8_t param, bool gotParam) { Enviar(inp); delay(500); } void setup(void) { Serial.begin(9600); Mesh.begin(); Aquila.begin(); Aquila.setClass("mx.makerlab.test"); Aquila.setName("Control"); Aquila.addAction("Turn On", encender); Aquila.addAction("Volumen +", volumenUP); Aquila.addAction("Volumen -", volumenDWN); Aquila.addAction("Chanel +", canalUP); Aquila.addAction("Chanel -", canalDWN); Aquila.addAction("Input", input); Mesh.announce(HUB); Serial.begin(9600); pinMode(Boton, INPUT); pinMode(Boton2, INPUT); // pinMode(Boton2, INPUT_PULLUP); pinMode(IR, OUTPUT); pinMode(15, OUTPUT); pinMode(14, OUTPUT);</p><p>// 7 6 5 4 3 2 1 0 //TCCR2A - [COM2A1, COM2A0, COM2B1, COM2B0, reserved, reserved, WGM21, WGM20] // 7 6 5 4 3 2 1 0 //TCCR2B - [FOC2A, FOC2B, reserved, reserved, WGM22, CS22, CS21, CS20]</p><p> TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); // A ‘or’ is applies to all of them and it looks like this -> TCCR2A = 0110 0011 (99) TCCR2B = _BV(WGM22) | _BV(CS21); // A ‘or’ is applies and it looks like this -> TCCR2B= 0000 1010 = 10 OCR2A = 25; //Inner time gets to 25 (splitted between the frequency of the micro controller (16MHz) times 2 (because the split will only show the half of the wave, we want to know the duration of a complete cycle. TCCR2A ^= _BV(COM2A1); // Prepares the IR LED</p><p> Serial.println("Ready to decode IR!"); //After this message we’ll know that it has just finished the SETUP part and stats reading pulses. }</p><p>void IRcarrier (unsigned int matrix) { if (matrix != 0) { TCCR2A ^= _BV(COM2A1); //Changes the 8’th bit. Turns the LED ON. delayMicroseconds(matrix); //Waits matrix-microseconds with the LED turned ON. TCCR2A ^= _BV(COM2A1); //Turns the LED off. } }</p><p>void Enviar(uint16_t pulse[120][2]) { digitalWrite(15, LOW); for (int i = 0; i < 120; i++) { if (pulse[i][0] == 0) //If a matrix slot is empty, it leaves the loop. { break; } delayMicroseconds(pulse[i][0]); //Waits n microseconds wi the IR LED off. IRcarrier(pulse[i][1]); //Enters the función sending the delay that takes the ON from the IR } digitalWrite(15, HIGH); }</p><p>//The only thing this función does is printing everything received after the pulse is over. void printpulses() { Serial.println("\n\r\n\rReceived: \n\rOFF\t|\tON"); Serial.print("{"); for (uint8_t i = 0; i < currentpulse; i++) { Serial.print("{"); Serial.print(pulses[i][0], DEC); //DEC <- En caso de que no esté en decimales, esto lo obliga a pasarlo a decimales. Serial.print(","); Serial.print(pulses[i][1], DEC); Serial.print("}"); } Serial.print("};\n"); full = true; } void loop(void) {</p><p>Mesh.loop(); Aquila.loop(); </p><p> digitalWrite(15, HIGH); //Built-in LEDs, inverted logic. digitalWrite(14, HIGH); //Both begin off.</p><p> if (digitalRead(Boton2) == HIGH || (currentpulse != 0)) { if (digitalRead(Boton2) == HIGH) { Serial.println("Leyendo!"); digitalWrite(14, LOW); //GREEN LED ON! full = false; } uint16_t highpulse, lowpulse; // The pulse will be temporary stored on this variables. highpulse = lowpulse = 0; //This process will be splitter in to steps, when the LED is ON; HighPulse and when it’s off; LowPulse. //All this ‘while’ function is for when the pulse is on High (the LED ON) // --- Complex Explanation --- // //We will apply what is on the pin 0-7 a “mask” and we take whatever is on the position 00000100 // If we order the pins this way -> 76543210 we an see in a clearer way that the 00000100 is on the antepenultimate position, same as (xxxxx2xx) //The '&' operator generates a truth table between 00000100 and what is connected to the pins (the micro controller will ignore whatever is not on the pin 2, basically). //So, if there’s anything connected to the PIN 2, it will work. while (IRpin_PIN & (1 << MASK) && full == false) { highpulse++; delayMicroseconds(RESOLUTION); // If the pulse is to long, the scanning ceases. // Writes down everything received and resets counters. if ((highpulse >= MAXPULSE) && (currentpulse != 0)) { printpulses(); currentpulse=0; return; } } // if it never got to the ‘if loop’, then it stores the new high pulse to the matrix. pulses[currentpulse][0] = highpulse; //--------------------------------------------- // The process repeats for the second part of the pulse (remember that it consists on a HIGH and a LOW together) // Is the same as on the other WHILE, only with another notation, where _BV is BITVALUE. Check the assistance links. // And this one will count every time the receiver receives nothing. while (! ( IRpin_PIN & _BV(MASK) ) && full == false) { lowpulse++; delayMicroseconds(RESOLUTION); // If the pulse is too long, the scanning ceases. // Writes down everything received and resets counters. if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) { printpulses(); currentpulse=0; return; } } pulses[currentpulse][1] = lowpulse * RESOLUTION; // A ON-OFF pulse has been read // the whole process will be repeated until some command exceeds the length of a ON or a OFF (and enters to the ‘if loop’). currentpulse++; }</p><p>if (digitalRead(Boton) == LOW && full == true) { Enviar(pulses); delay(500); } digitalWrite(14,HIGH); }</p> 

Articles Liés

Reginald : UDP surveillance bot ; contrôle via Internet

Reginald : UDP surveillance bot ; contrôle via Internet

Reginald démarré à partir du simple, encore "BOLD" idée pour contrôler un bot de n'importe où dans le monde avec un flux vidéo en direct. Ce que je ne m'attendais était pour Reginald se transformer en un projet riche de fonctionnalité impliqués.
Contrôle Edison Intel avec application Android personnalisée via Internet.

Contrôle Edison Intel avec application Android personnalisée via Internet.

¡Hello tout le monde, j'espère que ce projet va vous aider à faire votre propre maison intelligente contrôlée via Internet !Le projet consiste en un système de maison intelligente contrôlé via Internet par une application Android conçue par moi. Étap
Commander un relais sur l’Internet via Arduino avec Teleduino

Commander un relais sur l’Internet via Arduino avec Teleduino

relais sont un ancien mais un goodie. Ils vous permettent de commuter des charges élevées de courant/tension à l'aide d'une sortie numérique de quelque chose comme l'Arduino.Ce qui ferait un relais encore mieux ? Que diriez-vous de contrôler un relai
ITO : Raspberry Pi Robot avec commande à distance caméra Pan/Tilt et de Streamer de la vidéo sur internet

ITO : Raspberry Pi Robot avec commande à distance caméra Pan/Tilt et de Streamer de la vidéo sur internet

(Si vous aimez ce Instructable, n'oubliez pas de voter là-dessus - au-dessus : drapeau de coin à droite. Il est en concurrence sur l'INTERNET des objets et des concours d'automatisation. Merci beaucoup! ;-)Il s'agit d'une deuxième partie de mon précé
Ouvre-porte de Garage mobile via internet

Ouvre-porte de Garage mobile via internet

Ma porte de garage est un moteur tubulaire, avec un récepteur de télécommande dans un 433 MHZ. télécommande piles s'épuiser un jour, mais pas longtemps après que j'ai remplacer la batterie, trouver que le récepteur de télécommande est mauvais. Après
Raspberry Pi Robot contrôlé via Bluetooth

Raspberry Pi Robot contrôlé via Bluetooth

ce tutoriel est basé sur un précédent Instructable -Robots de bâtiment avec Raspberry Pi et PythonLe but est de présenter un exemple de comment mettre en place une connexion série Bluetooth avec Arduino pour contrôler un robot Raspberry Pi. Mais perm
Alarme de mouvement et capteur de sons surveillé et contrôlé Via le Web

Alarme de mouvement et capteur de sons surveillé et contrôlé Via le Web

Dans cette Instructables j'ai vais fait un petit projet avec un bleu de PHPoC du système Sollae (Corée du Sud).PHPoC Blue(P4S-342) est une carte programmable intégrée avec un interprète PHPoC. Il possède 22 broches d'entrées/sorties numériques, 6 ent
Arduino contrôle via un Service Web avec Teleduino

Arduino contrôle via un Service Web avec Teleduino

Convertir votre Arduino en une plate-forme de contrôle web sophistiquée à l'aide de Teleduino.Teleduino est un produit et un service. Une fois l'esquisse de Teleduino a été chargé sur votre Arduino (le « produit »), il se connecte ensuite au serveur
Aéroglisseur RC + commande à distance sur mesure

Aéroglisseur RC + commande à distance sur mesure

Vous aimez les véhicules RC ? Avez-vous envie de voler, mais ont peur des hauteurs ? Ou vous aimez simplement le défi de contrôler un véhicule avec un frottement faible sol?... ou peut-être juste envie d'aéroglisseurs pour certaines ou aucune raison
Commande à distance vos framboises Pi

Commande à distance vos framboises Pi

La plupart des articles qui traitent de journalisation à distance dans votre Pi framboise utilisent xrdp pour créer des sessions Bureau à distance dans votre Pi de framboise. C'est souvent une bonne solution et fonctionne même si vous n'avez pas un m
IPhone à distance contrôlée lampe

IPhone à distance contrôlée lampe

Ce projet utilise l'iPhone et un pi framboise à commande à distance la lampe. L'iPhone et la framboise pi sont connectés au routeur wifi. Le voyant marche/arrêt commandes sont envoyés en iPhone et reçus par le système raspberry pi incorporé. Le raspb
Hyundai Getz, aftermarked distance contrôlée verrouillage central

Hyundai Getz, aftermarked distance contrôlée verrouillage central

so. Je me suis une Hyundai Getz. Belle petite voiture. Verrouillage central a été installé, mais pas télécommandé.Et j'allai et m'a fait un kit de pièces de rechange, voulait que pirater sur le système existant. Quelque chose que j'ai fait 50 fois ou
Ajouter une commande à distance à peu près n’importe quoi !

Ajouter une commande à distance à peu près n’importe quoi !

Dans ce Instructable je vais vous montrer comment ajouter un contrôle à distance à bas prix à peu près n'importe quoi ! qui prend votre fantaisie.L'année dernière, j'ai construit un lance-roquettes de l'air comprimé qui a été présenté dans le Magazin
Appareil photo, commande à distance

Appareil photo, commande à distance

Mon appareil photo n'est pas un moyen d'être déclenchée à l'extérieur. Alors, j'ai décidé de construire une caméra Canon contrôlée à distance et il s'avère être « Vert ».Donc, certains d'entre vous ont peut-être appris du logiciel CHDK (Canon Hack De