Se envían mensajes aleatorios a un televisor panasonic

Dependencies:   TextLCD mbed

Committer:
NicolasV
Date:
Sat Jun 03 01:06:07 2017 +0000
Revision:
1:ed8910f358bc
Parent:
0:15536ec3bf58
Control Loco;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NicolasV 0:15536ec3bf58 1 /** Control Loco.
NicolasV 0:15536ec3bf58 2
NicolasV 0:15536ec3bf58 3 Por: Laura Ávila
NicolasV 0:15536ec3bf58 4 Daniela López
NicolasV 0:15536ec3bf58 5 Nicolás Villegas
NicolasV 0:15536ec3bf58 6
NicolasV 0:15536ec3bf58 7 Este programa interfiere de forma loca la operación de un televisor.
NicolasV 0:15536ec3bf58 8 Emite códigos de t.v. con el fin de fastidiar al televidente.
NicolasV 0:15536ec3bf58 9
NicolasV 0:15536ec3bf58 10 El control utilizado es de marca Panasonic. Se encontró que los códigos IRDA para
NicolasV 0:15536ec3bf58 11 esta referencia tienen una longitud de 48 bits. Se modificó el programa "Capturas IRDA"
NicolasV 0:15536ec3bf58 12 para ajustarse a esta característica y con base en eso se obtuvieron los códigos.
NicolasV 0:15536ec3bf58 13
NicolasV 0:15536ec3bf58 14 La emisión es aleatoria para
NicolasV 0:15536ec3bf58 15 1 Mute
NicolasV 0:15536ec3bf58 16 2 On/Off
NicolasV 0:15536ec3bf58 17 3 Vol+
NicolasV 0:15536ec3bf58 18 4 Vol-
NicolasV 0:15536ec3bf58 19 5 Ch+
NicolasV 0:15536ec3bf58 20 6 Ch-
NicolasV 0:15536ec3bf58 21 */
NicolasV 0:15536ec3bf58 22
NicolasV 0:15536ec3bf58 23 #include "mbed.h"
NicolasV 0:15536ec3bf58 24 #include <Timer.h>
NicolasV 0:15536ec3bf58 25 #include <math.h>
NicolasV 0:15536ec3bf58 26 #include "TextLCD.h"
NicolasV 0:15536ec3bf58 27
NicolasV 0:15536ec3bf58 28 Timer timer;
NicolasV 1:ed8910f358bc 29 DigitalOut led(PTE31);
NicolasV 0:15536ec3bf58 30 DigitalOut indic(LED2);
NicolasV 0:15536ec3bf58 31 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7
NicolasV 0:15536ec3bf58 32
NicolasV 0:15536ec3bf58 33 int code[50];
NicolasV 0:15536ec3bf58 34 int aleatorio(int a, int b);
NicolasV 0:15536ec3bf58 35 void enviar_uno(int duracion);
NicolasV 0:15536ec3bf58 36 void enviar_codigo(int n_bits, int *code);
NicolasV 0:15536ec3bf58 37
NicolasV 0:15536ec3bf58 38 const int n_bits = 48;
NicolasV 0:15536ec3bf58 39 const int header_L = 3440;
NicolasV 0:15536ec3bf58 40 const int header_H = 1737;
NicolasV 0:15536ec3bf58 41
NicolasV 0:15536ec3bf58 42 const unsigned ch_up[] = {449,1346,477,477,476,476,476,477,477,476,476,476,476,1346,476,477,477,478,476,475,476,476,477,1347,475,475,475,476,477,475,476,475,476,476,1346,476,1348,1320,476,475,475,476,1345,476,1347,1320,476,1346};
NicolasV 0:15536ec3bf58 43 const unsigned ch_down[] = {452,1323,451,452,452,453,452,454,452,451,453,451,453,1323,454,451,452,452,453,452,451,452,452,1322,451,451,453,452,453,452,454,451,1300,451,1322,453,1322,1322,451,451,1322,452,1322,451,1297,1298,450,1323};
NicolasV 0:15536ec3bf58 44 const unsigned mute[] = {457,1326,456,457,456,456,456,456,457,458,481,457,458,1326,481,455,456,456,457,457,456,456,457,1326,458,455,456,456,458,456,480,454,458,1327,456,456,1327,1327,455,458,457,1327,481,457,1328,1326,455,1328};
NicolasV 0:15536ec3bf58 45 const unsigned power[] = {476,1347,476,477,475,477,475,476,476,476,475,450,476,1347,476,475,476,476,476,478,477,477,475,1346,477,476,477,476,476,476,477,476,1346,477,1346,1347,1346,1347,475,477,1347,476,1324,1347,1346,1325,456,1327};
NicolasV 0:15536ec3bf58 46 const unsigned vol_up[] = {452,1322,452,452,452,453,452,451,451,452,452,452,452,1322,452,453,451,452,452,452,452,452,453,1322,451,454,453,453,453,452,452,452,452,453,453,452,453,1323,452,452,454,453,453,454,453,1323,453,1323};
NicolasV 0:15536ec3bf58 47 const unsigned vol_down[] = {453,1298,454,452,454,453,454,453,453,453,453,454,453,1324,454,453,454,454,452,454,453,454,454,1323,452,453,452,452,453,453,453,453,1322,454,452,453,452,1322,451,452,1323,454,452,453,452,1324,452,1323};
NicolasV 0:15536ec3bf58 48 char* msg;
NicolasV 0:15536ec3bf58 49
NicolasV 0:15536ec3bf58 50 int main() {
NicolasV 0:15536ec3bf58 51
NicolasV 0:15536ec3bf58 52 timer.start();
NicolasV 0:15536ec3bf58 53 lcd.cls();
NicolasV 0:15536ec3bf58 54
NicolasV 0:15536ec3bf58 55 while (true) {
NicolasV 0:15536ec3bf58 56
NicolasV 1:ed8910f358bc 57 int numero = aleatorio(0, 57) % 6; // Se escoge un número aleatorio para seleccionar la acción.
NicolasV 0:15536ec3bf58 58
NicolasV 0:15536ec3bf58 59 switch (numero) {
NicolasV 0:15536ec3bf58 60 case 0:
NicolasV 0:15536ec3bf58 61 for (int i = 0; i < n_bits; i++) {
NicolasV 0:15536ec3bf58 62 code[i] = ch_up[i];
NicolasV 0:15536ec3bf58 63 msg = "ch_up";
NicolasV 0:15536ec3bf58 64 }
NicolasV 0:15536ec3bf58 65 break;
NicolasV 0:15536ec3bf58 66 case 1:
NicolasV 0:15536ec3bf58 67 for (int i = 0; i < n_bits; i++) {
NicolasV 0:15536ec3bf58 68 code[i] = ch_down[i];
NicolasV 0:15536ec3bf58 69 msg = "ch_down";
NicolasV 0:15536ec3bf58 70 }
NicolasV 0:15536ec3bf58 71 break;
NicolasV 0:15536ec3bf58 72 case 2:
NicolasV 0:15536ec3bf58 73 for (int i = 0; i < n_bits; i++) {
NicolasV 0:15536ec3bf58 74 code[i] = mute[i];
NicolasV 0:15536ec3bf58 75 msg = "mute";
NicolasV 0:15536ec3bf58 76 }
NicolasV 0:15536ec3bf58 77 break;
NicolasV 0:15536ec3bf58 78 case 3:
NicolasV 0:15536ec3bf58 79 for (int i = 0; i < n_bits; i++) {
NicolasV 0:15536ec3bf58 80 code[i] = power[i];
NicolasV 0:15536ec3bf58 81 msg = "power";
NicolasV 0:15536ec3bf58 82 }
NicolasV 0:15536ec3bf58 83 break;
NicolasV 0:15536ec3bf58 84 case 4:
NicolasV 0:15536ec3bf58 85 for (int i = 0; i < n_bits; i++) {
NicolasV 0:15536ec3bf58 86 code[i] = vol_up[i];
NicolasV 0:15536ec3bf58 87 msg = "vol_up";
NicolasV 0:15536ec3bf58 88 }
NicolasV 0:15536ec3bf58 89 break;
NicolasV 0:15536ec3bf58 90 case 5:
NicolasV 0:15536ec3bf58 91 for (int i = 0; i < n_bits; i++) {
NicolasV 0:15536ec3bf58 92 code[i] = vol_down[i];
NicolasV 0:15536ec3bf58 93 msg = "vol_down";
NicolasV 0:15536ec3bf58 94 }
NicolasV 0:15536ec3bf58 95 break;
NicolasV 0:15536ec3bf58 96 }
NicolasV 0:15536ec3bf58 97
NicolasV 1:ed8910f358bc 98 int minutos = aleatorio(1, 100) % 10; // Un número aleatorio entre 0 y 9 minutos.
NicolasV 0:15536ec3bf58 99
NicolasV 1:ed8910f358bc 100 for (int m = minutos; m > 0; m--) { // Se muestra un contador de tiempo descendente que muestra la acción siguiente.
NicolasV 0:15536ec3bf58 101 for (int s = 59; s >= 0; s--) {
NicolasV 0:15536ec3bf58 102 indic = !indic;
NicolasV 0:15536ec3bf58 103 lcd.cls();
NicolasV 0:15536ec3bf58 104 lcd.locate(0,0);
NicolasV 1:ed8910f358bc 105 lcd.printf("%s en %2d:%02d", msg, m, s);
NicolasV 1:ed8910f358bc 106 wait(1);
NicolasV 0:15536ec3bf58 107 }
NicolasV 0:15536ec3bf58 108 }
NicolasV 0:15536ec3bf58 109
NicolasV 0:15536ec3bf58 110 enviar_codigo(n_bits, code);
NicolasV 0:15536ec3bf58 111
NicolasV 0:15536ec3bf58 112 }
NicolasV 0:15536ec3bf58 113 }
NicolasV 0:15536ec3bf58 114
NicolasV 1:ed8910f358bc 115 void enviar_uno(int duracion) { // Se conmuta rápidamente el led infrarrojo para enviar un 1.
NicolasV 0:15536ec3bf58 116
NicolasV 0:15536ec3bf58 117 Timer t;
NicolasV 0:15536ec3bf58 118 t.reset();
NicolasV 0:15536ec3bf58 119 t.start();
NicolasV 0:15536ec3bf58 120
NicolasV 0:15536ec3bf58 121 while (t.read_us() < duracion) {
NicolasV 0:15536ec3bf58 122 led = 1;
NicolasV 0:15536ec3bf58 123 wait_us(8);
NicolasV 0:15536ec3bf58 124 led = 0;
NicolasV 0:15536ec3bf58 125 wait_us(8);
NicolasV 0:15536ec3bf58 126 }
NicolasV 0:15536ec3bf58 127 }
NicolasV 0:15536ec3bf58 128
NicolasV 1:ed8910f358bc 129 void descanso(int duracion) { // Se espera con el led infrarrojo apagado.
NicolasV 0:15536ec3bf58 130 wait_us(duracion);
NicolasV 0:15536ec3bf58 131 }
NicolasV 0:15536ec3bf58 132
NicolasV 0:15536ec3bf58 133 void enviar_codigo(int n_bits, int *code) {
NicolasV 0:15536ec3bf58 134
NicolasV 0:15536ec3bf58 135 led = 0;
NicolasV 0:15536ec3bf58 136 wait_ms(100);
NicolasV 0:15536ec3bf58 137 enviar_uno(header_L);
NicolasV 0:15536ec3bf58 138 descanso(header_H);
NicolasV 0:15536ec3bf58 139
NicolasV 0:15536ec3bf58 140 for (int i = 0; i < n_bits; ++i) {
NicolasV 0:15536ec3bf58 141 enviar_uno(400);
NicolasV 0:15536ec3bf58 142 descanso(code[i]);
NicolasV 0:15536ec3bf58 143 }
NicolasV 0:15536ec3bf58 144 enviar_uno(420);
NicolasV 0:15536ec3bf58 145 }
NicolasV 0:15536ec3bf58 146
NicolasV 0:15536ec3bf58 147 int aleatorio(int a, int b) {
NicolasV 0:15536ec3bf58 148 return rint((b - a) * abs(cos((double)timer.read_us())) + a);
NicolasV 0:15536ec3bf58 149 }