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
main.cpp@0:01487f2574c6, 2014-03-31 (annotated)
- Committer:
- Jesse
- Date:
- Mon Mar 31 21:27:14 2014 +0000
- Revision:
- 0:01487f2574c6
Tarea 2,Con cualquier tecla del teclado 4x4, Se acciona el encendido de un PWM para el accionamiento de un Speaker, dandole un valor de Frecuencia dado. con un ancho de pulso fijo.
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 | 0:01487f2574c6 | 29 | |
Jesse | 0:01487f2574c6 | 30 | // Define your own keypad values |
Jesse | 0:01487f2574c6 | 31 | char Keytable[] = { '1', '2', '3', 'A', |
Jesse | 0:01487f2574c6 | 32 | '4', '5', '6', 'B', |
Jesse | 0:01487f2574c6 | 33 | '7', '8', '9', 'C', |
Jesse | 0:01487f2574c6 | 34 | '*', '0', '#', 'D' |
Jesse | 0:01487f2574c6 | 35 | }; |
Jesse | 0:01487f2574c6 | 36 | |
Jesse | 0:01487f2574c6 | 37 | |
Jesse | 0:01487f2574c6 | 38 | //Funcion de PWM |
Jesse | 0:01487f2574c6 | 39 | int PWMmodule(float pp,float Dd) |
Jesse | 0:01487f2574c6 | 40 | { |
Jesse | 0:01487f2574c6 | 41 | Pwm.period(pp); |
Jesse | 0:01487f2574c6 | 42 | Pwm.write(Dd); |
Jesse | 0:01487f2574c6 | 43 | wait(0.1); |
Jesse | 0:01487f2574c6 | 44 | Pwm.write(0); |
Jesse | 0:01487f2574c6 | 45 | return 0; |
Jesse | 0:01487f2574c6 | 46 | } |
Jesse | 0:01487f2574c6 | 47 | |
Jesse | 0:01487f2574c6 | 48 | uint32_t cbAfterInput(uint32_t Key) |
Jesse | 0:01487f2574c6 | 49 | { |
Jesse | 0:01487f2574c6 | 50 | |
Jesse | 0:01487f2574c6 | 51 | PWMmodule(pp,Dd); |
Jesse | 0:01487f2574c6 | 52 | key=Key; |
Jesse | 0:01487f2574c6 | 53 | lcd.locate(0,0); |
Jesse | 0:01487f2574c6 | 54 | lcd.printf("%c",Keytable[key]); |
Jesse | 0:01487f2574c6 | 55 | |
Jesse | 0:01487f2574c6 | 56 | return 0; |
Jesse | 0:01487f2574c6 | 57 | } |
Jesse | 0:01487f2574c6 | 58 | |
Jesse | 0:01487f2574c6 | 59 | int main() |
Jesse | 0:01487f2574c6 | 60 | |
Jesse | 0:01487f2574c6 | 61 | { |
Jesse | 0:01487f2574c6 | 62 | //Configuracion de Pines: |
Jesse | 0:01487f2574c6 | 63 | //Filas van a Resistencia que van a tierra, y tambien a los puertos |
Jesse | 0:01487f2574c6 | 64 | //Columnas van directamente a los pines de la tarjeta. |
Jesse | 0:01487f2574c6 | 65 | |
Jesse | 0:01487f2574c6 | 66 | // r0 r1 r2 r3 c0 c1 c2 c3 |
Jesse | 0:01487f2574c6 | 67 | Keypad keypad(PTA2,PTD4,PTD3,PTD1,PTD2,PTD0,PTD5,PTA13); |
Jesse | 0:01487f2574c6 | 68 | //keypad.attach(&cbAfterInput); |
Jesse | 0:01487f2574c6 | 69 | keypad.CallAfterInput(&cbAfterInput); |
Jesse | 0:01487f2574c6 | 70 | keypad.Start(); // energiza las columnas C0-C3 Del Keypad |
Jesse | 0:01487f2574c6 | 71 | |
Jesse | 0:01487f2574c6 | 72 | |
Jesse | 0:01487f2574c6 | 73 | while (1) |
Jesse | 0:01487f2574c6 | 74 | { |
Jesse | 0:01487f2574c6 | 75 | |
Jesse | 0:01487f2574c6 | 76 | } |
Jesse | 0:01487f2574c6 | 77 | } |
Jesse | 0:01487f2574c6 | 78 |