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 Jesse Beltran

main.cpp

Committer:
Jesse
Date:
2014-04-02
Revision:
1:4df1b22875c5
Parent:
0:01487f2574c6

File content as of revision 1:4df1b22875c5:

//Jesse Mauricio Beltran Soto
//Michelle Maceas Henao

//Manejo Basico del Teclado Matcicial , teclado matricial

#include "mbed.h"
#include "keypad.h"
#include "TextLCD.h"
 
//Definicion de puertos de la LCD

TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7

//Defino Salidas Digitales
DigitalOut myled(LED1);
DigitalOut Sonido(PTB8);



//Defino salida a Pwm
PwmOut Pwm(PTA5);

//Definicion de Variables
 
float pp=0.001;
float Dd=0.1;
char key,keyy;
int C1=0x0F;
//int C1=0x0F;
int sp=0,kp=0,kd=0,ki=0,p=0;

// Define your own keypad values
char Keytable[] = { '1', '2', '3', 'A',
                     '4', '5', '6', 'B',
                      '7', '8', '9', 'C',
                      '*', '0', '#', 'D'
                    };
 
 
//Funcion de PWM                   
int PWMmodule(float pp,float Dd)
{
        Pwm.period(pp);
        Pwm.write(Dd);
        wait(0.1);
        Pwm.write(0); 
        return 0;
}

uint32_t cbAfterInput(uint32_t Key)
{
        
    //lcd.cls();
    //lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
    //lcd.locate(9,0);
    //lcd.printf("kp=%d", kp);
    //lcd.locate(0,1);
    //lcd.printf("Ki=%d", ki);
    //lcd.locate(9,1);
    //lcd.printf("Kd=%d", kd);
    //lcd.locate(0,0);
    //lcd.printf("Sp=%d", sp);
        
        key=Key;
        //lcd.locate(0,0);
        //lcd.printf("%c",Keytable[key]);
        if(Keytable[key]=='A')
        {
            ++p;
            PWMmodule(pp,Dd);
            if (p==1)
            {
                //++p;
                lcd.locate(12,0);
                lcd.printf("%d", kp);
            }
            else if (p==2)
            {
                //++p;
                lcd.locate(3,1);
                lcd.printf("%d", ki);
                lcd.locate(3,1);
            }
            else if (p==3)
            {
                //++p;
                lcd.locate(12,1);
                lcd.printf("%d", kd);
                
            }
            else if (p==4)
            {
                lcd.locate(3,0);
                lcd.printf("%d", sp);
                p=0;
            }
        }
  
            
        return 0;
}
 
int main()

{
    
    
    lcd.cls();
    lcd.writeCommand(C1);//escribimos un comando segun el manual del modulo LCD
    lcd.locate(9,0);
    lcd.printf("kp=%d", kp);
    lcd.locate(0,1);
    lcd.printf("Ki=%d", ki);
    lcd.locate(9,1);
    lcd.printf("Kd=%d", kd);
    lcd.locate(0,0);
    lcd.printf("Sp=%d", sp);
    //lcd.locate(12,0);
    //lcd.printf("F=%d",Dd);
    //lcd.locate(12,1);
    //lcd.printf("D=%d",Pp);
    //Configuracion de Pines:
    //Filas van a Resistencia que van a tierra, y tambien a los puertos 
    //Columnas van directamente a los pines de la tarjeta.
    
    //             r0   r1   r2   r3   c0   c1   c2   c3
    Keypad keypad(PTA2,PTD4,PTD3,PTD1,PTD2,PTD0,PTD5,PTA13);
    //keypad.attach(&cbAfterInput);
    keypad.CallAfterInput(&cbAfterInput);
    keypad.Start();  // energiza las columnas C0-C3 Del Keypad

 
    while (1) 
    {
                    
    }
}