![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Tarea 2. Con cualquier pulso del teclado, se acciona la salid a PWM de un Speaker, dejando fijo el ancho de pulso y la frecuencia.
Dependencies: FPointer TextLCD keypad mbed
Fork of Tarea3_Teclado by
main.cpp@1:4df1b22875c5, 2014-04-02 (annotated)
- Committer:
- Jesse
- Date:
- Wed Apr 02 14:44:39 2014 +0000
- Revision:
- 1:4df1b22875c5
- Parent:
- 0:01487f2574c6
Tarea3.1_Mejoras
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jesse | 0:01487f2574c6 | 1 | //Jesse Mauricio Beltran Soto |
Jesse | 0:01487f2574c6 | 2 | //Michelle Maceas Henao |
Jesse | 0:01487f2574c6 | 3 | |
Jesse | 0:01487f2574c6 | 4 | //Manejo Basico del Teclado Matcicial , teclado matricial |
Jesse | 0:01487f2574c6 | 5 | |
Jesse | 0:01487f2574c6 | 6 | #include "mbed.h" |
Jesse | 0:01487f2574c6 | 7 | #include "keypad.h" |
Jesse | 0:01487f2574c6 | 8 | #include "TextLCD.h" |
Jesse | 0:01487f2574c6 | 9 | |
Jesse | 0:01487f2574c6 | 10 | //Definicion de puertos de la LCD |
Jesse | 0:01487f2574c6 | 11 | |
Jesse | 0:01487f2574c6 | 12 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 |
Jesse | 0:01487f2574c6 | 13 | |
Jesse | 0:01487f2574c6 | 14 | //Defino Salidas Digitales |
Jesse | 0:01487f2574c6 | 15 | DigitalOut myled(LED1); |
Jesse | 0:01487f2574c6 | 16 | DigitalOut Sonido(PTB8); |
Jesse | 0:01487f2574c6 | 17 | |
Jesse | 0:01487f2574c6 | 18 | |
Jesse | 0:01487f2574c6 | 19 | |
Jesse | 0:01487f2574c6 | 20 | //Defino salida a Pwm |
Jesse | 0:01487f2574c6 | 21 | PwmOut Pwm(PTA5); |
Jesse | 0:01487f2574c6 | 22 | |
Jesse | 0:01487f2574c6 | 23 | //Definicion de Variables |
Jesse | 0:01487f2574c6 | 24 | |
Jesse | 0:01487f2574c6 | 25 | float pp=0.001; |
Jesse | 0:01487f2574c6 | 26 | float Dd=0.1; |
Jesse | 0:01487f2574c6 | 27 | char key,keyy; |
Jesse | 0:01487f2574c6 | 28 | int C1=0x0F; |
Jesse | 1:4df1b22875c5 | 29 | //int C1=0x0F; |
Jesse | 1:4df1b22875c5 | 30 | int sp=0,kp=0,kd=0,ki=0,p=0; |
Jesse | 0:01487f2574c6 | 31 | |
Jesse | 0:01487f2574c6 | 32 | // Define your own keypad values |
Jesse | 0:01487f2574c6 | 33 | char Keytable[] = { '1', '2', '3', 'A', |
Jesse | 0:01487f2574c6 | 34 | '4', '5', '6', 'B', |
Jesse | 0:01487f2574c6 | 35 | '7', '8', '9', 'C', |
Jesse | 0:01487f2574c6 | 36 | '*', '0', '#', 'D' |
Jesse | 0:01487f2574c6 | 37 | }; |
Jesse | 0:01487f2574c6 | 38 | |
Jesse | 0:01487f2574c6 | 39 | |
Jesse | 0:01487f2574c6 | 40 | //Funcion de PWM |
Jesse | 0:01487f2574c6 | 41 | int PWMmodule(float pp,float Dd) |
Jesse | 0:01487f2574c6 | 42 | { |
Jesse | 0:01487f2574c6 | 43 | Pwm.period(pp); |
Jesse | 0:01487f2574c6 | 44 | Pwm.write(Dd); |
Jesse | 0:01487f2574c6 | 45 | wait(0.1); |
Jesse | 0:01487f2574c6 | 46 | Pwm.write(0); |
Jesse | 0:01487f2574c6 | 47 | return 0; |
Jesse | 0:01487f2574c6 | 48 | } |
Jesse | 0:01487f2574c6 | 49 | |
Jesse | 0:01487f2574c6 | 50 | uint32_t cbAfterInput(uint32_t Key) |
Jesse | 0:01487f2574c6 | 51 | { |
Jesse | 0:01487f2574c6 | 52 | |
Jesse | 1:4df1b22875c5 | 53 | //lcd.cls(); |
Jesse | 1:4df1b22875c5 | 54 | //lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD |
Jesse | 1:4df1b22875c5 | 55 | //lcd.locate(9,0); |
Jesse | 1:4df1b22875c5 | 56 | //lcd.printf("kp=%d", kp); |
Jesse | 1:4df1b22875c5 | 57 | //lcd.locate(0,1); |
Jesse | 1:4df1b22875c5 | 58 | //lcd.printf("Ki=%d", ki); |
Jesse | 1:4df1b22875c5 | 59 | //lcd.locate(9,1); |
Jesse | 1:4df1b22875c5 | 60 | //lcd.printf("Kd=%d", kd); |
Jesse | 1:4df1b22875c5 | 61 | //lcd.locate(0,0); |
Jesse | 1:4df1b22875c5 | 62 | //lcd.printf("Sp=%d", sp); |
Jesse | 1:4df1b22875c5 | 63 | |
Jesse | 0:01487f2574c6 | 64 | key=Key; |
Jesse | 1:4df1b22875c5 | 65 | //lcd.locate(0,0); |
Jesse | 1:4df1b22875c5 | 66 | //lcd.printf("%c",Keytable[key]); |
Jesse | 1:4df1b22875c5 | 67 | if(Keytable[key]=='A') |
Jesse | 1:4df1b22875c5 | 68 | { |
Jesse | 1:4df1b22875c5 | 69 | ++p; |
Jesse | 1:4df1b22875c5 | 70 | PWMmodule(pp,Dd); |
Jesse | 1:4df1b22875c5 | 71 | if (p==1) |
Jesse | 1:4df1b22875c5 | 72 | { |
Jesse | 1:4df1b22875c5 | 73 | //++p; |
Jesse | 1:4df1b22875c5 | 74 | lcd.locate(12,0); |
Jesse | 1:4df1b22875c5 | 75 | lcd.printf("%d", kp); |
Jesse | 1:4df1b22875c5 | 76 | } |
Jesse | 1:4df1b22875c5 | 77 | else if (p==2) |
Jesse | 1:4df1b22875c5 | 78 | { |
Jesse | 1:4df1b22875c5 | 79 | //++p; |
Jesse | 1:4df1b22875c5 | 80 | lcd.locate(3,1); |
Jesse | 1:4df1b22875c5 | 81 | lcd.printf("%d", ki); |
Jesse | 1:4df1b22875c5 | 82 | lcd.locate(3,1); |
Jesse | 1:4df1b22875c5 | 83 | } |
Jesse | 1:4df1b22875c5 | 84 | else if (p==3) |
Jesse | 1:4df1b22875c5 | 85 | { |
Jesse | 1:4df1b22875c5 | 86 | //++p; |
Jesse | 1:4df1b22875c5 | 87 | lcd.locate(12,1); |
Jesse | 1:4df1b22875c5 | 88 | lcd.printf("%d", kd); |
Jesse | 1:4df1b22875c5 | 89 | |
Jesse | 1:4df1b22875c5 | 90 | } |
Jesse | 1:4df1b22875c5 | 91 | else if (p==4) |
Jesse | 1:4df1b22875c5 | 92 | { |
Jesse | 1:4df1b22875c5 | 93 | lcd.locate(3,0); |
Jesse | 1:4df1b22875c5 | 94 | lcd.printf("%d", sp); |
Jesse | 1:4df1b22875c5 | 95 | p=0; |
Jesse | 1:4df1b22875c5 | 96 | } |
Jesse | 1:4df1b22875c5 | 97 | } |
Jesse | 1:4df1b22875c5 | 98 | |
Jesse | 0:01487f2574c6 | 99 | |
Jesse | 0:01487f2574c6 | 100 | return 0; |
Jesse | 0:01487f2574c6 | 101 | } |
Jesse | 0:01487f2574c6 | 102 | |
Jesse | 0:01487f2574c6 | 103 | int main() |
Jesse | 0:01487f2574c6 | 104 | |
Jesse | 0:01487f2574c6 | 105 | { |
Jesse | 1:4df1b22875c5 | 106 | |
Jesse | 1:4df1b22875c5 | 107 | |
Jesse | 1:4df1b22875c5 | 108 | lcd.cls(); |
Jesse | 1:4df1b22875c5 | 109 | lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD |
Jesse | 1:4df1b22875c5 | 110 | lcd.locate(9,0); |
Jesse | 1:4df1b22875c5 | 111 | lcd.printf("kp=%d", kp); |
Jesse | 1:4df1b22875c5 | 112 | lcd.locate(0,1); |
Jesse | 1:4df1b22875c5 | 113 | lcd.printf("Ki=%d", ki); |
Jesse | 1:4df1b22875c5 | 114 | lcd.locate(9,1); |
Jesse | 1:4df1b22875c5 | 115 | lcd.printf("Kd=%d", kd); |
Jesse | 1:4df1b22875c5 | 116 | lcd.locate(0,0); |
Jesse | 1:4df1b22875c5 | 117 | lcd.printf("Sp=%d", sp); |
Jesse | 1:4df1b22875c5 | 118 | //lcd.locate(12,0); |
Jesse | 1:4df1b22875c5 | 119 | //lcd.printf("F=%d",Dd); |
Jesse | 1:4df1b22875c5 | 120 | //lcd.locate(12,1); |
Jesse | 1:4df1b22875c5 | 121 | //lcd.printf("D=%d",Pp); |
Jesse | 0:01487f2574c6 | 122 | //Configuracion de Pines: |
Jesse | 0:01487f2574c6 | 123 | //Filas van a Resistencia que van a tierra, y tambien a los puertos |
Jesse | 0:01487f2574c6 | 124 | //Columnas van directamente a los pines de la tarjeta. |
Jesse | 0:01487f2574c6 | 125 | |
Jesse | 0:01487f2574c6 | 126 | // r0 r1 r2 r3 c0 c1 c2 c3 |
Jesse | 0:01487f2574c6 | 127 | Keypad keypad(PTA2,PTD4,PTD3,PTD1,PTD2,PTD0,PTD5,PTA13); |
Jesse | 0:01487f2574c6 | 128 | //keypad.attach(&cbAfterInput); |
Jesse | 0:01487f2574c6 | 129 | keypad.CallAfterInput(&cbAfterInput); |
Jesse | 0:01487f2574c6 | 130 | keypad.Start(); // energiza las columnas C0-C3 Del Keypad |
Jesse | 0:01487f2574c6 | 131 | |
Jesse | 0:01487f2574c6 | 132 | |
Jesse | 0:01487f2574c6 | 133 | while (1) |
Jesse | 0:01487f2574c6 | 134 | { |
Jesse | 1:4df1b22875c5 | 135 | |
Jesse | 0:01487f2574c6 | 136 | } |
Jesse | 0:01487f2574c6 | 137 | } |
Jesse | 0:01487f2574c6 | 138 |