Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /** Control Loco. 00002 00003 Por: Laura Ávila 00004 Daniela López 00005 Nicolás Villegas 00006 00007 Este programa interfiere de forma loca la operación de un televisor. 00008 Emite códigos de t.v. con el fin de fastidiar al televidente. 00009 00010 El control utilizado es de marca Panasonic. Se encontró que los códigos IRDA para 00011 esta referencia tienen una longitud de 48 bits. Se modificó el programa "Capturas IRDA" 00012 para ajustarse a esta característica y con base en eso se obtuvieron los códigos. 00013 00014 La emisión es aleatoria para 00015 1 Mute 00016 2 On/Off 00017 3 Vol+ 00018 4 Vol- 00019 5 Ch+ 00020 6 Ch- 00021 */ 00022 00023 #include "mbed.h" 00024 #include <Timer.h> 00025 #include <math.h> 00026 #include "TextLCD.h" 00027 00028 Timer timer; 00029 DigitalOut led(PTE31); 00030 DigitalOut indic(LED2); 00031 TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 00032 00033 int code[50]; 00034 int aleatorio(int a, int b); 00035 void enviar_uno(int duracion); 00036 void enviar_codigo(int n_bits, int *code); 00037 00038 const int n_bits = 48; 00039 const int header_L = 3440; 00040 const int header_H = 1737; 00041 00042 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}; 00043 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}; 00044 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}; 00045 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}; 00046 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}; 00047 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}; 00048 char* msg; 00049 00050 int main() { 00051 00052 timer.start(); 00053 lcd.cls(); 00054 00055 while (true) { 00056 00057 int numero = aleatorio(0, 57) % 6; // Se escoge un número aleatorio para seleccionar la acción. 00058 00059 switch (numero) { 00060 case 0: 00061 for (int i = 0; i < n_bits; i++) { 00062 code[i] = ch_up[i]; 00063 msg = "ch_up"; 00064 } 00065 break; 00066 case 1: 00067 for (int i = 0; i < n_bits; i++) { 00068 code[i] = ch_down[i]; 00069 msg = "ch_down"; 00070 } 00071 break; 00072 case 2: 00073 for (int i = 0; i < n_bits; i++) { 00074 code[i] = mute[i]; 00075 msg = "mute"; 00076 } 00077 break; 00078 case 3: 00079 for (int i = 0; i < n_bits; i++) { 00080 code[i] = power[i]; 00081 msg = "power"; 00082 } 00083 break; 00084 case 4: 00085 for (int i = 0; i < n_bits; i++) { 00086 code[i] = vol_up[i]; 00087 msg = "vol_up"; 00088 } 00089 break; 00090 case 5: 00091 for (int i = 0; i < n_bits; i++) { 00092 code[i] = vol_down[i]; 00093 msg = "vol_down"; 00094 } 00095 break; 00096 } 00097 00098 int minutos = aleatorio(1, 100) % 10; // Un número aleatorio entre 0 y 9 minutos. 00099 00100 for (int m = minutos; m > 0; m--) { // Se muestra un contador de tiempo descendente que muestra la acción siguiente. 00101 for (int s = 59; s >= 0; s--) { 00102 indic = !indic; 00103 lcd.cls(); 00104 lcd.locate(0,0); 00105 lcd.printf("%s en %2d:%02d", msg, m, s); 00106 wait(1); 00107 } 00108 } 00109 00110 enviar_codigo(n_bits, code); 00111 00112 } 00113 } 00114 00115 void enviar_uno(int duracion) { // Se conmuta rápidamente el led infrarrojo para enviar un 1. 00116 00117 Timer t; 00118 t.reset(); 00119 t.start(); 00120 00121 while (t.read_us() < duracion) { 00122 led = 1; 00123 wait_us(8); 00124 led = 0; 00125 wait_us(8); 00126 } 00127 } 00128 00129 void descanso(int duracion) { // Se espera con el led infrarrojo apagado. 00130 wait_us(duracion); 00131 } 00132 00133 void enviar_codigo(int n_bits, int *code) { 00134 00135 led = 0; 00136 wait_ms(100); 00137 enviar_uno(header_L); 00138 descanso(header_H); 00139 00140 for (int i = 0; i < n_bits; ++i) { 00141 enviar_uno(400); 00142 descanso(code[i]); 00143 } 00144 enviar_uno(420); 00145 } 00146 00147 int aleatorio(int a, int b) { 00148 return rint((b - a) * abs(cos((double)timer.read_us())) + a); 00149 }
Generated on Sat Jul 23 2022 03:13:03 by
1.7.2