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

Files at this revision

API Documentation at this revision

Comitter:
Antulius
Date:
Fri Jun 28 17:52:12 2019 +0000
Parent:
0:a935d23434d9
Commit message:
FRDM-KL46Z_Pasos

Changed in this revision

DHT/Mbed_DHT.cpp Show annotated file Show diff for this revision Revisions of this file
DHT/Mbed_DHT.h Show annotated file Show diff for this revision Revisions of this file
DHT/dht22.cpp Show annotated file Show diff for this revision Revisions of this file
DHT/dht22.h Show annotated file Show diff for this revision Revisions of this file
Mbed_DHT.cpp Show diff for this revision Revisions of this file
Mbed_DHT.h Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
dht22.cpp Show diff for this revision Revisions of this file
dht22.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
tsi_sensor.lib Show annotated file Show diff for this revision Revisions of this file
diff -r a935d23434d9 -r e7f73d96ddde DHT/Mbed_DHT.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT/Mbed_DHT.cpp	Fri Jun 28 17:52:12 2019 +0000
@@ -0,0 +1,224 @@
+/*
+ *  DHT Library for  Digital-output Humidity and Temperature sensors
+ *
+ *  Works with DHT11, DHT22
+ *             SEN11301P,  Grove - Temperature&Humidity Sensor     (Seeed Studio)
+ *             SEN51035P,  Grove - Temperature&Humidity Sensor Pro (Seeed Studio)
+ *             AM2302   ,  temperature-humidity sensor
+ *             HM2303   ,  Digital-output humidity and temperature sensor
+ *
+ *  Copyright (C) Wim De Roeve
+ *                based on DHT22 sensor library by HO WING KIT
+ *                Arduino DHT11 library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documnetation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to  whom the Software is
+ * furished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+ 
+#include "Mbed_DHT.h"
+ 
+#define DHT_DATA_BIT_COUNT 40
+ 
+DHT::DHT(PinName pin, eType DHTtype)
+{
+    _pin = pin;
+    _DHTtype = DHTtype;
+    _firsttime = true;
+}
+ 
+DHT::~DHT()
+{
+    
+}
+ 
+eError DHT::stall(DigitalInOut &io, int const level, int const max_time)
+{
+    int cnt = 0;
+    while (level == io) {
+        if (cnt > max_time) {
+            return ERROR_NO_PATIENCE;
+        }
+        cnt++;
+        wait_us(1);
+    }
+    return ERROR_NONE;
+}
+ 
+eError DHT::readData()
+{
+    uint8_t i = 0, j = 0, b = 0, data_valid = 0;
+    uint32_t bit_value[DHT_DATA_BIT_COUNT] = {0};
+ 
+    eError err = ERROR_NONE;
+    time_t currentTime = time(NULL);
+ 
+    DigitalInOut DHT_io(_pin);
+ 
+    // IO must be in hi state to start
+    if (ERROR_NONE != stall(DHT_io, 0, 250)) {
+        return BUS_BUSY;
+    }
+ 
+    // start the transfer
+    DHT_io.output();
+    DHT_io = 0;
+    wait_ms(18);
+    DHT_io = 1;
+    wait_us(30);
+    DHT_io.input();
+    // wait till the sensor grabs the bus
+    if (ERROR_NONE != stall(DHT_io, 1, 100)) {
+        return ERROR_NOT_PRESENT;
+    }
+    // sensor should signal low 80us and then hi 80us
+    if (ERROR_NONE != stall(DHT_io, 0, 100)) {
+        return ERROR_SYNC_TIMEOUT;
+    }
+    if (ERROR_NONE != stall(DHT_io, 1, 100)) {
+        return ERROR_NO_PATIENCE;
+    }
+    // capture the data
+    for (i = 0; i < 5; i++) {
+        for (j = 0; j < 8; j++) {
+            if (ERROR_NONE != stall(DHT_io, 0, 75)) {
+                return ERROR_DATA_TIMEOUT;
+            }
+            // logic 0 is 28us max, 1 is 70us
+            wait_us(40);
+            bit_value[i*8+j] = DHT_io;
+            if (ERROR_NONE != stall(DHT_io, 1, 50)) {
+                return ERROR_DATA_TIMEOUT;
+            }
+        }
+    }
+    // store the data
+    for (i = 0; i < 5; i++) {
+        b=0;
+        for (j=0; j<8; j++) {
+            if (bit_value[i*8+j] == 1) {
+                b |= (1 << (7-j));
+            }
+        }
+        DHT_data[i]=b;
+    }
+ 
+    // uncomment to see the checksum error if it exists
+    //printf(" 0x%02x + 0x%02x + 0x%02x + 0x%02x = 0x%02x \n", DHT_data[0], DHT_data[1], DHT_data[2], DHT_data[3], DHT_data[4]);
+    data_valid = DHT_data[0] + DHT_data[1] + DHT_data[2] + DHT_data[3];
+    if (DHT_data[4] == data_valid) {
+        _lastReadTime = currentTime;
+        _lastTemperature = CalcTemperature();
+        _lastHumidity = CalcHumidity();
+ 
+    } else {
+        err = ERROR_CHECKSUM;
+    }
+ 
+    return err;
+ 
+}
+ 
+float DHT::CalcTemperature()
+{
+    int v;
+ 
+    switch (_DHTtype) {
+        case DHT11:
+            v = DHT_data[2];
+            return float(v);
+        case DHT22:
+            v = DHT_data[2] & 0x7F;
+            v *= 256;
+            v += DHT_data[3];
+            v /= 10;
+            if (DHT_data[2] & 0x80)
+                v *= -1;
+            return float(v);
+    }
+    return 0;
+}
+ 
+float DHT::ReadHumidity()
+{
+    return _lastHumidity;
+}
+ 
+float DHT::ConvertCelciustoFarenheit(float const celsius)
+{
+    return celsius * 9 / 5 + 32;
+}
+ 
+float DHT::ConvertCelciustoKelvin(float const celsius)
+{
+    return celsius + 273.15f;
+}
+ 
+// dewPoint function NOAA
+// reference: http://wahiduddin.net/calc/density_algorithms.htm
+float DHT::CalcdewPoint(float const celsius, float const humidity)
+{
+    float A0= 373.15f/(273.15f + celsius);
+    float SUM = -7.90298 * (A0-1);
+    SUM += 5.02808f * log10(A0);
+    SUM += -1.3816e-7 * (pow(10, (11.344f*(1-1/A0)))-1) ;
+    SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
+    SUM += log10(1013.246);
+    float VP = pow(10, SUM-3) * humidity;
+    float T = log(VP/0.61078f);   // temp var
+    return (241.88f * T) / (17.558f-T);
+}
+ 
+// delta max = 0.6544 wrt dewPoint()
+// 5x faster than dewPoint()
+// reference: http://en.wikipedia.org/wiki/Dew_point
+float DHT::CalcdewPointFast(float const celsius, float const humidity)
+{
+    float a = 17.271;
+    float b = 237.7;
+    float temp = (a * celsius) / (b + celsius) + log(humidity/100);
+    float Td = (b * temp) / (a - temp);
+    return Td;
+}
+ 
+float DHT::ReadTemperature(eScale Scale)
+{
+    if (Scale == FARENHEIT)
+        return ConvertCelciustoFarenheit(_lastTemperature);
+    else if (Scale == KELVIN)
+        return ConvertCelciustoKelvin(_lastTemperature);
+    else
+        return _lastTemperature;
+}
+ 
+float DHT::CalcHumidity()
+{
+    int v;
+ 
+    switch (_DHTtype) {
+        case DHT11:
+            v = DHT_data[0];
+            return float(v);
+        case DHT22:
+            v = DHT_data[0];
+            v *= 256;
+            v += DHT_data[1];
+            v /= 10;
+            return float(v);
+    }
+    return 0;
+}
\ No newline at end of file
diff -r a935d23434d9 -r e7f73d96ddde DHT/Mbed_DHT.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT/Mbed_DHT.h	Fri Jun 28 17:52:12 2019 +0000
@@ -0,0 +1,100 @@
+/*
+ *  DHT Library for  Digital-output Humidity and Temperature sensors
+ *
+ *  Works with DHT11, DHT21, DHT22
+ *             SEN11301P,  Grove - Temperature&Humidity Sensor     (Seeed Studio)
+ *             SEN51035P,  Grove - Temperature&Humidity Sensor Pro (Seeed Studio)
+ *             AM2302   ,  temperature-humidity sensor
+ *             RHT01,RHT02, RHT03    ,  Humidity and Temperature Sensor         (Sparkfun)
+ *
+ *  Copyright (C) Wim De Roeve
+ *                based on DHT22 sensor library by HO WING KIT
+ *                Arduino DHT11 library
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documnetation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to  whom the Software is
+ * furished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+ 
+#ifndef MBED_DHT_H
+#define MBED_DHT_H
+ 
+#include "mbed.h"
+ 
+typedef enum eType eType;
+enum eType {
+    DHT11     = 11,
+    SEN11301P = 11,
+    RHT01     = 11,
+    DHT22     = 22,
+    AM2302    = 22,
+    SEN51035P = 22,
+    RHT02     = 22,
+    RHT03     = 22
+};
+ 
+typedef enum eError eError;
+enum eError {
+    ERROR_NONE = 0,
+    BUS_BUSY,
+    ERROR_NOT_PRESENT,
+    ERROR_ACK_TOO_LONG,
+    ERROR_SYNC_TIMEOUT,
+    ERROR_DATA_TIMEOUT,
+    ERROR_CHECKSUM,
+    ERROR_NO_PATIENCE
+};
+ 
+typedef enum eScale eScale;
+enum eScale {
+    CELCIUS = 0,
+    FARENHEIT,
+    KELVIN
+};
+ 
+ 
+class DHT
+{
+ 
+public:
+ 
+    DHT(PinName pin, eType DHTtype);
+    ~DHT();
+    eError readData(void);
+    float ReadHumidity(void);
+    float ReadTemperature(eScale const Scale);
+    float CalcdewPoint(float const celsius, float const humidity);
+    float CalcdewPointFast(float const celsius, float const humidity);
+ 
+private:
+    time_t  _lastReadTime;
+    float _lastTemperature;
+    float _lastHumidity;
+    PinName _pin;
+    bool _firsttime;
+    eType _DHTtype;
+    uint8_t DHT_data[5];
+    float CalcTemperature();
+    float CalcHumidity();
+    float ConvertCelciustoFarenheit(float const);
+    float ConvertCelciustoKelvin(float const);
+    eError stall(DigitalInOut &io, int const level, int const max_time);
+ 
+};
+ 
+#endif
+ 
\ No newline at end of file
diff -r a935d23434d9 -r e7f73d96ddde DHT/dht22.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT/dht22.cpp	Fri Jun 28 17:52:12 2019 +0000
@@ -0,0 +1,149 @@
+/*
+ * (C) The University of Kent and Simon Cooksey 2015.
+ */
+ 
+#include "mbed.h"
+#include <inttypes.h>
+ 
+#include "dht22.h"
+ 
+/*
+ * The DHT22 uses a 1 wire interface, sending 1's and 0s by varying the length
+ * of the HIGH time on the signal pin.
+ */
+ 
+/*
+ * Wait for a rising or falling edge on the sense pin.
+ *
+ * Returns: the number of uS elapsed before the transition
+ */
+int DHT22::wait_for_edge(edge_type_t type)
+{
+    dht22_s.input();
+ 
+    // Timing is done by increasing this number, as the Timer class appears to
+    // be super slow.
+    int time = 0;
+    do {
+        wait_us(2);
+        time+=2;
+    } while(dht22_s != (int)type);
+ 
+    // wait for the edge to transition properly
+    wait_us(2);
+    return time;
+}
+ 
+/*
+ * Send a start bit to the DHT22
+ */
+void DHT22::send_start()
+{
+    dht22_s.output();
+    dht22_s = 0;
+    wait_us(DHT22_START_BIT_TIME);
+    dht22_s = 1;
+    dht22_s.input();
+}
+ 
+/*
+ * Wait for the DHT22 to send the start bit ACK, after this we can read data.
+ */
+void DHT22::await_start_response()
+{
+    dht22_s.input();
+    wait_for_edge(EDGE_TYPE_FALLING); // 20-40 uS
+    wait_for_edge(EDGE_TYPE_RISING);  // 80 uS
+    wait_for_edge(EDGE_TYPE_FALLING); // 80 uS
+}
+ 
+/*
+ * Reads 16 bits of data from the DHT22
+ *
+ * Returns: the signed value read. dht22_t.
+ * NB. the DHT22 uses a sign bit to do -ve and positive, but this is
+ * incompatible with signed numbers in C, so the conversion is done here.
+ */
+int16_t DHT22::read_word()
+{
+    dht22_s.input();
+    int32_t duration;
+    int16_t word = 0x00;
+    for(char bit = 0; bit < 16; bit++)
+    {
+        /*       /-----------\
+         *      /   duration  \    50us
+         * ----/               \-------
+         */
+        wait_for_edge(EDGE_TYPE_RISING);
+        duration = wait_for_edge(EDGE_TYPE_FALLING);
+ 
+        if(duration > DHT22_SIGNAL_HIGH_LOW_BOUNDARY)
+        {
+            word |= (1 << 15-bit);
+        }
+        else
+        {
+            word |= (0 << 15-bit);
+        }
+    }
+    if(word & 0x8000)
+        return 1 - (word ^ 0x8000);
+    return word;
+}
+ 
+/*
+ * Reads 8 bits of data from the DHT22
+ *
+ * Returns: the unsigned checksum value read. dht22_t.
+ */
+uint8_t DHT22::read_checksum()
+{
+    dht22_s.input();
+    uint32_t duration;
+    uint8_t word;
+    for(char bit = 0; bit < sizeof(uint8_t)*8; bit++)
+    {
+        /*       /-----------\
+         *      /   duration  \    50us
+         * ----/               \-------
+         */
+        wait_for_edge(EDGE_TYPE_RISING);
+        duration = wait_for_edge(EDGE_TYPE_FALLING);
+ 
+        if(duration > DHT22_SIGNAL_HIGH_LOW_BOUNDARY)
+        {
+            word |= (1 << 7-bit);
+        }
+        else
+        {
+            word |= (0 << 7-bit);
+        }
+    }
+    return word;
+}
+ 
+/*
+ * Reads a packet of DHT22 data.
+ *
+ * Param data: the packet to fill.
+ */
+void DHT22::read(DHT22_data_t * data)
+{
+    // Send start bits
+    send_start();
+ 
+    // Wait for device to respond
+    await_start_response();
+ 
+    // Read data bits (16+16)
+    int16_t humidity = read_word();
+    int16_t temp = read_word();
+ 
+    // Read checksum  (8)
+    uint8_t checksum = read_checksum();
+ 
+    data->humidity = (humidity);
+    data->temp = (temp);
+    data->checksum = checksum;
+}
\ No newline at end of file
diff -r a935d23434d9 -r e7f73d96ddde DHT/dht22.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DHT/dht22.h	Fri Jun 28 17:52:12 2019 +0000
@@ -0,0 +1,38 @@
+/*
+ * (C) The University of Kent and Simon Cooksey 2015.
+ */
+ 
+#ifndef __DHT22_h_
+#define __DHT22_h_
+ 
+// We'll pick a point to decide if a signal is 1 or 0 from. 
+#define DHT22_SIGNAL_HIGH_LOW_BOUNDARY      50   // uS
+#define DHT22_START_BIT_TIME                500  // uS
+#define DHT22_START_BIT_RESPONSE            80   // uS
+ 
+typedef enum {
+    EDGE_TYPE_FALLING,
+    EDGE_TYPE_RISING,
+} edge_type_t;
+ 
+typedef struct {
+    int temp;
+    int humidity;
+    uint8_t checksum;
+} DHT22_data_t;
+ 
+class DHT22 {
+public:
+    DHT22(PinName pin)  : dht22_s(pin) { }
+    void read(DHT22_data_t * data);
+private:
+    DigitalInOut dht22_s;
+ 
+    int wait_for_edge(edge_type_t type);
+    void send_start();
+    void await_start_response();
+    int16_t read_word();
+    uint8_t read_checksum();
+};
+ 
+#endif // __DHT22_h_
diff -r a935d23434d9 -r e7f73d96ddde Mbed_DHT.cpp
--- a/Mbed_DHT.cpp	Fri May 11 02:33:01 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,224 +0,0 @@
-/*
- *  DHT Library for  Digital-output Humidity and Temperature sensors
- *
- *  Works with DHT11, DHT22
- *             SEN11301P,  Grove - Temperature&Humidity Sensor     (Seeed Studio)
- *             SEN51035P,  Grove - Temperature&Humidity Sensor Pro (Seeed Studio)
- *             AM2302   ,  temperature-humidity sensor
- *             HM2303   ,  Digital-output humidity and temperature sensor
- *
- *  Copyright (C) Wim De Roeve
- *                based on DHT22 sensor library by HO WING KIT
- *                Arduino DHT11 library
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documnetation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to  whom the Software is
- * furished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- 
-#include "Mbed_DHT.h"
- 
-#define DHT_DATA_BIT_COUNT 40
- 
-DHT::DHT(PinName pin, eType DHTtype)
-{
-    _pin = pin;
-    _DHTtype = DHTtype;
-    _firsttime = true;
-}
- 
-DHT::~DHT()
-{
-    
-}
- 
-eError DHT::stall(DigitalInOut &io, int const level, int const max_time)
-{
-    int cnt = 0;
-    while (level == io) {
-        if (cnt > max_time) {
-            return ERROR_NO_PATIENCE;
-        }
-        cnt++;
-        wait_us(1);
-    }
-    return ERROR_NONE;
-}
- 
-eError DHT::readData()
-{
-    uint8_t i = 0, j = 0, b = 0, data_valid = 0;
-    uint32_t bit_value[DHT_DATA_BIT_COUNT] = {0};
- 
-    eError err = ERROR_NONE;
-    time_t currentTime = time(NULL);
- 
-    DigitalInOut DHT_io(_pin);
- 
-    // IO must be in hi state to start
-    if (ERROR_NONE != stall(DHT_io, 0, 250)) {
-        return BUS_BUSY;
-    }
- 
-    // start the transfer
-    DHT_io.output();
-    DHT_io = 0;
-    wait_ms(18);
-    DHT_io = 1;
-    wait_us(30);
-    DHT_io.input();
-    // wait till the sensor grabs the bus
-    if (ERROR_NONE != stall(DHT_io, 1, 100)) {
-        return ERROR_NOT_PRESENT;
-    }
-    // sensor should signal low 80us and then hi 80us
-    if (ERROR_NONE != stall(DHT_io, 0, 100)) {
-        return ERROR_SYNC_TIMEOUT;
-    }
-    if (ERROR_NONE != stall(DHT_io, 1, 100)) {
-        return ERROR_NO_PATIENCE;
-    }
-    // capture the data
-    for (i = 0; i < 5; i++) {
-        for (j = 0; j < 8; j++) {
-            if (ERROR_NONE != stall(DHT_io, 0, 75)) {
-                return ERROR_DATA_TIMEOUT;
-            }
-            // logic 0 is 28us max, 1 is 70us
-            wait_us(40);
-            bit_value[i*8+j] = DHT_io;
-            if (ERROR_NONE != stall(DHT_io, 1, 50)) {
-                return ERROR_DATA_TIMEOUT;
-            }
-        }
-    }
-    // store the data
-    for (i = 0; i < 5; i++) {
-        b=0;
-        for (j=0; j<8; j++) {
-            if (bit_value[i*8+j] == 1) {
-                b |= (1 << (7-j));
-            }
-        }
-        DHT_data[i]=b;
-    }
- 
-    // uncomment to see the checksum error if it exists
-    //printf(" 0x%02x + 0x%02x + 0x%02x + 0x%02x = 0x%02x \n", DHT_data[0], DHT_data[1], DHT_data[2], DHT_data[3], DHT_data[4]);
-    data_valid = DHT_data[0] + DHT_data[1] + DHT_data[2] + DHT_data[3];
-    if (DHT_data[4] == data_valid) {
-        _lastReadTime = currentTime;
-        _lastTemperature = CalcTemperature();
-        _lastHumidity = CalcHumidity();
- 
-    } else {
-        err = ERROR_CHECKSUM;
-    }
- 
-    return err;
- 
-}
- 
-float DHT::CalcTemperature()
-{
-    int v;
- 
-    switch (_DHTtype) {
-        case DHT11:
-            v = DHT_data[2];
-            return float(v);
-        case DHT22:
-            v = DHT_data[2] & 0x7F;
-            v *= 256;
-            v += DHT_data[3];
-            v /= 10;
-            if (DHT_data[2] & 0x80)
-                v *= -1;
-            return float(v);
-    }
-    return 0;
-}
- 
-float DHT::ReadHumidity()
-{
-    return _lastHumidity;
-}
- 
-float DHT::ConvertCelciustoFarenheit(float const celsius)
-{
-    return celsius * 9 / 5 + 32;
-}
- 
-float DHT::ConvertCelciustoKelvin(float const celsius)
-{
-    return celsius + 273.15f;
-}
- 
-// dewPoint function NOAA
-// reference: http://wahiduddin.net/calc/density_algorithms.htm
-float DHT::CalcdewPoint(float const celsius, float const humidity)
-{
-    float A0= 373.15f/(273.15f + celsius);
-    float SUM = -7.90298 * (A0-1);
-    SUM += 5.02808f * log10(A0);
-    SUM += -1.3816e-7 * (pow(10, (11.344f*(1-1/A0)))-1) ;
-    SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
-    SUM += log10(1013.246);
-    float VP = pow(10, SUM-3) * humidity;
-    float T = log(VP/0.61078f);   // temp var
-    return (241.88f * T) / (17.558f-T);
-}
- 
-// delta max = 0.6544 wrt dewPoint()
-// 5x faster than dewPoint()
-// reference: http://en.wikipedia.org/wiki/Dew_point
-float DHT::CalcdewPointFast(float const celsius, float const humidity)
-{
-    float a = 17.271;
-    float b = 237.7;
-    float temp = (a * celsius) / (b + celsius) + log(humidity/100);
-    float Td = (b * temp) / (a - temp);
-    return Td;
-}
- 
-float DHT::ReadTemperature(eScale Scale)
-{
-    if (Scale == FARENHEIT)
-        return ConvertCelciustoFarenheit(_lastTemperature);
-    else if (Scale == KELVIN)
-        return ConvertCelciustoKelvin(_lastTemperature);
-    else
-        return _lastTemperature;
-}
- 
-float DHT::CalcHumidity()
-{
-    int v;
- 
-    switch (_DHTtype) {
-        case DHT11:
-            v = DHT_data[0];
-            return float(v);
-        case DHT22:
-            v = DHT_data[0];
-            v *= 256;
-            v += DHT_data[1];
-            v /= 10;
-            return float(v);
-    }
-    return 0;
-}
\ No newline at end of file
diff -r a935d23434d9 -r e7f73d96ddde Mbed_DHT.h
--- a/Mbed_DHT.h	Fri May 11 02:33:01 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/*
- *  DHT Library for  Digital-output Humidity and Temperature sensors
- *
- *  Works with DHT11, DHT21, DHT22
- *             SEN11301P,  Grove - Temperature&Humidity Sensor     (Seeed Studio)
- *             SEN51035P,  Grove - Temperature&Humidity Sensor Pro (Seeed Studio)
- *             AM2302   ,  temperature-humidity sensor
- *             RHT01,RHT02, RHT03    ,  Humidity and Temperature Sensor         (Sparkfun)
- *
- *  Copyright (C) Wim De Roeve
- *                based on DHT22 sensor library by HO WING KIT
- *                Arduino DHT11 library
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documnetation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to  whom the Software is
- * furished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- 
-#ifndef MBED_DHT_H
-#define MBED_DHT_H
- 
-#include "mbed.h"
- 
-typedef enum eType eType;
-enum eType {
-    DHT11     = 11,
-    SEN11301P = 11,
-    RHT01     = 11,
-    DHT22     = 22,
-    AM2302    = 22,
-    SEN51035P = 22,
-    RHT02     = 22,
-    RHT03     = 22
-};
- 
-typedef enum eError eError;
-enum eError {
-    ERROR_NONE = 0,
-    BUS_BUSY,
-    ERROR_NOT_PRESENT,
-    ERROR_ACK_TOO_LONG,
-    ERROR_SYNC_TIMEOUT,
-    ERROR_DATA_TIMEOUT,
-    ERROR_CHECKSUM,
-    ERROR_NO_PATIENCE
-};
- 
-typedef enum eScale eScale;
-enum eScale {
-    CELCIUS = 0,
-    FARENHEIT,
-    KELVIN
-};
- 
- 
-class DHT
-{
- 
-public:
- 
-    DHT(PinName pin, eType DHTtype);
-    ~DHT();
-    eError readData(void);
-    float ReadHumidity(void);
-    float ReadTemperature(eScale const Scale);
-    float CalcdewPoint(float const celsius, float const humidity);
-    float CalcdewPointFast(float const celsius, float const humidity);
- 
-private:
-    time_t  _lastReadTime;
-    float _lastTemperature;
-    float _lastHumidity;
-    PinName _pin;
-    bool _firsttime;
-    eType _DHTtype;
-    uint8_t DHT_data[5];
-    float CalcTemperature();
-    float CalcHumidity();
-    float ConvertCelciustoFarenheit(float const);
-    float ConvertCelciustoKelvin(float const);
-    eError stall(DigitalInOut &io, int const level, int const max_time);
- 
-};
- 
-#endif
- 
\ No newline at end of file
diff -r a935d23434d9 -r e7f73d96ddde TSI.lib
--- a/TSI.lib	Fri May 11 02:33:01 2018 +0000
+++ b/TSI.lib	Fri Jun 28 17:52:12 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/vsluiter/code/TSI/#4dc2f5a3a731
+http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r a935d23434d9 -r e7f73d96ddde TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Jun 28 17:52:12 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/IPN-ESIME-ZACATENCO/code/TextLCD/#844090a5557e
diff -r a935d23434d9 -r e7f73d96ddde dht22.cpp
--- a/dht22.cpp	Fri May 11 02:33:01 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,149 +0,0 @@
-/*
- * (C) The University of Kent and Simon Cooksey 2015.
- */
- 
-#include "mbed.h"
-#include <inttypes.h>
- 
-#include "dht22.h"
- 
-/*
- * The DHT22 uses a 1 wire interface, sending 1's and 0s by varying the length
- * of the HIGH time on the signal pin.
- */
- 
-/*
- * Wait for a rising or falling edge on the sense pin.
- *
- * Returns: the number of uS elapsed before the transition
- */
-int DHT22::wait_for_edge(edge_type_t type)
-{
-    dht22_s.input();
- 
-    // Timing is done by increasing this number, as the Timer class appears to
-    // be super slow.
-    int time = 0;
-    do {
-        wait_us(2);
-        time+=2;
-    } while(dht22_s != (int)type);
- 
-    // wait for the edge to transition properly
-    wait_us(2);
-    return time;
-}
- 
-/*
- * Send a start bit to the DHT22
- */
-void DHT22::send_start()
-{
-    dht22_s.output();
-    dht22_s = 0;
-    wait_us(DHT22_START_BIT_TIME);
-    dht22_s = 1;
-    dht22_s.input();
-}
- 
-/*
- * Wait for the DHT22 to send the start bit ACK, after this we can read data.
- */
-void DHT22::await_start_response()
-{
-    dht22_s.input();
-    wait_for_edge(EDGE_TYPE_FALLING); // 20-40 uS
-    wait_for_edge(EDGE_TYPE_RISING);  // 80 uS
-    wait_for_edge(EDGE_TYPE_FALLING); // 80 uS
-}
- 
-/*
- * Reads 16 bits of data from the DHT22
- *
- * Returns: the signed value read. dht22_t.
- * NB. the DHT22 uses a sign bit to do -ve and positive, but this is
- * incompatible with signed numbers in C, so the conversion is done here.
- */
-int16_t DHT22::read_word()
-{
-    dht22_s.input();
-    int32_t duration;
-    int16_t word = 0x00;
-    for(char bit = 0; bit < 16; bit++)
-    {
-        /*       /-----------\
-         *      /   duration  \    50us
-         * ----/               \-------
-         */
-        wait_for_edge(EDGE_TYPE_RISING);
-        duration = wait_for_edge(EDGE_TYPE_FALLING);
- 
-        if(duration > DHT22_SIGNAL_HIGH_LOW_BOUNDARY)
-        {
-            word |= (1 << 15-bit);
-        }
-        else
-        {
-            word |= (0 << 15-bit);
-        }
-    }
-    if(word & 0x8000)
-        return 1 - (word ^ 0x8000);
-    return word;
-}
- 
-/*
- * Reads 8 bits of data from the DHT22
- *
- * Returns: the unsigned checksum value read. dht22_t.
- */
-uint8_t DHT22::read_checksum()
-{
-    dht22_s.input();
-    uint32_t duration;
-    uint8_t word;
-    for(char bit = 0; bit < sizeof(uint8_t)*8; bit++)
-    {
-        /*       /-----------\
-         *      /   duration  \    50us
-         * ----/               \-------
-         */
-        wait_for_edge(EDGE_TYPE_RISING);
-        duration = wait_for_edge(EDGE_TYPE_FALLING);
- 
-        if(duration > DHT22_SIGNAL_HIGH_LOW_BOUNDARY)
-        {
-            word |= (1 << 7-bit);
-        }
-        else
-        {
-            word |= (0 << 7-bit);
-        }
-    }
-    return word;
-}
- 
-/*
- * Reads a packet of DHT22 data.
- *
- * Param data: the packet to fill.
- */
-void DHT22::read(DHT22_data_t * data)
-{
-    // Send start bits
-    send_start();
- 
-    // Wait for device to respond
-    await_start_response();
- 
-    // Read data bits (16+16)
-    int16_t humidity = read_word();
-    int16_t temp = read_word();
- 
-    // Read checksum  (8)
-    uint8_t checksum = read_checksum();
- 
-    data->humidity = (humidity);
-    data->temp = (temp);
-    data->checksum = checksum;
-}
\ No newline at end of file
diff -r a935d23434d9 -r e7f73d96ddde dht22.h
--- a/dht22.h	Fri May 11 02:33:01 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
- * (C) The University of Kent and Simon Cooksey 2015.
- */
- 
-#ifndef __DHT22_h_
-#define __DHT22_h_
- 
-// We'll pick a point to decide if a signal is 1 or 0 from. 
-#define DHT22_SIGNAL_HIGH_LOW_BOUNDARY      50   // uS
-#define DHT22_START_BIT_TIME                500  // uS
-#define DHT22_START_BIT_RESPONSE            80   // uS
- 
-typedef enum {
-    EDGE_TYPE_FALLING,
-    EDGE_TYPE_RISING,
-} edge_type_t;
- 
-typedef struct {
-    int temp;
-    int humidity;
-    uint8_t checksum;
-} DHT22_data_t;
- 
-class DHT22 {
-public:
-    DHT22(PinName pin)  : dht22_s(pin) { }
-    void read(DHT22_data_t * data);
-private:
-    DigitalInOut dht22_s;
- 
-    int wait_for_edge(edge_type_t type);
-    void send_start();
-    void await_start_response();
-    int16_t read_word();
-    uint8_t read_checksum();
-};
- 
-#endif // __DHT22_h_
diff -r a935d23434d9 -r e7f73d96ddde main.cpp
--- a/main.cpp	Fri May 11 02:33:01 2018 +0000
+++ b/main.cpp	Fri Jun 28 17:52:12 2019 +0000
@@ -1,88 +1,444 @@
-/*******************************************************************************
-*
-* 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
-*
-*******************************************************************************/
+/* ###########################################################################
+**    Archivo        : main.c
+**    Proyecto       : FRDM-KL46Z_Pasos
+**    Procesador     : MKL46Z256VLL4
+**    Herramienta    : Mbed
+**    Version        : Driver 01.01
+**    Compilador     : GNU C Compiler
+**    Fecha/Hora     : 14-07-2015, 11:48, # CodeGen: 0
+**    Descripción    :
+**      El programa genera las diferentes secuencias para operar un motor a pasos 
+**      (Stepper Motor).
+**      Este programa tiene 3 modos de operación:
+**          1) Medio Paso
+**          2) Pasos Completo
+**          3) Pasos Wave
+**      Además puede girar en el sentido horario o anti horario
+**   Componentes     : GPIO, Timer, etc .
+**   Configuraciones : Includes, Stacks y Drivers externos
+**   Autores         :
+**         ATEAM Development Group:
+**          - Antulio Morgado Valle
+**
+**   Versión        : Beta
+**   Revisión       : A
+**   Release        : 0
+**   Bugs & Fixes   :
+**   Date           : 20/10/2019
+**                    Added support for Led_RGB
+**                    22/09/2018 
+**                    Added LCD Menu, Beta version (with bugs)
+**
+** ###########################################################################*/
+/*
+::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+:  Includes
+::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+*/
 #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)
