Facundo Sussini
/
TP1_ejer2
Pio IX 6ºTecnica - Integrantes: Facundo Carmona, Facundo Sussini - Simon
main.cpp@0:3a971b81979a, 2019-06-04 (annotated)
- Committer:
- Susso
- Date:
- Tue Jun 04 12:10:47 2019 +0000
- Revision:
- 0:3a971b81979a
sadv;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Susso | 0:3a971b81979a | 1 | #include "mbed.h" |
Susso | 0:3a971b81979a | 2 | #include <stdio.h> |
Susso | 0:3a971b81979a | 3 | #include <stdlib.h> |
Susso | 0:3a971b81979a | 4 | |
Susso | 0:3a971b81979a | 5 | /* |
Susso | 0:3a971b81979a | 6 | * Si se toca el slider (cerca de la zona izquierda) |
Susso | 0:3a971b81979a | 7 | * enciende / apaga el led rojo |
Susso | 0:3a971b81979a | 8 | * |
Susso | 0:3a971b81979a | 9 | * Para FRDM-KL25z |
Susso | 0:3a971b81979a | 10 | */ |
Susso | 0:3a971b81979a | 11 | |
Susso | 0:3a971b81979a | 12 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
Susso | 0:3a971b81979a | 13 | #define ELEC0 9 |
Susso | 0:3a971b81979a | 14 | #define ELEC1 10 |
Susso | 0:3a971b81979a | 15 | #elif defined (TARGET_KL05Z) |
Susso | 0:3a971b81979a | 16 | #define ELEC0 9 |
Susso | 0:3a971b81979a | 17 | #define ELEC1 8 |
Susso | 0:3a971b81979a | 18 | #else |
Susso | 0:3a971b81979a | 19 | #error TARGET NOT DEFINED |
Susso | 0:3a971b81979a | 20 | #endif |
Susso | 0:3a971b81979a | 21 | /* Defino los LEDS RGB */ |
Susso | 0:3a971b81979a | 22 | DigitalOut rojo(LED_RED); |
Susso | 0:3a971b81979a | 23 | DigitalOut verde(LED_GREEN); |
Susso | 0:3a971b81979a | 24 | DigitalOut azul(LED_BLUE); |
Susso | 0:3a971b81979a | 25 | |
Susso | 0:3a971b81979a | 26 | /* Defino el pulsador de inicio y reseteo */ |
Susso | 0:3a971b81979a | 27 | void contador1(); |
Susso | 0:3a971b81979a | 28 | void pulsadorsito1(); |
Susso | 0:3a971b81979a | 29 | char salida1=0,cuenta1=0, PIN1=0; |
Susso | 0:3a971b81979a | 30 | Ticker ti1; |
Susso | 0:3a971b81979a | 31 | DigitalIn pin1(A0,PullUp); |
Susso | 0:3a971b81979a | 32 | |
Susso | 0:3a971b81979a | 33 | /* Defino el pulsador del color verde */ |
Susso | 0:3a971b81979a | 34 | void contador2(); |
Susso | 0:3a971b81979a | 35 | void pulsadorsito2(); |
Susso | 0:3a971b81979a | 36 | char salida2=0,cuenta2=0, PIN2=0; |
Susso | 0:3a971b81979a | 37 | Ticker ti2; |
Susso | 0:3a971b81979a | 38 | DigitalIn pin2(A1,PullUp); |
Susso | 0:3a971b81979a | 39 | |
Susso | 0:3a971b81979a | 40 | |
Susso | 0:3a971b81979a | 41 | /* Defino el pulsador del color rojo */ |
Susso | 0:3a971b81979a | 42 | void contador3(); |
Susso | 0:3a971b81979a | 43 | void pulsadorsito3(); |
Susso | 0:3a971b81979a | 44 | char salida3=0,cuenta3=0, PIN3=0; |
Susso | 0:3a971b81979a | 45 | Ticker ti3; |
Susso | 0:3a971b81979a | 46 | DigitalIn pin3(A2,PullUp); |
Susso | 0:3a971b81979a | 47 | |
Susso | 0:3a971b81979a | 48 | /* Defino el pulsador del color azul */ |
Susso | 0:3a971b81979a | 49 | void contador4(); |
Susso | 0:3a971b81979a | 50 | void pulsadorsito4(); |
Susso | 0:3a971b81979a | 51 | char salida4=0,cuenta4=0, PIN4=0; |
Susso | 0:3a971b81979a | 52 | Ticker ti4; |
Susso | 0:3a971b81979a | 53 | DigitalIn pin4(A3,PullUp); |
Susso | 0:3a971b81979a | 54 | |
Susso | 0:3a971b81979a | 55 | |
Susso | 0:3a971b81979a | 56 | /* Defino las variables del "simon" y el ticker correspondiente */ |
Susso | 0:3a971b81979a | 57 | Ticker ti; |
Susso | 0:3a971b81979a | 58 | void contador(); |
Susso | 0:3a971b81979a | 59 | void simone(); |
Susso | 0:3a971b81979a | 60 | char cuenta=0,estado=0, rondom=0,randomi[25],rendam=0,i=0, reseteo=0, muestrita=0, secuencita=0,secuence=1, secuenco=0, seleccione=0, verificate=0, validacion=0,a=0,bloqueo=0,x=0,randomizate=0,veric=0, bloqueo1=0, bloqueo2=0, bloqueo3=0; |
Susso | 0:3a971b81979a | 61 | |
Susso | 0:3a971b81979a | 62 | /* ticker random */ |
Susso | 0:3a971b81979a | 63 | Ticker ran; |
Susso | 0:3a971b81979a | 64 | int ramd=0; |
Susso | 0:3a971b81979a | 65 | void randoma(); |
Susso | 0:3a971b81979a | 66 | |
Susso | 0:3a971b81979a | 67 | #define inicio 0 |
Susso | 0:3a971b81979a | 68 | #define random 1 |
Susso | 0:3a971b81979a | 69 | #define muestra 2 |
Susso | 0:3a971b81979a | 70 | #define secuencia 3 |
Susso | 0:3a971b81979a | 71 | #define seleccion 4 |
Susso | 0:3a971b81979a | 72 | #define verificacion 5 |
Susso | 0:3a971b81979a | 73 | |
Susso | 0:3a971b81979a | 74 | #define rojito 0 |
Susso | 0:3a971b81979a | 75 | #define azulcito 1 |
Susso | 0:3a971b81979a | 76 | #define verdecito 2 |
Susso | 0:3a971b81979a | 77 | |
Susso | 0:3a971b81979a | 78 | #define verdale 0 |
Susso | 0:3a971b81979a | 79 | #define rojale 1 |
Susso | 0:3a971b81979a | 80 | #define azulale 2 |
Susso | 0:3a971b81979a | 81 | #define reseteale 3 |
Susso | 0:3a971b81979a | 82 | |
Susso | 0:3a971b81979a | 83 | int main() |
Susso | 0:3a971b81979a | 84 | { |
Susso | 0:3a971b81979a | 85 | /* inicializo los numeros random */ |
Susso | 0:3a971b81979a | 86 | srand(ramd); |
Susso | 0:3a971b81979a | 87 | ran.attach(&randoma,0.0001); |
Susso | 0:3a971b81979a | 88 | |
Susso | 0:3a971b81979a | 89 | /* seteo en off para los leds */ |
Susso | 0:3a971b81979a | 90 | rojo=1; |
Susso | 0:3a971b81979a | 91 | verde=1; |
Susso | 0:3a971b81979a | 92 | azul=1; |
Susso | 0:3a971b81979a | 93 | |
Susso | 0:3a971b81979a | 94 | /* defino los tickers */ |
Susso | 0:3a971b81979a | 95 | ti.attach(&contador, 0.01); |
Susso | 0:3a971b81979a | 96 | ti1.attach(&contador1, 0.001); |
Susso | 0:3a971b81979a | 97 | ti2.attach(&contador2, 0.001); |
Susso | 0:3a971b81979a | 98 | ti3.attach(&contador3, 0.001); |
Susso | 0:3a971b81979a | 99 | ti4.attach(&contador4, 0.001); |
Susso | 0:3a971b81979a | 100 | |
Susso | 0:3a971b81979a | 101 | /* inicializo los numeros random */ |
Susso | 0:3a971b81979a | 102 | srand (time(NULL)); |
Susso | 0:3a971b81979a | 103 | while(1) { |
Susso | 0:3a971b81979a | 104 | |
Susso | 0:3a971b81979a | 105 | /* llamo a las funciones */ |
Susso | 0:3a971b81979a | 106 | pulsadorsito1(); |
Susso | 0:3a971b81979a | 107 | pulsadorsito2(); |
Susso | 0:3a971b81979a | 108 | pulsadorsito3(); |
Susso | 0:3a971b81979a | 109 | pulsadorsito4(); |
Susso | 0:3a971b81979a | 110 | simone(); |
Susso | 0:3a971b81979a | 111 | } |
Susso | 0:3a971b81979a | 112 | } |
Susso | 0:3a971b81979a | 113 | //---------funcion del juego simon---------------------------------------------- |
Susso | 0:3a971b81979a | 114 | void simone() |
Susso | 0:3a971b81979a | 115 | { |
Susso | 0:3a971b81979a | 116 | /* maquina de estados */ |
Susso | 0:3a971b81979a | 117 | switch(estado) { |
Susso | 0:3a971b81979a | 118 | /* indico cuando toco el pulsador inicio el del juego y reseteo todas las variables */ |
Susso | 0:3a971b81979a | 119 | case inicio: |
Susso | 0:3a971b81979a | 120 | if(salida1==1 && reseteo==0) { |
Susso | 0:3a971b81979a | 121 | reseteo=1; |
Susso | 0:3a971b81979a | 122 | estado=random; |
Susso | 0:3a971b81979a | 123 | printf("inicio \r\n "); |
Susso | 0:3a971b81979a | 124 | i=0; |
Susso | 0:3a971b81979a | 125 | secuence=1; |
Susso | 0:3a971b81979a | 126 | rojo=1; |
Susso | 0:3a971b81979a | 127 | verde=1; |
Susso | 0:3a971b81979a | 128 | azul=1; |
Susso | 0:3a971b81979a | 129 | } |
Susso | 0:3a971b81979a | 130 | break; |
Susso | 0:3a971b81979a | 131 | |
Susso | 0:3a971b81979a | 132 | /* incio la secuencia random y la guardo en un vector */ |
Susso | 0:3a971b81979a | 133 | case random: |
Susso | 0:3a971b81979a | 134 | if(cuenta==0) { |
Susso | 0:3a971b81979a | 135 | rendam=rand()%3; |
Susso | 0:3a971b81979a | 136 | if(i<24) { |
Susso | 0:3a971b81979a | 137 | if(rendam==rojito) { |
Susso | 0:3a971b81979a | 138 | randomi[i]=rojito; |
Susso | 0:3a971b81979a | 139 | i++; |
Susso | 0:3a971b81979a | 140 | } else if(rendam==azulcito) { |
Susso | 0:3a971b81979a | 141 | randomi[i]=azulcito; |
Susso | 0:3a971b81979a | 142 | i++; |
Susso | 0:3a971b81979a | 143 | } else if(rendam==verdecito) { |
Susso | 0:3a971b81979a | 144 | randomi[i]=verdecito; |
Susso | 0:3a971b81979a | 145 | i++; |
Susso | 0:3a971b81979a | 146 | } |
Susso | 0:3a971b81979a | 147 | } else { |
Susso | 0:3a971b81979a | 148 | /* cuando se termina de establecer la secuencia random*/ |
Susso | 0:3a971b81979a | 149 | estado=secuencia; |
Susso | 0:3a971b81979a | 150 | i=0; |
Susso | 0:3a971b81979a | 151 | cuenta=100; |
Susso | 0:3a971b81979a | 152 | printf("secuencia \r\n"); |
Susso | 0:3a971b81979a | 153 | } |
Susso | 0:3a971b81979a | 154 | } |
Susso | 0:3a971b81979a | 155 | break; |
Susso | 0:3a971b81979a | 156 | |
Susso | 0:3a971b81979a | 157 | /* cuando es necesario mostrar la secuencia a seleccionar */ |
Susso | 0:3a971b81979a | 158 | case muestra: |
Susso | 0:3a971b81979a | 159 | /* cuando se termina de mostrar lo seleccionado */ |
Susso | 0:3a971b81979a | 160 | if(secuencita==1 && cuenta==0) { |
Susso | 0:3a971b81979a | 161 | rojo=1; |
Susso | 0:3a971b81979a | 162 | verde=1; |
Susso | 0:3a971b81979a | 163 | azul=1; |
Susso | 0:3a971b81979a | 164 | estado=secuencia; |
Susso | 0:3a971b81979a | 165 | secuencita=0; |
Susso | 0:3a971b81979a | 166 | rondom=0; |
Susso | 0:3a971b81979a | 167 | cuenta=50; |
Susso | 0:3a971b81979a | 168 | } else if(cuenta) { |
Susso | 0:3a971b81979a | 169 | /* mientras que el tiempo sea indistinto a 0 */ |
Susso | 0:3a971b81979a | 170 | if(secuencita==1) |
Susso | 0:3a971b81979a | 171 | muestrita = secuenco; |
Susso | 0:3a971b81979a | 172 | /* enciendo el led correspondiente */ |
Susso | 0:3a971b81979a | 173 | switch(muestrita) { |
Susso | 0:3a971b81979a | 174 | case rojito: { |
Susso | 0:3a971b81979a | 175 | rojo=0; |
Susso | 0:3a971b81979a | 176 | verde=1; |
Susso | 0:3a971b81979a | 177 | azul=1; |
Susso | 0:3a971b81979a | 178 | break; |
Susso | 0:3a971b81979a | 179 | } |
Susso | 0:3a971b81979a | 180 | case verdecito: { |
Susso | 0:3a971b81979a | 181 | rojo=1; |
Susso | 0:3a971b81979a | 182 | verde=0; |
Susso | 0:3a971b81979a | 183 | azul=1; |
Susso | 0:3a971b81979a | 184 | break; |
Susso | 0:3a971b81979a | 185 | } |
Susso | 0:3a971b81979a | 186 | case azulcito: { |
Susso | 0:3a971b81979a | 187 | rojo=1; |
Susso | 0:3a971b81979a | 188 | verde=1; |
Susso | 0:3a971b81979a | 189 | azul=0; |
Susso | 0:3a971b81979a | 190 | break; |
Susso | 0:3a971b81979a | 191 | } |
Susso | 0:3a971b81979a | 192 | } |
Susso | 0:3a971b81979a | 193 | } |
Susso | 0:3a971b81979a | 194 | /* en el caso que desee resetear el programa en el medio de la muestra */ |
Susso | 0:3a971b81979a | 195 | if(salida1==1 && reseteo==1) { |
Susso | 0:3a971b81979a | 196 | reseteo=0; |
Susso | 0:3a971b81979a | 197 | estado=inicio; |
Susso | 0:3a971b81979a | 198 | rojo=1; |
Susso | 0:3a971b81979a | 199 | verde=1; |
Susso | 0:3a971b81979a | 200 | azul=1; |
Susso | 0:3a971b81979a | 201 | } |
Susso | 0:3a971b81979a | 202 | break; |
Susso | 0:3a971b81979a | 203 | |
Susso | 0:3a971b81979a | 204 | /* defino mi secuencia a seguir y luego la muestro, esta aumenta por cada vez que gano */ |
Susso | 0:3a971b81979a | 205 | case secuencia: |
Susso | 0:3a971b81979a | 206 | if(cuenta==0) { |
Susso | 0:3a971b81979a | 207 | if(i<secuence) { |
Susso | 0:3a971b81979a | 208 | secuenco=randomi[i]; |
Susso | 0:3a971b81979a | 209 | estado=muestra; |
Susso | 0:3a971b81979a | 210 | secuencita=1; |
Susso | 0:3a971b81979a | 211 | i++; |
Susso | 0:3a971b81979a | 212 | cuenta=100; |
Susso | 0:3a971b81979a | 213 | } else if(i==secuence) { |
Susso | 0:3a971b81979a | 214 | /* cuando termino de mostrar empiezo a seleccionar */ |
Susso | 0:3a971b81979a | 215 | estado=seleccion; |
Susso | 0:3a971b81979a | 216 | printf("Elija con prudencia \r\n"); |
Susso | 0:3a971b81979a | 217 | } |
Susso | 0:3a971b81979a | 218 | } |
Susso | 0:3a971b81979a | 219 | |
Susso | 0:3a971b81979a | 220 | |
Susso | 0:3a971b81979a | 221 | break; |
Susso | 0:3a971b81979a | 222 | |
Susso | 0:3a971b81979a | 223 | /* dependiendo del pulsador que toque voy a mostrar encendido un led */ |
Susso | 0:3a971b81979a | 224 | case seleccion: |
Susso | 0:3a971b81979a | 225 | switch(a) { |
Susso | 0:3a971b81979a | 226 | case verdale: |
Susso | 0:3a971b81979a | 227 | if(salida2 == 1 && bloqueo1==0) { |
Susso | 0:3a971b81979a | 228 | /* cuando presiono enciendo el led correspondiente--- esto se repite con los demas pulsadores */ |
Susso | 0:3a971b81979a | 229 | verde =0; |
Susso | 0:3a971b81979a | 230 | printf("apretaste verde \r\n"); |
Susso | 0:3a971b81979a | 231 | bloqueo1=1; |
Susso | 0:3a971b81979a | 232 | } else if(salida2==0 && bloqueo1==1) { |
Susso | 0:3a971b81979a | 233 | /* cuando suelto el pulsador envio la informacion del color que elegir--- esto se repite con los demas pulsadores */ |
Susso | 0:3a971b81979a | 234 | veric= verdecito; |
Susso | 0:3a971b81979a | 235 | estado=verificacion; |
Susso | 0:3a971b81979a | 236 | bloqueo1=0; |
Susso | 0:3a971b81979a | 237 | verde=1; |
Susso | 0:3a971b81979a | 238 | } |
Susso | 0:3a971b81979a | 239 | a++; |
Susso | 0:3a971b81979a | 240 | break; |
Susso | 0:3a971b81979a | 241 | |
Susso | 0:3a971b81979a | 242 | case rojale: |
Susso | 0:3a971b81979a | 243 | if(salida3 == 1 && bloqueo2==0) { |
Susso | 0:3a971b81979a | 244 | rojo =0; |
Susso | 0:3a971b81979a | 245 | printf("apretaste rojo \r\n"); |
Susso | 0:3a971b81979a | 246 | bloqueo2=1; |
Susso | 0:3a971b81979a | 247 | } else if(salida3==0 && bloqueo2==1) { |
Susso | 0:3a971b81979a | 248 | |
Susso | 0:3a971b81979a | 249 | veric= rojito; |
Susso | 0:3a971b81979a | 250 | estado=verificacion; |
Susso | 0:3a971b81979a | 251 | bloqueo2=0; |
Susso | 0:3a971b81979a | 252 | rojo=1; |
Susso | 0:3a971b81979a | 253 | } |
Susso | 0:3a971b81979a | 254 | a++; |
Susso | 0:3a971b81979a | 255 | break; |
Susso | 0:3a971b81979a | 256 | |
Susso | 0:3a971b81979a | 257 | case azulale: |
Susso | 0:3a971b81979a | 258 | if(salida4 == 1 && bloqueo3==0) { |
Susso | 0:3a971b81979a | 259 | azul =0; |
Susso | 0:3a971b81979a | 260 | printf("apretaste azul \r\n"); |
Susso | 0:3a971b81979a | 261 | bloqueo3=1; |
Susso | 0:3a971b81979a | 262 | } else if(salida4==0 && bloqueo3==1) { |
Susso | 0:3a971b81979a | 263 | |
Susso | 0:3a971b81979a | 264 | veric= azulcito; |
Susso | 0:3a971b81979a | 265 | estado=verificacion; |
Susso | 0:3a971b81979a | 266 | bloqueo3=0; |
Susso | 0:3a971b81979a | 267 | azul=1; |
Susso | 0:3a971b81979a | 268 | } |
Susso | 0:3a971b81979a | 269 | a++; |
Susso | 0:3a971b81979a | 270 | break; |
Susso | 0:3a971b81979a | 271 | |
Susso | 0:3a971b81979a | 272 | case reseteale: |
Susso | 0:3a971b81979a | 273 | if(salida1==1 && reseteo==1) { |
Susso | 0:3a971b81979a | 274 | /* en el caso que desee resetear el programa en el medio de la seleccion */ |
Susso | 0:3a971b81979a | 275 | reseteo=0; |
Susso | 0:3a971b81979a | 276 | estado=inicio; |
Susso | 0:3a971b81979a | 277 | rojo=1; |
Susso | 0:3a971b81979a | 278 | verde=1; |
Susso | 0:3a971b81979a | 279 | azul=1; |
Susso | 0:3a971b81979a | 280 | } |
Susso | 0:3a971b81979a | 281 | a=0; |
Susso | 0:3a971b81979a | 282 | break; |
Susso | 0:3a971b81979a | 283 | } |
Susso | 0:3a971b81979a | 284 | break; |
Susso | 0:3a971b81979a | 285 | |
Susso | 0:3a971b81979a | 286 | /* se verifica lo que elegi */ |
Susso | 0:3a971b81979a | 287 | case verificacion: |
Susso | 0:3a971b81979a | 288 | randomizate=randomi[x]; |
Susso | 0:3a971b81979a | 289 | /* si le acerte al color */ |
Susso | 0:3a971b81979a | 290 | if(randomizate == veric) { |
Susso | 0:3a971b81979a | 291 | estado=seleccion; |
Susso | 0:3a971b81979a | 292 | x++; |
Susso | 0:3a971b81979a | 293 | } else { |
Susso | 0:3a971b81979a | 294 | /* si le acierto al color */ |
Susso | 0:3a971b81979a | 295 | x=0; |
Susso | 0:3a971b81979a | 296 | estado=inicio; |
Susso | 0:3a971b81979a | 297 | reseteo=0; |
Susso | 0:3a971b81979a | 298 | rojo=0; |
Susso | 0:3a971b81979a | 299 | verde=1; |
Susso | 0:3a971b81979a | 300 | azul=1; |
Susso | 0:3a971b81979a | 301 | secuence=1; |
Susso | 0:3a971b81979a | 302 | |
Susso | 0:3a971b81979a | 303 | } |
Susso | 0:3a971b81979a | 304 | /* cuando acierto la secuencia entera */ |
Susso | 0:3a971b81979a | 305 | if(x==secuence) { |
Susso | 0:3a971b81979a | 306 | /* si aun me falta para ganar */ |
Susso | 0:3a971b81979a | 307 | if(secuence<24) { |
Susso | 0:3a971b81979a | 308 | estado=secuencia; |
Susso | 0:3a971b81979a | 309 | secuence++; |
Susso | 0:3a971b81979a | 310 | x=0; |
Susso | 0:3a971b81979a | 311 | i=0; |
Susso | 0:3a971b81979a | 312 | rojo=1; |
Susso | 0:3a971b81979a | 313 | verde=1; |
Susso | 0:3a971b81979a | 314 | azul=1; |
Susso | 0:3a971b81979a | 315 | } else if(secuence==24) { |
Susso | 0:3a971b81979a | 316 | /* si gano al elegir correctamente todas las secuencias */ |
Susso | 0:3a971b81979a | 317 | estado=inicio; |
Susso | 0:3a971b81979a | 318 | x=0; |
Susso | 0:3a971b81979a | 319 | rojo=1; |
Susso | 0:3a971b81979a | 320 | verde=0; |
Susso | 0:3a971b81979a | 321 | azul=1; |
Susso | 0:3a971b81979a | 322 | reseteo=0; |
Susso | 0:3a971b81979a | 323 | } |
Susso | 0:3a971b81979a | 324 | |
Susso | 0:3a971b81979a | 325 | } |
Susso | 0:3a971b81979a | 326 | break; |
Susso | 0:3a971b81979a | 327 | } |
Susso | 0:3a971b81979a | 328 | } |
Susso | 0:3a971b81979a | 329 | /* contador */ |
Susso | 0:3a971b81979a | 330 | void contador() |
Susso | 0:3a971b81979a | 331 | { |
Susso | 0:3a971b81979a | 332 | if(cuenta) |
Susso | 0:3a971b81979a | 333 | cuenta--; |
Susso | 0:3a971b81979a | 334 | } |
Susso | 0:3a971b81979a | 335 | |
Susso | 0:3a971b81979a | 336 | /* funcion ticker random */ |
Susso | 0:3a971b81979a | 337 | void randoma() |
Susso | 0:3a971b81979a | 338 | { |
Susso | 0:3a971b81979a | 339 | ramd++; |
Susso | 0:3a971b81979a | 340 | srand(ramd); |
Susso | 0:3a971b81979a | 341 | } |
Susso | 0:3a971b81979a | 342 | |
Susso | 0:3a971b81979a | 343 | //----------------funcion de los 4 pulsadores----------------------------------------- |
Susso | 0:3a971b81979a | 344 | void pulsadorsito1() |
Susso | 0:3a971b81979a | 345 | { |
Susso | 0:3a971b81979a | 346 | switch(PIN1) { |
Susso | 0:3a971b81979a | 347 | default: |
Susso | 0:3a971b81979a | 348 | case 0: |
Susso | 0:3a971b81979a | 349 | if(pin1==1) { |
Susso | 0:3a971b81979a | 350 | salida1=0; |
Susso | 0:3a971b81979a | 351 | cuenta1=0; |
Susso | 0:3a971b81979a | 352 | } else if(pin1==0) { |
Susso | 0:3a971b81979a | 353 | PIN1=1; |
Susso | 0:3a971b81979a | 354 | cuenta1=25; |
Susso | 0:3a971b81979a | 355 | } |
Susso | 0:3a971b81979a | 356 | break; |
Susso | 0:3a971b81979a | 357 | |
Susso | 0:3a971b81979a | 358 | case 1: |
Susso | 0:3a971b81979a | 359 | if(cuenta1==0 && pin1==1) { |
Susso | 0:3a971b81979a | 360 | salida1=1; |
Susso | 0:3a971b81979a | 361 | PIN1=0; |
Susso | 0:3a971b81979a | 362 | } else if( pin1==1 && cuenta1>0) { |
Susso | 0:3a971b81979a | 363 | PIN1=0; |
Susso | 0:3a971b81979a | 364 | } |
Susso | 0:3a971b81979a | 365 | break; |
Susso | 0:3a971b81979a | 366 | } |
Susso | 0:3a971b81979a | 367 | } |
Susso | 0:3a971b81979a | 368 | |
Susso | 0:3a971b81979a | 369 | void contador1() |
Susso | 0:3a971b81979a | 370 | { |
Susso | 0:3a971b81979a | 371 | if(cuenta1) |
Susso | 0:3a971b81979a | 372 | cuenta1--; |
Susso | 0:3a971b81979a | 373 | } |
Susso | 0:3a971b81979a | 374 | |
Susso | 0:3a971b81979a | 375 | //------------------------------------------------------------------------------ |
Susso | 0:3a971b81979a | 376 | void pulsadorsito2() |
Susso | 0:3a971b81979a | 377 | { |
Susso | 0:3a971b81979a | 378 | switch(PIN2) { |
Susso | 0:3a971b81979a | 379 | default: |
Susso | 0:3a971b81979a | 380 | case 0: |
Susso | 0:3a971b81979a | 381 | if(pin2==1) { |
Susso | 0:3a971b81979a | 382 | salida2=0; |
Susso | 0:3a971b81979a | 383 | cuenta2=0; |
Susso | 0:3a971b81979a | 384 | } else if(pin2==0) { |
Susso | 0:3a971b81979a | 385 | PIN2=1; |
Susso | 0:3a971b81979a | 386 | cuenta2=25; |
Susso | 0:3a971b81979a | 387 | } |
Susso | 0:3a971b81979a | 388 | break; |
Susso | 0:3a971b81979a | 389 | |
Susso | 0:3a971b81979a | 390 | case 1: |
Susso | 0:3a971b81979a | 391 | if(cuenta2==0 && pin2==0) |
Susso | 0:3a971b81979a | 392 | salida2=1; |
Susso | 0:3a971b81979a | 393 | else if(cuenta2==0 && pin2==1) |
Susso | 0:3a971b81979a | 394 | PIN2=0; |
Susso | 0:3a971b81979a | 395 | else if( pin2==1 && cuenta2>0) |
Susso | 0:3a971b81979a | 396 | PIN2=0; |
Susso | 0:3a971b81979a | 397 | break; |
Susso | 0:3a971b81979a | 398 | } |
Susso | 0:3a971b81979a | 399 | } |
Susso | 0:3a971b81979a | 400 | |
Susso | 0:3a971b81979a | 401 | void contador2() |
Susso | 0:3a971b81979a | 402 | { |
Susso | 0:3a971b81979a | 403 | if(cuenta2) |
Susso | 0:3a971b81979a | 404 | cuenta2--; |
Susso | 0:3a971b81979a | 405 | } |
Susso | 0:3a971b81979a | 406 | |
Susso | 0:3a971b81979a | 407 | //------------------------------------------------------------------------------ |
Susso | 0:3a971b81979a | 408 | void pulsadorsito3() |
Susso | 0:3a971b81979a | 409 | { |
Susso | 0:3a971b81979a | 410 | switch(PIN3) { |
Susso | 0:3a971b81979a | 411 | default: |
Susso | 0:3a971b81979a | 412 | case 0: |
Susso | 0:3a971b81979a | 413 | if(pin3==1) { |
Susso | 0:3a971b81979a | 414 | salida3=0; |
Susso | 0:3a971b81979a | 415 | cuenta3=0; |
Susso | 0:3a971b81979a | 416 | } else if(pin3==0) { |
Susso | 0:3a971b81979a | 417 | PIN3=1; |
Susso | 0:3a971b81979a | 418 | cuenta3=25; |
Susso | 0:3a971b81979a | 419 | } |
Susso | 0:3a971b81979a | 420 | break; |
Susso | 0:3a971b81979a | 421 | |
Susso | 0:3a971b81979a | 422 | case 1: |
Susso | 0:3a971b81979a | 423 | if(cuenta3==0 && pin3==0) |
Susso | 0:3a971b81979a | 424 | salida3=1; |
Susso | 0:3a971b81979a | 425 | else if(cuenta3==0 && pin3==1) |
Susso | 0:3a971b81979a | 426 | PIN3=0; |
Susso | 0:3a971b81979a | 427 | else if( pin3==1 && cuenta3>0) |
Susso | 0:3a971b81979a | 428 | PIN3=0; |
Susso | 0:3a971b81979a | 429 | break; |
Susso | 0:3a971b81979a | 430 | } |
Susso | 0:3a971b81979a | 431 | } |
Susso | 0:3a971b81979a | 432 | |
Susso | 0:3a971b81979a | 433 | void contador3() |
Susso | 0:3a971b81979a | 434 | { |
Susso | 0:3a971b81979a | 435 | if(cuenta3) |
Susso | 0:3a971b81979a | 436 | cuenta3--; |
Susso | 0:3a971b81979a | 437 | } |
Susso | 0:3a971b81979a | 438 | |
Susso | 0:3a971b81979a | 439 | //------------------------------------------------------------------------------ |
Susso | 0:3a971b81979a | 440 | void pulsadorsito4() |
Susso | 0:3a971b81979a | 441 | { |
Susso | 0:3a971b81979a | 442 | switch(PIN4) { |
Susso | 0:3a971b81979a | 443 | default: |
Susso | 0:3a971b81979a | 444 | case 0: |
Susso | 0:3a971b81979a | 445 | if(pin4==1) { |
Susso | 0:3a971b81979a | 446 | salida4=0; |
Susso | 0:3a971b81979a | 447 | cuenta4=0; |
Susso | 0:3a971b81979a | 448 | } else if(pin4==0) { |
Susso | 0:3a971b81979a | 449 | PIN4=1; |
Susso | 0:3a971b81979a | 450 | cuenta4=25; |
Susso | 0:3a971b81979a | 451 | } |
Susso | 0:3a971b81979a | 452 | break; |
Susso | 0:3a971b81979a | 453 | |
Susso | 0:3a971b81979a | 454 | case 1: |
Susso | 0:3a971b81979a | 455 | if(cuenta4==0 && pin4==0) |
Susso | 0:3a971b81979a | 456 | salida4=1; |
Susso | 0:3a971b81979a | 457 | else if(cuenta4==0 && pin4==1) |
Susso | 0:3a971b81979a | 458 | PIN4=0; |
Susso | 0:3a971b81979a | 459 | else if( pin4==1 && cuenta4>0) |
Susso | 0:3a971b81979a | 460 | PIN4=0; |
Susso | 0:3a971b81979a | 461 | break; |
Susso | 0:3a971b81979a | 462 | } |
Susso | 0:3a971b81979a | 463 | } |
Susso | 0:3a971b81979a | 464 | |
Susso | 0:3a971b81979a | 465 | void contador4() |
Susso | 0:3a971b81979a | 466 | { |
Susso | 0:3a971b81979a | 467 | if(cuenta4) |
Susso | 0:3a971b81979a | 468 | cuenta4--; |
Susso | 0:3a971b81979a | 469 | } |