Trujillo Fernandez Yosef

Dependencies:   mbed Servo

Committer:
Yoscat
Date:
Sun Jun 02 03:20:19 2019 +0000
Revision:
0:559e39b80702
Truijillo Fernandez yosef;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yoscat 0:559e39b80702 1 /* ###########################################################################
Yoscat 0:559e39b80702 2 ** Archivo : proyecto.c
Yoscat 0:559e39b80702 3 ** Proyecto : FRDM-KL46Z_Plantilla
Yoscat 0:559e39b80702 4 ** Procesador : MKL46Z256VLL4
Yoscat 0:559e39b80702 5 ** Herramienta : Mbed
Yoscat 0:559e39b80702 6 ** Version : Driver 01.01
Yoscat 0:559e39b80702 7 ** Compilador : GNU C Compiler
Yoscat 0:559e39b80702 8 ** Fecha : 31-05-19
Yoscat 0:559e39b80702 9 ** Descripción :
Yoscat 0:559e39b80702 10 ** Este proyecto hace...
Yoscat 0:559e39b80702 11 ** Al ingresar el codigo correcto abre la activa el motor abriendo la puerta
Yoscat 0:559e39b80702 12 ** Componentes : Servo motor, teclado numerico, tarjeta bduino.
Yoscat 0:559e39b80702 13 ** Configuraciones :
Yoscat 0:559e39b80702 14 ** Autores :
Yoscat 0:559e39b80702 15 ** ATEAM Development Group:
Yoscat 0:559e39b80702 16 ** - Trujillo Fern'andez Yosef David
Yoscat 0:559e39b80702 17 **
Yoscat 0:559e39b80702 18 ** Versión :
Yoscat 0:559e39b80702 19 ** Revisión :
Yoscat 0:559e39b80702 20 ** Release :
Yoscat 0:559e39b80702 21 ** Bugs & Fixes :
Yoscat 0:559e39b80702 22 ** Date :
Yoscat 0:559e39b80702 23 **
Yoscat 0:559e39b80702 24 **
Yoscat 0:559e39b80702 25 **
Yoscat 0:559e39b80702 26 * ###########################################################################/
Yoscat 0:559e39b80702 27 */
Yoscat 0:559e39b80702 28 #include "mbed.h"
Yoscat 0:559e39b80702 29 #include <Servo.h>
Yoscat 0:559e39b80702 30 #include<string>
Yoscat 0:559e39b80702 31 DigitalOut buzzer (PTA5);
Yoscat 0:559e39b80702 32 DigitalOut gpo(D0);
Yoscat 0:559e39b80702 33 DigitalOut led(LED_RED);
Yoscat 0:559e39b80702 34 DigitalIn sensor (PTC16);
Yoscat 0:559e39b80702 35 Servo servo (PTA13);
Yoscat 0:559e39b80702 36 DigitalOut verde (PTE3);
Yoscat 0:559e39b80702 37 DigitalOut azul (PTE2);
Yoscat 0:559e39b80702 38
Yoscat 0:559e39b80702 39
Yoscat 0:559e39b80702 40
Yoscat 0:559e39b80702 41 void open (){
Yoscat 0:559e39b80702 42 /*for (int i=0; i<50; i++){
Yoscat 0:559e39b80702 43 servo=1;
Yoscat 0:559e39b80702 44 wait_us(2300);
Yoscat 0:559e39b80702 45 servo=0;
Yoscat 0:559e39b80702 46 wait_ms(18);
Yoscat 0:559e39b80702 47 }*/
Yoscat 0:559e39b80702 48 servo=1;
Yoscat 0:559e39b80702 49 verde=1;
Yoscat 0:559e39b80702 50 azul=0;
Yoscat 0:559e39b80702 51 //wait(5);
Yoscat 0:559e39b80702 52
Yoscat 0:559e39b80702 53 }
Yoscat 0:559e39b80702 54
Yoscat 0:559e39b80702 55
Yoscat 0:559e39b80702 56
Yoscat 0:559e39b80702 57 void close (){
Yoscat 0:559e39b80702 58 /*for (int i=0; i<50; i++){
Yoscat 0:559e39b80702 59 servo=1;
Yoscat 0:559e39b80702 60 wait_us(700);
Yoscat 0:559e39b80702 61 servo=0;
Yoscat 0:559e39b80702 62 wait_ms(20);
Yoscat 0:559e39b80702 63 }*/
Yoscat 0:559e39b80702 64 verde=0;
Yoscat 0:559e39b80702 65 azul=1;
Yoscat 0:559e39b80702 66 // wait(5);
Yoscat 0:559e39b80702 67
Yoscat 0:559e39b80702 68 }
Yoscat 0:559e39b80702 69
Yoscat 0:559e39b80702 70
Yoscat 0:559e39b80702 71 using namespace std;
Yoscat 0:559e39b80702 72 const int numeros[]={0x81,0xE7,0x49,0x43,0x27,0x13,0x11,0xC7,0x01,0x03,0xFF};
Yoscat 0:559e39b80702 73 const int letras[]={0x05,0x31,0x99,0x61,0x19,0x1D,0x03,0x25,0xE7,0xC3,0xE7,0xB9,0x85,0x85,0x81,0x0D,0x07,0x7D,0x13,0x39,0xA1,0xA1,0xA1,0x25,0x27,0x49};
Yoscat 0:559e39b80702 74 char const kpdLayout[4][4] = {{'1' ,'2' ,'3' ,'A'}, //row0
Yoscat 0:559e39b80702 75 {'4' ,'5' ,'6' ,'B'}, //row1
Yoscat 0:559e39b80702 76 {'7' ,'8' ,'9' ,'C'}, //row2
Yoscat 0:559e39b80702 77 {'*' ,'0' ,'#' ,'D'}}; //row3
Yoscat 0:559e39b80702 78
Yoscat 0:559e39b80702 79 const int contrasena [4]= {1,0,1,0};
Yoscat 0:559e39b80702 80
Yoscat 0:559e39b80702 81 struct matriz
Yoscat 0:559e39b80702 82 {
Yoscat 0:559e39b80702 83 int anterior, actual, estado;
Yoscat 0:559e39b80702 84 char caracter;
Yoscat 0:559e39b80702 85 };// end estruct
Yoscat 0:559e39b80702 86 class BusDisplay
Yoscat 0:559e39b80702 87 {
Yoscat 0:559e39b80702 88 protected:
Yoscat 0:559e39b80702 89 int dig;
Yoscat 0:559e39b80702 90 DigitalOut *_pin[8], *_control[4];
Yoscat 0:559e39b80702 91 matriz **_matriz;
Yoscat 0:559e39b80702 92 DigitalIn *_keypad[4];
Yoscat 0:559e39b80702 93 public:
Yoscat 0:559e39b80702 94 BusDisplay(PinName p0 = NC, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,PinName p8= NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, PinName p12= NC, PinName p13= NC, PinName p14= NC, PinName p15= NC );
Yoscat 0:559e39b80702 95 void write(int value);
Yoscat 0:559e39b80702 96 void write_text(BusDisplay &cadena, string text );
Yoscat 0:559e39b80702 97 void write_value(BusDisplay &cadena, int entrada[]);
Yoscat 0:559e39b80702 98 void read ( BusDisplay &cadena, int &a);
Yoscat 0:559e39b80702 99
Yoscat 0:559e39b80702 100
Yoscat 0:559e39b80702 101 virtual ~BusDisplay();
Yoscat 0:559e39b80702 102 };//class Busdisplay
Yoscat 0:559e39b80702 103 BusDisplay::BusDisplay(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7,PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15)
Yoscat 0:559e39b80702 104 {
Yoscat 0:559e39b80702 105 PinName pins[8] = {p0, p1, p2, p3, p4, p5, p6, p7};
Yoscat 0:559e39b80702 106 PinName control[4]= {p8, p9, p10, p11};
Yoscat 0:559e39b80702 107
Yoscat 0:559e39b80702 108 for (int i=0; i<8; i++)
Yoscat 0:559e39b80702 109 {
Yoscat 0:559e39b80702 110 _pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
Yoscat 0:559e39b80702 111 //_pin[i]->write(0);
Yoscat 0:559e39b80702 112 }
Yoscat 0:559e39b80702 113 for (int i=0; i<4; i++)
Yoscat 0:559e39b80702 114 {
Yoscat 0:559e39b80702 115 _control[i] = (control[i] != NC) ? new DigitalOut(control[i]) : 0;
Yoscat 0:559e39b80702 116 //_control[i]->write(0);
Yoscat 0:559e39b80702 117 }
Yoscat 0:559e39b80702 118 dig=4;
Yoscat 0:559e39b80702 119 PinName keypad[4]= {p12, p13, p14, p15};
Yoscat 0:559e39b80702 120 for (int i=0; i<4; i++)
Yoscat 0:559e39b80702 121 {
Yoscat 0:559e39b80702 122 _keypad[i] = (keypad[i] != NC) ? new DigitalIn(keypad[i], PullUp) : 0;
Yoscat 0:559e39b80702 123
Yoscat 0:559e39b80702 124 }
Yoscat 0:559e39b80702 125 _matriz= new matriz *[4];
Yoscat 0:559e39b80702 126 for(int i=0; i<4; i++)
Yoscat 0:559e39b80702 127 {
Yoscat 0:559e39b80702 128 _matriz[i]= new matriz [4];
Yoscat 0:559e39b80702 129 }
Yoscat 0:559e39b80702 130 for (int i=0; i<4; i++)
Yoscat 0:559e39b80702 131 {
Yoscat 0:559e39b80702 132 for (int j=0; j<4; j++)
Yoscat 0:559e39b80702 133 {
Yoscat 0:559e39b80702 134 (*(_matriz+i)+j)->estado=3;
Yoscat 0:559e39b80702 135 (*(_matriz+i)+j)->anterior=0;
Yoscat 0:559e39b80702 136 (*(_matriz+i)+j)->actual=0;
Yoscat 0:559e39b80702 137 (*(_matriz+i)+j)->caracter= kpdLayout[i][j];
Yoscat 0:559e39b80702 138 }
Yoscat 0:559e39b80702 139 }
Yoscat 0:559e39b80702 140
Yoscat 0:559e39b80702 141
Yoscat 0:559e39b80702 142
Yoscat 0:559e39b80702 143 } //BusDisplay
Yoscat 0:559e39b80702 144
Yoscat 0:559e39b80702 145 void BusDisplay::write_text(BusDisplay &cadena, string text )
Yoscat 0:559e39b80702 146 {
Yoscat 0:559e39b80702 147 int i=0 ;
Yoscat 0:559e39b80702 148 while(text[i]!='\0') {
Yoscat 0:559e39b80702 149 cadena.write(letras[(((int)text[i])-65)]);
Yoscat 0:559e39b80702 150 i++;
Yoscat 0:559e39b80702 151 }//end while
Yoscat 0:559e39b80702 152
Yoscat 0:559e39b80702 153 }//write_text
Yoscat 0:559e39b80702 154 void BusDisplay::write_value(BusDisplay &cadena, int entrada[])
Yoscat 0:559e39b80702 155 {
Yoscat 0:559e39b80702 156 /*int millares=numero/1000;
Yoscat 0:559e39b80702 157 int centenas=(numero-(millares*1000))/100;
Yoscat 0:559e39b80702 158 int decenas=(numero- (millares*1000 + centenas*100))/10;
Yoscat 0:559e39b80702 159 int unidades=numero-(millares*1000 + centenas*100 + decenas*10 );*/
Yoscat 0:559e39b80702 160
Yoscat 0:559e39b80702 161 cadena.write(numeros[entrada[0]]);
Yoscat 0:559e39b80702 162 cadena.write(numeros[entrada[1]]);
Yoscat 0:559e39b80702 163 cadena.write(numeros[entrada[2]]);
Yoscat 0:559e39b80702 164 cadena.write(numeros[entrada[3]]);
Yoscat 0:559e39b80702 165 }//write_value
Yoscat 0:559e39b80702 166
Yoscat 0:559e39b80702 167
Yoscat 0:559e39b80702 168
Yoscat 0:559e39b80702 169
Yoscat 0:559e39b80702 170 void BusDisplay::write(int value)
Yoscat 0:559e39b80702 171 {
Yoscat 0:559e39b80702 172
Yoscat 0:559e39b80702 173 if(dig==4) {
Yoscat 0:559e39b80702 174
Yoscat 0:559e39b80702 175 for (int i=0; i<8; i++) {
Yoscat 0:559e39b80702 176 if (_pin[i] != 0) {
Yoscat 0:559e39b80702 177
Yoscat 0:559e39b80702 178 _pin[i]->write((value >> i) & 1);
Yoscat 0:559e39b80702 179 }
Yoscat 0:559e39b80702 180 }
Yoscat 0:559e39b80702 181 _control[0]->write(1);
Yoscat 0:559e39b80702 182 for(int j=0; j<4;j++){
Yoscat 0:559e39b80702 183 (*(_matriz+0)+j)->actual=! (_keypad[j]->read());
Yoscat 0:559e39b80702 184 // wait_ms(5);
Yoscat 0:559e39b80702 185 }
Yoscat 0:559e39b80702 186 _control[1]->write(0);
Yoscat 0:559e39b80702 187 _control[2]->write(0);
Yoscat 0:559e39b80702 188 _control[3]->write(0);
Yoscat 0:559e39b80702 189 wait_ms(5);
Yoscat 0:559e39b80702 190 }//endif(digi==4)
Yoscat 0:559e39b80702 191 else if(dig==3) {
Yoscat 0:559e39b80702 192 for (int i=0; i<8; i++) {
Yoscat 0:559e39b80702 193 if (_pin[i] != 0) {
Yoscat 0:559e39b80702 194 _pin[i]->write((value >> i) & 1);
Yoscat 0:559e39b80702 195 }
Yoscat 0:559e39b80702 196 }
Yoscat 0:559e39b80702 197 _control[0]->write(0);
Yoscat 0:559e39b80702 198 _control[1]->write(1);
Yoscat 0:559e39b80702 199 for(int j=0; j<4;j++){
Yoscat 0:559e39b80702 200 (*(_matriz+1)+j)->actual=!(_keypad[j]->read());
Yoscat 0:559e39b80702 201 // wait_ms(5);
Yoscat 0:559e39b80702 202 }
Yoscat 0:559e39b80702 203 _control[2]->write(0);
Yoscat 0:559e39b80702 204 _control[3]->write(0);
Yoscat 0:559e39b80702 205 wait_ms(5);
Yoscat 0:559e39b80702 206
Yoscat 0:559e39b80702 207
Yoscat 0:559e39b80702 208 }//endif(digi==3)
Yoscat 0:559e39b80702 209 else if(dig==2) {
Yoscat 0:559e39b80702 210
Yoscat 0:559e39b80702 211 for (int i=0; i<8; i++) {
Yoscat 0:559e39b80702 212 if (_pin[i] != 0) {
Yoscat 0:559e39b80702 213 _pin[i]->write((value >> i) & 1);
Yoscat 0:559e39b80702 214 }
Yoscat 0:559e39b80702 215 }
Yoscat 0:559e39b80702 216 _control[0]->write(0);
Yoscat 0:559e39b80702 217 _control[1]->write(0);
Yoscat 0:559e39b80702 218 _control[2]->write(1);
Yoscat 0:559e39b80702 219 for(int j=0; j<4;j++){
Yoscat 0:559e39b80702 220 (*(_matriz+2)+j)->actual=!(_keypad[j]->read());
Yoscat 0:559e39b80702 221 // wait_ms(5);
Yoscat 0:559e39b80702 222 }
Yoscat 0:559e39b80702 223 _control[3]->write(0);
Yoscat 0:559e39b80702 224 wait_ms(5);
Yoscat 0:559e39b80702 225
Yoscat 0:559e39b80702 226 }//endif(digi==2)
Yoscat 0:559e39b80702 227 else if(dig==1) {
Yoscat 0:559e39b80702 228
Yoscat 0:559e39b80702 229 for (int i=0; i<8; i++) {
Yoscat 0:559e39b80702 230 if (_pin[i] != 0) {
Yoscat 0:559e39b80702 231 _pin[i]->write((value >> i) & 1);
Yoscat 0:559e39b80702 232 }
Yoscat 0:559e39b80702 233 }
Yoscat 0:559e39b80702 234 _control[0]->write(0);
Yoscat 0:559e39b80702 235 _control[1]->write(0);
Yoscat 0:559e39b80702 236 _control[2]->write(0);
Yoscat 0:559e39b80702 237 _control[3]->write(1);
Yoscat 0:559e39b80702 238 for(int j=0; j<4;j++){
Yoscat 0:559e39b80702 239 (*(_matriz+3)+j)->actual=!(_keypad[j]->read());
Yoscat 0:559e39b80702 240 // wait_ms(5);
Yoscat 0:559e39b80702 241 }
Yoscat 0:559e39b80702 242 wait_ms(5);
Yoscat 0:559e39b80702 243 dig=5;
Yoscat 0:559e39b80702 244
Yoscat 0:559e39b80702 245 }//endif(digi==1)
Yoscat 0:559e39b80702 246 dig--;
Yoscat 0:559e39b80702 247
Yoscat 0:559e39b80702 248
Yoscat 0:559e39b80702 249 }
Yoscat 0:559e39b80702 250 void BusDisplay::read( BusDisplay &cadena, int & a){
Yoscat 0:559e39b80702 251
Yoscat 0:559e39b80702 252 for(int i=0; i<4; i++){
Yoscat 0:559e39b80702 253 for(int j=0;j<4;j++){
Yoscat 0:559e39b80702 254 if((*(_matriz+i)+j)->actual==1){
Yoscat 0:559e39b80702 255 a= (int)(((*(_matriz+i)+j)->caracter) - 48);
Yoscat 0:559e39b80702 256
Yoscat 0:559e39b80702 257 }
Yoscat 0:559e39b80702 258 }//for j
Yoscat 0:559e39b80702 259 } //for i
Yoscat 0:559e39b80702 260
Yoscat 0:559e39b80702 261 } // end read()
Yoscat 0:559e39b80702 262 BusDisplay::~BusDisplay()
Yoscat 0:559e39b80702 263 {
Yoscat 0:559e39b80702 264 for (int i=0; i<8; i++) {
Yoscat 0:559e39b80702 265 delete _pin[i];
Yoscat 0:559e39b80702 266
Yoscat 0:559e39b80702 267 }
Yoscat 0:559e39b80702 268 for(int i=0; i<4; i++) {
Yoscat 0:559e39b80702 269 delete _control[i];
Yoscat 0:559e39b80702 270
Yoscat 0:559e39b80702 271 }
Yoscat 0:559e39b80702 272 }//~BusDisplay
Yoscat 0:559e39b80702 273
Yoscat 0:559e39b80702 274
Yoscat 0:559e39b80702 275 BusDisplay bus(PTE16,PTE17,PTE18,PTE19,PTE20,PTE21,PTE22,PTE23,PTA14,PTA15,PTA16,PTA17, PTC11,PTC10,PTC9,PTC8);
Yoscat 0:559e39b80702 276 int main(){
Yoscat 0:559e39b80702 277
Yoscat 0:559e39b80702 278
Yoscat 0:559e39b80702 279 bus.write_text(bus, "CLOSE");
Yoscat 0:559e39b80702 280
Yoscat 0:559e39b80702 281
Yoscat 0:559e39b80702 282 verde=0;
Yoscat 0:559e39b80702 283 azul=1;
Yoscat 0:559e39b80702 284
Yoscat 0:559e39b80702 285 while (true) {
Yoscat 0:559e39b80702 286 if(sensor.read()==0)
Yoscat 0:559e39b80702 287 {open();
Yoscat 0:559e39b80702 288 bus.write_text(bus, "OPEN");
Yoscat 0:559e39b80702 289 }
Yoscat 0:559e39b80702 290
Yoscat 0:559e39b80702 291 else
Yoscat 0:559e39b80702 292 {bus.write_text(bus, "CLOSE");
Yoscat 0:559e39b80702 293 close();
Yoscat 0:559e39b80702 294 }
Yoscat 0:559e39b80702 295 }
Yoscat 0:559e39b80702 296 }