+#include "MKL46Z4.h"
+#include "stdio.h"
+#include "string.h"
+#include "TSISensor.h"      // Libreria para Touch Sensor Interface
+#include "TextLCD.h"        // Libreria para escritura en LCD 
+#include "I2C.h"            // Libreria para la interface I2C
+#include "SPI.h"            // Libreria para la interface SPI
+#include "Serial.h"         // Libreria para la interface Serial
+#include "MMA8451Q.h"       // Libreria para el Acelerómetro
+
+#include "stdio.h" 
+/*
+:...............................................................................
+:  Definiciones
+:...............................................................................
+*/
+#define   MMA8451_I2C_ADDRESS (0x1d<<1) // Dirección del Acelerómetro
+
+#define   Modo_Wave             3 
+#define   Paso_Doble            2
+#define   Paso_Completo         1 
+#define   Medio_Paso            0 
+#define   Sentido_Horario       1 
+#define   Sentido_Antihorario   0 
+#define   On                    0
+#define   Off                   1
+#define   TRUE                  1
+#define   FALSE                 0
+#define   DO2                   0.0078125            // 128 Hz
+#define   DOs2                  0.0073740180703125   // 136 Hz
+#define   RE2                   0.006960146234375    // 144 Hz
+#define   REs2                  0.0065695032421875   // 152 Hz
+#define   MI2                   0.006200785359375    // 161 Hz
+#define   FA2                   0.005852762015625    // 171 Hz
+#define   FAs2                  0.0055242717265625   // 181 Hz
+#define   SOL2                  0.0052142181796875   // 192 Hz
+#define   SOLs2                 0.0049215666015625   // 203 Hz
+#define   LA2                   0.004645340296875    // 215 Hz
+#define   LAs2                  0.004384617375       // 228 Hz
+#define   SI2                   0.0041385277109375   // 242 Hz
+#define   DO3                   0.00390625           // 256 Hz
+#define   DOs3                  0.00368700903515625  // 271 Hz
+#define   RE3                   0.0034800731171875   // 287 Hz
+#define   REs3                  0.00328475162109375  // 304 Hz
+#define   MI3                   0.0031003926796875   // 323 Hz
+#define   FA3                   0.0029263810078125   // 342 Hz
+#define   FAs3                  0.0055242717265625   // 362 Hz
+#define   SOL3                  0.00260710908984375  // 384 Hz
+#define   SOLs3                 0.00246078330078125  // 406 Hz
+#define   LA3                   0.0023226701484375   // 431 Hz
+#define   LAs3                  0.0021923086875      // 456 Hz
+#define   SI3                   0.00206926385546875  // 483 Hz
+#define   DO4                   0.00390625           // 512 Hz
+#define   DOs4                  0.001843504517578125 // 542 Hz
+#define   RE4                   0.00174003655859375  // 575 Hz
+#define   REs4                  0.001642375810546875 // 609 Hz
+#define   MI4                   0.00155019633984375  // 645 Hz
+#define   FA4                   0.00146319050390625  // 683 Hz
+#define   FAs4                  0.001381067931640625 // 724 Hz
+#define   SOL4                  0.001303554544921875 // 767 Hz
+#define   SOLs4                 0.001230391650390625 // 813 Hz
+#define   LA4                   0.00116133507421875  // 861 Hz
+#define   LAs4                  0.00109615434375     // 912 Hz
+#define   SI4                   0.001034631927734375 // 966 Hz
+#define   DO5                   0.001953125          // 1024 Hz
+/*
++-------------------------------------------------------------------------------
+|  Configuración de Puertos 
++-------------------------------------------------------------------------------
+*/
+Ticker     Barrido;                     // Interrupción del Timer
+BusOut     Salidas(PTE19, PTE18, PTE17, PTE16); // Salidas a las bobinas:  A  /A   B  /B
+DigitalOut Led_Azul  (PTE2);            // Definición para el Led Azul
+DigitalOut Led_Verde (PTE3);            // Definición para el Led Verde
+DigitalOut Led_Rojo  (PTE6);            // Definición para el Led Rojo
+DigitalOut Green_Led (PTD5);            // Led de Actividad del Programa
+DigitalOut Red_Led   (PTE29);           // Led de Actividad del Programa
+DigitalIn  Adelante  (PTC3, PullUp);    // Switch para mover hacia Adelante
+DigitalIn  Atras     (PTC12,PullUp);    // Switch para mover hacia Atras     
+BusIn      Modo      (PTB18,PTB19);     // Modo de operación de los motores
+PwmOut     Backlight (PTD2);            // Activacion Backlight del LCD
+PwmOut     Buzzer    (PTE31);           // Salida del Buzzer
+
+/*
+** -------------------------------------------------------------------
+**    Inicialización de los Pines de Funciones Especiales.
+** -------------------------------------------------------------------
+*/
+TSISensor  tsi;                         //activa el Touch Sensor Interface
+
+// Host PC Communication channels
+Serial      terminal(USBTX, USBRX);     // USB Terminal Interface Tx, Rx
+//Serial    terminal(PTA2,PTA1);        // Terminal Serial
+//Serial    terminal(PTE0, PTE1);       // Tx, Rx Using MAX3232 or BlueTooth
+//Serial    terminal(PTE22, PTE23);
+// -------- Bluetooth Communication support --------
+Serial      bluetooth(PTE0, PTE1);      // Tx, Rx
+
+/************************************************* 
+* Inicializa la biblioteca TextLCD con los números de los pines de la interface
+* Board Freedom FRDM-KL25Z
+* IDE  Mbed On Line Compiler
+* LCD  SPI  SN74595
+* Pin  Board     LCD
+*      SPI_MOSI  SER   (white) 
+*      SPI_MISO  none  (blue)  
+*      SPI_CLK   SRCLK
+*      SPI_PCS   RCLK
+*      5V       5V  (red)
+*      GND      GND (black)
+* LCD  I2C  PCF8574A
+* Pin  Board    LCD
+*      I2C_SCL  SCL (white) + resistance pull-up 4.7k
+*      I2C_SDA  SDA (blue)  + resistance pull-up 4.7k
+*      5V       5V  (red)
+*      GND      GND (black)
+* LCD  Port PTE
+* LCD  Port PTC
+***************************************************/
+// -------- I2C Communication ---------
+//I2C         i2c_LCD(PTC2,PTC1);             // SDA, SCL
+
+// -------- SPI Communication ---------
+//SPI         spi_LCD(PTD6,PTD7,PTD5,PTD4);   // MOSI, MISO, SCLK, SSEL
+
+//--------- LCD instantiation -----------
+//TextLCD_SPI lcd(&spi_LCD, PTD4, TextLCD::LCD16x4, TextLCD::HD44780);  // SPI bus, SN74595 expander, CS pin, LCD Type 
+//TextLCD_I2C lcd(&i2c_LCD, 0x7E, TextLCD::LCD20x4);                    // I2C bus, PCF8574A Arduino Shield, LCD Type
+TextLCD     lcd(PTC6, PTC7, PTC8, PTC9, PTC10, PTC11, TextLCD::LCD20x4); // 4bit bus: rs, e, d4-d7
+/*
++-------------------------------------------------------------------------------
+|  Variables Globales de Usuario 
++-------------------------------------------------------------------------------
+*/
+uint8_t  paso;
+uint8_t  No_Pasos;
+uint8_t  Revoluciones;
+uint8_t  Sentido;
+uint8_t  modo_paso;
+uint16_t Velocidad=50000;
+char     Cadena[20];
+char     Modo_0[]="Medio Paso\n\r";
+char     Modo_1[]="Paso Completo\n\r";
+char     Modo_2[]="Medio Paso\n\r";
+char     Modo_3[]="Modo Wave\n\r";
+char     Modo_4[]="Antihorario \n\r";
+char     Modo_5[]="Horario \n\r";
+uint8_t  Unipolar[8]      = {0x01,0x03,0x02,0x06,
+                             0x04,0x0C,0x08,0x09} ;     // Unipolar
+uint8_t  Bipolar[4]       = {0x05,0x09,0x0A,0x06} ;     // BiPolar
+uint8_t  Wave_Drive[4]    = {0x01,0x02,0x04,0x08} ;     // Modo Onda 
+uint8_t  Modo_Completo[4] = {0x03,0x06,0x0C,0x09} ;     // Paso Doble
+bool     Flag;
+uint8_t  dummy;
+/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+|  Definición de Funciones Prototipo y Rutinas de los Vectores de Interrupción
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+*/
+void Barrido_OnInterrupt(void);              // Rutina de Atención al Ticker
+void Buzzer_SetPeriodMode(float Periodo,bool Estado);
+void outstrg(char *ap_cad);
+void Despliega_L1(char *ap_cad);
+void Despliega_L2(char *ap_cad); 
+void Despliega_L3(char *ap_cad); 
+void Despliega_L4(char *ap_cad);
  
