FRDM-KL46Z_Pasos Es un programa que permite controlar un Motor a Pasos en sus diferntes modos de operación y tampbien permite controlar un Motor de CD en Modo ON-OFF Adelante y Atrás
Dependencies: mbed Debounced tsi_sensor TSI TextLCD MMA8451Q USBDevice
Diff: main.cpp
- Revision:
- 0:a935d23434d9
- Child:
- 1:e7f73d96ddde
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 11 02:33:01 2018 +0000 @@ -0,0 +1,94 @@ +/******************************************************************************* +* +* ARCHIVO: main.cpp +* +* PROYECTO: FRDM-KL46Z_USBMouse +* +* PROCESADOR: MKL46Z256VLL4 +* +* HERRAMIENTA: Mbed +* +* DESCRIPCION: El programa emula a un mouse USB. Utiliza el acelerómetro para +* detectar el movimieto y el TSI para simular los botones. +* Una vez descargado el programa cambiar el Cable del SDA al USB +* +* AUTOR(ES): Antulio Morgado Valle +* +* VERSION: 1.0 +* +* REVISION: 0 +* +* RELEASE: 0 +* +* BUG & FIXES: +* +* FECHA: 10/20/2014 +* +*******************************************************************************/ +#include "mbed.h" +#include "USBMouse.h" //libreria para la Interface USB +#include "TSISensor.h" //libreria Touch Sensor Interface +#include "MMA8451Q.h" //libreria para la interface del acelerómetro +#define MMA8451_I2C_ADDRESS (0x1d<<1) + +USBMouse mouse; //activa la función del mouse USB +TSISensor tsi; //activa el Touch Sensor Interface +/* +#=============================================================================== +| +| P R O G R A M A P R I N C I P A L +| +#================================================================================ +*/ +int main() +{ + MMA8451Q acc(PTE25,PTE24,MMA8451_I2C_ADDRESS); //DATO,RELOJ,DIRECCION + int16_t x = 0; + int16_t y = 0; + int32_t desplazamiento = 5; + float boton = 0; + bool izquierda = 0; + bool centro = 0; + bool derecha = 0; + + while (1) + { + x = acc.getAccX()*(desplazamiento+5); + y = -acc.getAccY()*desplazamiento; + mouse.move(y,x); + boton = tsi.readPercentage(); + izquierda = 0; + derecha = 0; + if (boton > 0.0) + { + if (tsi.readPercentage() < 0.3) derecha = 1; // Lee el TSI para buscar el boton derecho +// if (tsi.readPercentage() >=0.33 <=0.66) centro = 1; // Lee el TSI para buscar el boton central + if (tsi.readPercentage() > 0.7) izquierda = 1; // Lee el TSI para buscar el boton izquierdo + } + if (izquierda) mouse.click(MOUSE_LEFT); // Activa el click del botón izquierdo + if (derecha) mouse.click(MOUSE_RIGHT); // Activa el click del botón derecho + wait(0.001); + } +} + +/* ++-------------------------------------------------------------------------------- +| EJERCICIO +| +| 1.- Modificar el programa para que acepte tambien las funciones: + mouse.doubleclick(MOUSE_LEFT); +| 2.- Agregar al programa la función de scroll utilizando el botón central y el eje z +| utilizar MOUSE_MIDDLE +| +| Sugerencia: Revisar USBMouse.cpp y USBMouse.h +| ++-------------------------------------------------------------------------------- +| +| T H E A N T U L I U S T E A M +| Research, Development, Systems Equipment, Support & Spare Parts I n c. +| (C) Copyright 1989-2014, All rigths Reserved +| +| This program is licensed under rules of +| THE BEANERS TECHNOLOGIES PROYECT ++------------------------------------------------------------------------------- +*/ \ No newline at end of file