-USBMouse mouse;         //activa la función del mouse USB
-TSISensor  tsi;         //activa el Touch Sensor Interface 
+/* END Events */        // Rutinas de Atención a Interrupciones
+
+
 /*
 #===============================================================================
 |
 |               P R O G R A M A     P R I N C I P A L
 |
-#================================================================================ 
+#=============================================================================== 
 */
-int main()
+int main() {
+  /* Write your code here */
+  Barrido.attach_us(&Barrido_OnInterrupt, Velocidad);   // Le asigna el periodo de barrido cada 10 ms
+  No_Pasos=0,paso=0,modo_paso=Medio_Paso;   // Configuración de Arranque del Motor
+  Red_Led   = Off;                          //Apaga Led's de los botones
+  Green_Led = Off;     
+  terminal.baud(115200);                    //velocidad de transmisión para la terminal serial
+  /* Configufración del Display LCD */      /* Mucho OjO !!! */
+//  spi_LCD.frequency(100000);      // Frecuencia de operación para el SPI (100KHz)
+//  spi_LCD.format(8,0);            // Modo de Operación para el SPI
+//  i2c_LCD.frequency(100000);      // Frecuencia de operación para el I2C (100KHz)
+//  i2c_LCD.start();                // Inicio de operación para el I2C
+  lcd.printf("  MOTOR A PASOS");    //mensaje a desplegar en el LCD
+  terminal.printf("  MOTOR A PASOS\n\r\n");   
+  Buzzer=Off;                       // Apaga el Buzzer
+  Flag=TRUE;                        // Enciende la bandera
+  while(1) 
+  {
+  if (Flag==TRUE)
+    {
+     outstrg ("MODO DEL MOTOR A PASOS: ");
+       if (modo_paso==Modo_Wave)        strcpy (Cadena,Modo_3);
+       if (modo_paso==Paso_Doble)       strcpy (Cadena,Modo_2);
+       if (modo_paso==Paso_Completo)    strcpy (Cadena,Modo_1);  
+       if (modo_paso==Medio_Paso)       strcpy (Cadena,Modo_0);         
+     outstrg (Cadena);
+     outstrg ("SENTIDO DEL MOTOR: ");
+       if (Sentido==Sentido_Antihorario) strcpy (Cadena, Modo_4);
+       if (Sentido==Sentido_Horario)     strcpy (Cadena, Modo_5);   
+     outstrg (Cadena);
+     dummy=sprintf(Cadena,"Paso:      %3d  \n\r",paso); 
+     Despliega_L2 (Cadena);
+     outstrg (Cadena);   
+     dummy=sprintf(Cadena,"No. Pasos: %3d  \n\r",No_Pasos); 
+     Despliega_L3 (Cadena);
+     outstrg (Cadena);  
+     dummy=sprintf(Cadena,"Vueltas: %3d  \n\r",Revoluciones); 
+     Despliega_L4 (Cadena);
+     outstrg (Cadena);
+//     outstrg (Cadena);     
+     Flag=FALSE ; 
+//     if (tsi.readPercentage()!=0.0) Backlight = 1.0-tsi.readPercentage(); // Lee el TSI y cambia el Backlight del LCD
+     if (tsi.readPercentage()!=0.0) Velocidad = (1.0-tsi.readPercentage())*65535; // Lee el TSI y cambia la velocidad del motor
+     wait(0.1);
+   
+    }       // End Flag
+  }         // End While
+}           // End Main 
+/* END Pasos */
+/* END main() */
+/*
+................................................................................
+:  Rutinas de los Vectores de Interrupción
+................................................................................
+*/
+                // Las Rutinas de Atención a Interrupcion van aquí !
+
+void Barrido_OnInterrupt(void)              // Rutina de Atención al Ticker
 {
-    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)
+//    if (paso>8)paso=0;
+//    Buzzer_SetPeriodMode(LA4,FALSE);      // Apaga el Buzzer
+    modo_paso=Modo;
+  if (Flag==FALSE)
+  {
+    if (Atras==FALSE)                       // Se presionó el Botón Izquierdo?
     {
-       x  = acc.getAccX()*(desplazamiento+5);
-       y  = -acc.getAccY()*desplazamiento;
-       mouse.move(y,x);
-       boton = tsi.readPercentage();
-       izquierda = 0;
-       derecha   = 0;
-       if (boton > 0.0)
+      Red_Led=On;
+      Sentido=Sentido_Antihorario;
+      if (modo_paso==Modo_Wave)             // Modo: WAVE DRIVE
+       {
+         Buzzer_SetPeriodMode(DO2,TRUE);
+         Buzzer=On;                         // Enciende el Buzzer
+         if (paso==0) paso=3;
+             else paso-- ;
+             Salidas=Wave_Drive[paso];
+             
+       }
+      if (modo_paso==Paso_Completo)            // Modo: FULL STEP
+       {
+        Buzzer_SetPeriodMode(MI2,TRUE);
+        Buzzer=On;                          // Enciende el Buzzer
+        if (paso==0) paso=6;
+            else 
+            {
+             paso--; 
+             paso--;                  
+            }
+            Salidas=(Unipolar [paso]);           
+       }
+      if (modo_paso==Medio_Paso)            // Modo: HALF STEP
+       {
+        Buzzer_SetPeriodMode(SOL2,TRUE);
+        Buzzer=On;                          // Enciende el Buzzer
+        if (paso==0) paso=7;
+            else paso-- ;
+            Salidas=(Unipolar [paso]);  
+       }
+      if (modo_paso==Paso_Doble)             // Modo: DOUBLE STEP
+       {
+         Buzzer_SetPeriodMode(LAs2,TRUE);
+         Buzzer=On;                         // Enciende el Buzzer
+         if (paso==0) paso=3;
+             else paso-- ;
+             Salidas=Bipolar[paso];
+             
+       } 
+      No_Pasos-- ;
+      Red_Led = Off;                        // Apaga Led's de los botones   
+    }
+    Flag=TRUE;
+  if (Adelante==FALSE)                       // Se presionó el Botón Derecho?
+    {
+     Green_Led=On;
+     Sentido=Sentido_Horario;
+     if (modo_paso==Modo_Wave)              // Modo: WAVE DRIVE
+       {
+         Buzzer_SetPeriodMode(DO3,TRUE); 
+         Buzzer=On;                         // Enciende el Buzzer
+         if (paso==3) paso=0;
+             else paso++ ;
+             Salidas=(Wave_Drive [paso]);    
+       }
+     if (modo_paso==Paso_Completo)          // Modo: FULL STEP
+       {
+        Buzzer_SetPeriodMode(MI3,TRUE);
+        Buzzer=On;                         // Enciende el Buzzer
+        if (paso==6) paso=0;
+            else 
+             {
+              paso++; 
+              paso++;
+             }
+            Salidas=(Unipolar [paso]);               
+       }
+     if (modo_paso==Medio_Paso)             // Modo: HALF STEP
        {
-           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);
-    }
+        Buzzer_SetPeriodMode(SOL3,TRUE);
+        Buzzer=On;                          // Enciende el Buzzer
+        if (paso==7) paso=0;
+            else paso++ ;
+            Salidas=(Unipolar [paso]);      
+       }   
+      if (modo_paso==Paso_Doble)             // Modo: DOUBLE STEP
+       {
+         Buzzer_SetPeriodMode(LAs3,TRUE);
+         Buzzer=On;                         // Enciende el Buzzer
+         if (paso==3) paso=0;
+             else paso++ ;
+             Salidas=Bipolar[paso];
+             
+       }        
+      No_Pasos++ ;     
+    } 
+      //Flag=TRUE;
+      Green_Led = Off;                      //Apaga Led's de los botones    
+  }
+     if (No_Pasos==180)  Revoluciones++;  
+   Flag=TRUE ;  
 }
+/* END Events */
+
+/*
+________________________________________________________________________________
+|
+|  Funciones Prototipo
+|_______________________________________________________________________________
+*/
+                // Las Funciones Prototipo van aquí !
+                
+void Buzzer_SetPeriodMode(float Periodo,bool Estado)
+{
+    Buzzer.period(Periodo);
+    Buzzer.pulsewidth(Periodo/2);
+    if (Estado==1)Buzzer=0.5; 
+    if (Estado==0)Buzzer=0.0; 
+}
+
+
+void outstrg(char *ap_cad) 
+{  
+  while(*ap_cad)
+  {  
+   while(!terminal.writeable()); 
+   terminal.putc(*ap_cad++);
+   printf("%s",*ap_cad);
+  }
+}
+
+void Despliega_L1(char *ap_cad) 
+{
+    lcd.locate(0,1);            //Coloca cursor de la LCD al inicio de la Linea 1.
+    lcd.printf("", *ap_cad);    //Imprime mensaje en la LCD.
+}
+void Despliega_L2(char *ap_cad) 
+{
+    lcd.locate(0,2);            //Coloca cursor de la LCD al inicio de la Linea 2.
+    lcd.printf("", *ap_cad);    //Imprime mensaje en la LCD.
+}
+void Despliega_L3(char *ap_cad) 
+{
+    lcd.locate(0,3);            //Coloca cursor de la LCD al inicio de la Linea 3.
+    lcd.printf("", *ap_cad);    //Imprime mensaje en la LCD.
+}
+void Despliega_L4(char *ap_cad) 
+{
+    lcd.locate(0,4);            //Coloca cursor de la LCD al inicio de la Linea 4.
+    lcd.printf("", *ap_cad);    //Imprime mensaje en la LCD.
+}
+/* END Routines */ 
+
+/* END program */ 
 
 /*
 +--------------------------------------------------------------------------------
 |                               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
+| 1.-   Habilitar el módulo TSI para cambiar la velocidad del motor.
+| 2.-   Habilitar el programa para que despligue los datos en la pantalla LCD: 
+|       
++-------------------------------------------------------------------------------
+|                               EXAMEN
 |
-|       Sugerencia: Revisar USBMouse.cpp y USBMouse.h
-|
-+--------------------------------------------------------------------------------
+| 1.-   Modificar el programa para que envie datos y se pueda modificar a traves 
+|       del teléfono celular por medio de la interface Bluetooth.
+| Suerte!
++-------------------------------------------------------------------------------
 |
 |                     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.
@@ -91,4 +447,5 @@
 | This program is licensed under rules of
 | THE BEANERS TECHNOLOGIES PROYECT
 +-------------------------------------------------------------------------------
-*/
\ No newline at end of file
+*/
+/* END Mbed */
\ No newline at end of file
diff -r a935d23434d9 -r e7f73d96ddde tsi_sensor.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tsi_sensor.lib	Fri Jun 28 17:52:12 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Kojto/code/tsi_sensor/#976904559b5c