Sistema de supervision y alarma para deposito de comida de animales

Files at this revision

API Documentation at this revision

Comitter:
ciror00
Date:
Fri May 14 17:27:28 2021 +0000
Commit message:
Trabajo final de la materia Introduccion a los Sistemas Embebidos

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
CONTRIBUTING.md Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
modules/arm_book_lib.h Show annotated file Show diff for this revision Revisions of this file
modules/date_and_time/date_and_time.cpp Show annotated file Show diff for this revision Revisions of this file
modules/date_and_time/date_and_time.h Show annotated file Show diff for this revision Revisions of this file
modules/display/display.cpp Show annotated file Show diff for this revision Revisions of this file
modules/display/display.h Show annotated file Show diff for this revision Revisions of this file
resources/official_armmbed_example_badge.png Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CONTRIBUTING.md	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,5 @@
+# Contributing to Mbed OS
+
+Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor.
+
+To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,64 @@
+![](./resources/official_armmbed_example_badge.png)
+# Blinky Mbed OS example
+
+The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/) and is the [getting started example for Mbed OS](https://os.mbed.com/docs/mbed-os/v5.14/quick-start/index.html). It contains an application that repeatedly blinks an LED on supported [Mbed boards](https://os.mbed.com/platforms/).
+
+You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
+
+1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html).
+
+1. Clone this repository on your system, and change the current directory to where the project was cloned:
+
+    ```bash
+    $ git clone git@github.com:armmbed/mbed-os-example-blinky && cd mbed-os-example-blinky
+    ```
+
+    Alternatively, you can download the example project with Arm Mbed CLI using the `import` subcommand:
+
+    ```bash
+    $ mbed import mbed-os-example-blinky && cd mbed-os-example-blinky
+    ```
+
+
+## Application functionality
+
+The `main()` function is the single thread in the application. It toggles the state of a digital output connected to an LED on the board.
+
+## Building and running
+
+1. Connect a USB cable between the USB port on the board and the host computer.
+2. <a name="build_cmd"></a> Run the following command to build the example project and program the microcontroller flash memory:
+    ```bash
+    $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash
+    ```
+The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin`.
+
+Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB.
+
+Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target:
+
+```bash
+$ mbed compile -S
+```
+
+## Expected output
+The LED on your target turns on and off every 500 milliseconds.
+
+
+## Troubleshooting
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
+
+## Related Links
+
+* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html).
+* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html).
+* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html).
+* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html).
+* [Mbed boards](https://os.mbed.com/platforms/).
+
+### License and contributions
+
+The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info.
+
+This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,185 @@
+//=====[Libraries]=============================================================
+
+#include "arm_book_lib.h"
+#include "display.h"
+
+//=====[Declaration of private defines]======================================
+
+#define DISPLAY_REFRESH_TIME_MS 1000
+
+//=====[Declaration and initialization of public global objects]===============
+
+Serial uartUsb(USBTX, USBRX);
+AnalogIn ligthSensor(A0);
+
+DigitalIn blueButton(BUTTON1);
+DigitalOut verminLed(LED1);
+DigitalOut alarmLed(LED3);
+DigitalOut otherLed(LED2);
+
+DigitalOut sirenPin(PE_10); // Buzzer
+
+// Interrupciones
+InterruptIn pir(PG_0); // HC-SR501
+InterruptIn shock(PG_1); // EM8343
+
+Ticker preventiveCheck;
+
+//=====[Declaration of external public global variables]=======================
+
+//=====[Declaration and initialization of public global variables]=============
+
+float ligth = 0.0;
+int shaking = 0;
+
+bool check = OFF;
+bool pirStatus = ON;
+bool paused = OFF;
+bool maintenance = OFF;
+bool verminDetectorState = OFF;
+
+//=====[Declaration and initialization of private global variables]============
+
+//=====[Declarations (prototypes) of public functions]=========================
+
+static void maintenanceMode();
+
+static void userInterfaceDisplayInit();
+static void userInterfaceDisplayUpdate(float ligth, bool vermin);
+
+static void displayClear();
+static void alarm();
+
+void verminDetected();
+void insideStatusIn();
+void insideStatusOut();
+
+//=====[Main function, the program entry point after power on or reset]========
+
+int main(){
+    userInterfaceDisplayInit();
+    
+    shock.mode(PullDown);
+    //pir.mode(PullDown);
+
+    shock.fall(&verminDetected);
+    pir.fall(&insideStatusIn);
+    preventiveCheck.attach([](){otherLed = !otherLed;}, 10.00);
+    
+    otherLed = OFF;
+    
+    while(1) {
+        maintenance = (!blueButton) ? ON : OFF;
+
+        if(maintenance){
+            if(paused == ON){
+                paused = OFF;
+                userInterfaceDisplayInit();
+            }
+            ligth = ligthSensor.read() * 100;
+            userInterfaceDisplayUpdate(ligth, check);
+            alarm();
+        }else{
+            maintenanceMode();
+        }
+    }
+}
+
+//=====[Implementations of public functions]===================================
+
+static void userInterfaceDisplayInit(){
+    displayInit( DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER );
+    displayClear();
+    displayCharPositionWrite ( 0,1 );
+    displayStringWrite( "Luz: " );
+    displayCharPositionWrite ( 0,2 );
+    displayStringWrite( "DET: " );
+}
+
+static void userInterfaceDisplayUpdate(float ligth, bool vermin){
+    static int accumulatedDisplayTime = 0;
+    char ligthString[2];
+    
+    if( accumulatedDisplayTime >= DISPLAY_REFRESH_TIME_MS ) {
+        accumulatedDisplayTime = 0;
+
+        sprintf(ligthString, "%.2f", ligth);
+        displayCharPositionWrite ( 7,1 );
+        displayStringWrite( ligthString );
+        displayCharPositionWrite ( 12,1 );
+        displayStringWrite( "lux" );
+        uartUsb.printf( "Luz: %f lux\r\n", ligth); 
+        
+        displayCharPositionWrite ( 7,2 );
+        if(!vermin || pir){
+            displayStringWrite("DETECCION");
+        }else{
+            displayStringWrite("VACIO    ");
+        }
+        
+        if(verminDetectorState){
+            displayCharPositionWrite ( 7,0 );
+            displayStringWrite("ALERTA!");
+            displayCharPositionWrite ( 7,3 );
+            displayStringWrite("ALERTA!");
+        }else{
+            displayCharPositionWrite ( 7,0 );
+            displayStringWrite("       ");
+            displayCharPositionWrite ( 7,3 );
+            displayStringWrite("       ");
+        }
+    } else {
+        accumulatedDisplayTime = accumulatedDisplayTime + 1;        
+    } 
+}
+
+static void maintenanceMode(){
+    displayClear();
+    displayCharPositionWrite(3,1);
+    displayStringWrite("MANTENIMIENTO");
+    verminDetectorState = OFF;
+    paused = ON;
+}
+
+void verminDetected(){
+    if(!verminDetectorState){
+        verminDetectorState = ON;
+    }
+}
+
+void insideStatusIn(){
+    check = ON;
+    verminLed = ON;
+    pir.fall(NULL);
+    pir.rise(&insideStatusOut);
+}
+
+void insideStatusOut(){
+    check = OFF;
+    verminLed = OFF;
+    pir.rise(NULL);
+    if(pirStatus){
+        pir.fall(&insideStatusIn);
+    }
+}
+
+static void displayClear(){
+    displayCharPositionWrite(0,0);
+    displayStringWrite("                    ");
+    displayCharPositionWrite(0,1);
+    displayStringWrite("                    ");
+    displayCharPositionWrite(0,2);
+    displayStringWrite("                    ");
+    displayCharPositionWrite(0,3);
+    displayStringWrite("                    ");
+}
+
+static void alarm(){
+    if(verminDetectorState){
+        sirenPin = !sirenPin;
+        alarmLed = sirenPin;
+    }else{
+        sirenPin = ON;
+        alarmLed = !sirenPin;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/arm_book_lib.h	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,176 @@
+/* Copyright 2020, Eric Pernia, Pablo Gomez and Ariel Lutemberg.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _ARM_BOOK_LIBRARY_H_
+#define _ARM_BOOK_LIBRARY_H_
+
+/*==================[inclusions]=============================================*/
+
+#include <cstdint>
+#include <mbed.h>
+
+/*==================[c++]====================================================*/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*==================[macros]=================================================*/
+
+// Functional states
+#ifndef OFF
+#define OFF    0
+#endif
+#ifndef ON
+#define ON     (!OFF)
+#endif
+
+// Electrical states
+#ifndef LOW
+#define LOW    0
+#endif
+#ifndef HIGH
+#define HIGH   (!LOW)
+#endif
+
+// Logical states
+
+#ifndef FALSE
+#define FALSE  0
+#endif
+#ifndef TRUE
+#define TRUE   (!FALSE)
+#endif
+
+#ifndef false
+#define false  0
+#endif
+#ifndef true
+#define true   (!false)
+#endif
+
+//  __I Defines 'read only' permissions: volatile const
+//  __O Defines 'write only' permissions: volatile
+// __IO Defines 'read / write' permissions: volatile
+
+#define HW_REG_8_R(x)     (*((__I  uint8_t *)(x)))
+#define HW_REG_16_R(x)    (*((__I uint16_t *)(x)))
+#define HW_REG_32_R(x)    (*((__I uint32_t *)(x)))
+
+#define HW_REG_8_W(x)     (*((__O  uint8_t *)(x)))
+#define HW_REG_16_W(x)    (*((__O uint16_t *)(x)))
+#define HW_REG_32_W(x)    (*((__O uint32_t *)(x)))
+
+#define HW_REG_8_RW(x)    (*((__IO  uint8_t *)(x)))
+#define HW_REG_16_RW(x)   (*((__IO uint16_t *)(x)))
+#define HW_REG_32_RW(x)   (*((__IO uint32_t *)(x)))
+
+// Example:
+// #define REG_NAME   (HW_REG_32_RW(0x4544555))
+
+/*==================[Function-like macros]===================================*/
+
+#define delay(ms)      thread_sleep_for( ms )
+
+/*==================[typedef]================================================*/
+
+// ST Zio connector namings
+
+// CN7
+# define D16   PC_6
+# define D17   PB_15
+# define D18   PB_13
+# define D19   PB_12
+# define D20   PA_15
+# define D21   PC_7
+# define D22   PB_5
+# define D23   PB_3
+# define D24   PA_4
+# define D25   PB_4
+
+// CN10
+# define D26   PB_6
+# define D27   PB_2
+# define D28   PD_13
+# define D29   PD_12
+# define D30   PD_11
+# define D31   PE_2
+# define D32   PA_0
+# define D33   PB_0
+# define D34   PE_0
+# define D35   PB_11
+# define D36   PB_10
+# define D37   PE_15
+# define D38   PE_14
+# define D39   PE_12
+# define D40   PE_10
+# define D41   PE_7
+# define D42   PE_8
+
+// CN8
+# define D43   PC_8
+# define D44   PC_9
+# define D45   PC_10
+# define D46   PC_11
+# define D47   PC_12
+# define D48   PD_1
+# define D49   PG_2
+# define D50   PG_3
+
+// CN9
+# define D51   PD_7
+# define D52   PD_6
+# define D53   PD_5
+# define D54   PD_4
+# define D55   PD_3
+# define D56   PE_2
+# define D57   PE_4
+# define D58   PE_5
+# define D59   PE_6
+# define D60   PE_3
+# define D61   PF_8
+# define D62   PF_7
+# define D63   PF_9
+# define D64   PG_1
+# define D65   PG_0
+# define D66   PD_1
+# define D67   PD_0
+# define D68   PF_0
+# define D69   PF_1
+# define D70   PF_2
+# define D71   PA_7
+# define D72   NC
+
+/*==================[c++]====================================================*/
+#ifdef __cplusplus
+}
+#endif
+
+/*==================[end of file]============================================*/
+#endif // _ARM_BOOK_LIBRARY_H_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/date_and_time/date_and_time.cpp	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,48 @@
+//=====[Libraries]=============================================================
+
+#include "mbed.h"
+
+#include "date_and_time.h"
+
+//=====[Declaration of private defines]======================================
+
+//=====[Declaration of private data types]=====================================
+
+//=====[Declaration and initialization of public global objects]===============
+
+//=====[Declaration of external public global variables]=======================
+
+//=====[Declaration and initialization of public global variables]=============
+
+//=====[Declaration and initialization of private global variables]============
+
+//=====[Declarations (prototypes) of private functions]========================
+
+//=====[Implementations of public functions]===================================
+
+char* dateAndTimeRead()
+{
+    time_t epochSeconds;
+    epochSeconds = time(NULL);
+    return ctime(&epochSeconds);    
+}
+
+void dateAndTimeWrite( int year, int month, int day, 
+                       int hour, int minute, int second )
+{
+    struct tm rtcTime;
+
+    rtcTime.tm_year = year - 1900;
+    rtcTime.tm_mon  = month - 1;
+    rtcTime.tm_mday = day;
+    rtcTime.tm_hour = hour;
+    rtcTime.tm_min  = minute;
+    rtcTime.tm_sec  = second;
+
+    rtcTime.tm_isdst = -1;
+
+    set_time( mktime( &rtcTime ) );
+}
+
+//=====[Implementations of private functions]==================================
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/date_and_time/date_and_time.h	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,21 @@
+//=====[#include guards - begin]===============================================
+
+#ifndef _DATE_AND_TIME_H_
+#define _DATE_AND_TIME_H_
+
+//=====[Libraries]=============================================================
+
+//=====[Declaration of public defines]=======================================
+
+//=====[Declaration of public data types]======================================
+
+//=====[Declarations (prototypes) of public functions]=========================
+
+char* dateAndTimeRead();
+
+void dateAndTimeWrite( int year, int month, int day, 
+                       int hour, int minute, int second );
+
+//=====[#include guards - end]=================================================
+
+#endif // _DATE_AND_TIME_H_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/display/display.cpp	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,357 @@
+//=====[Libraries]=============================================================
+
+#include "mbed.h"
+#include "arm_book_lib.h"
+#include "display.h"
+
+//=====[Declaration of private defines]========================================
+
+#define DISPLAY_IR_CLEAR_DISPLAY   0b00000001
+#define DISPLAY_IR_ENTRY_MODE_SET  0b00000100
+#define DISPLAY_IR_DISPLAY_CONTROL 0b00001000
+#define DISPLAY_IR_FUNCTION_SET    0b00100000
+#define DISPLAY_IR_SET_DDRAM_ADDR  0b10000000
+
+#define DISPLAY_IR_ENTRY_MODE_SET_INCREMENT 0b00000010
+#define DISPLAY_IR_ENTRY_MODE_SET_DECREMENT 0b00000000
+#define DISPLAY_IR_ENTRY_MODE_SET_SHIFT     0b00000001
+#define DISPLAY_IR_ENTRY_MODE_SET_NO_SHIFT  0b00000000
+
+#define DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_ON  0b00000100
+#define DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_OFF 0b00000000
+#define DISPLAY_IR_DISPLAY_CONTROL_CURSOR_ON   0b00000010
+#define DISPLAY_IR_DISPLAY_CONTROL_CURSOR_OFF  0b00000000
+#define DISPLAY_IR_DISPLAY_CONTROL_BLINK_ON    0b00000001
+#define DISPLAY_IR_DISPLAY_CONTROL_BLINK_OFF   0b00000000
+
+#define DISPLAY_IR_FUNCTION_SET_8BITS    0b00010000
+#define DISPLAY_IR_FUNCTION_SET_4BITS    0b00000000
+#define DISPLAY_IR_FUNCTION_SET_2LINES   0b00001000
+#define DISPLAY_IR_FUNCTION_SET_1LINE    0b00000000
+#define DISPLAY_IR_FUNCTION_SET_5x10DOTS 0b00000100
+#define DISPLAY_IR_FUNCTION_SET_5x8DOTS  0b00000000
+
+#define DISPLAY_20x4_LINE1_FIRST_CHARACTER_ADDRESS 0
+#define DISPLAY_20x4_LINE2_FIRST_CHARACTER_ADDRESS 64
+#define DISPLAY_20x4_LINE3_FIRST_CHARACTER_ADDRESS 20
+#define DISPLAY_20x4_LINE4_FIRST_CHARACTER_ADDRESS 84
+
+#define DISPLAY_RS_INSTRUCTION 0
+#define DISPLAY_RS_DATA        1
+
+#define DISPLAY_RW_WRITE 0
+#define DISPLAY_RW_READ  1
+
+#define DISPLAY_PIN_RS  4
+#define DISPLAY_PIN_RW  5
+#define DISPLAY_PIN_EN  6
+#define DISPLAY_PIN_D0  7  
+#define DISPLAY_PIN_D1  8  
+#define DISPLAY_PIN_D2  9  
+#define DISPLAY_PIN_D3 10
+#define DISPLAY_PIN_D4 11
+#define DISPLAY_PIN_D5 12 
+#define DISPLAY_PIN_D6 13 
+#define DISPLAY_PIN_D7 14 
+
+#define DISPLAY_PIN_A_PCF8574 3
+
+#define I2C1_SDA PB_9
+#define I2C1_SCL PB_8
+
+#define PCF8574_I2C_BUS_8BIT_WRITE_ADDRESS 78
+
+//=====[Declaration of private data types]=====================================
+
+typedef struct{
+    int address;
+    char data;
+    bool displayPin_RS;
+    bool displayPin_RW; 
+    bool displayPin_EN;
+    bool displayPin_A;
+    bool displayPin_D4;
+    bool displayPin_D5;
+    bool displayPin_D6;
+    bool displayPin_D7;
+} pcf8574_t;
+
+//=====[Declaration and initialization of public global objects]===============
+
+DigitalOut displayD0( D0 );
+DigitalOut displayD1( D1 );
+DigitalOut displayD2( D2 );
+DigitalOut displayD3( D3 );
+DigitalOut displayD4( D4 );
+DigitalOut displayD5( D5 );
+DigitalOut displayD6( D6 );
+DigitalOut displayD7( D7 );
+DigitalOut displayRS( D8 );
+DigitalOut displayEN( D9 );
+
+I2C I2C_PCF8574( I2C1_SDA, I2C1_SCL ); 
+
+//=====[Declaration of external public global variables]=======================
+
+//=====[Declaration and initialization of public global variables]=============
+
+//=====[Declaration and initialization of private global variables]============
+
+static display_t display;
+static pcf8574_t pcf8574;
+static bool initial8BitCommunicationIsCompleted;
+
+//=====[Declarations (prototypes) of private functions]========================
+
+static void displayPinWrite( uint8_t pinName, int value );
+static void displayDataBusWrite( uint8_t dataByte );
+static void displayCodeWrite( bool type, uint8_t dataBus );
+
+//=====[Implementations of public functions]===================================
+
+void displayInit( displayConnection_t connection )
+{
+    display.connection = connection;
+	
+	if( display.connection == DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER) {
+		pcf8574.address = PCF8574_I2C_BUS_8BIT_WRITE_ADDRESS;
+		pcf8574.data = 0b00000000;
+		I2C_PCF8574.frequency(100000);
+        displayPinWrite( DISPLAY_PIN_A_PCF8574,  ON );
+    } 
+	
+	initial8BitCommunicationIsCompleted = FALSE;    
+
+    delay( 50 );
+    
+    displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                      DISPLAY_IR_FUNCTION_SET | 
+                      DISPLAY_IR_FUNCTION_SET_8BITS );
+    delay( 5 );
+            
+    displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                      DISPLAY_IR_FUNCTION_SET | 
+                      DISPLAY_IR_FUNCTION_SET_8BITS );
+    delay( 1 ); 
+
+    displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                      DISPLAY_IR_FUNCTION_SET | 
+                      DISPLAY_IR_FUNCTION_SET_8BITS );
+    delay( 1 );  
+
+    switch( display.connection ) {
+        case DISPLAY_CONNECTION_GPIO_8BITS:
+            displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                              DISPLAY_IR_FUNCTION_SET | 
+                              DISPLAY_IR_FUNCTION_SET_8BITS | 
+                              DISPLAY_IR_FUNCTION_SET_2LINES |
+                              DISPLAY_IR_FUNCTION_SET_5x8DOTS );
+            delay( 1 );         
+        break;
+        
+        case DISPLAY_CONNECTION_GPIO_4BITS:
+        case DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER:
+            displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                              DISPLAY_IR_FUNCTION_SET | 
+                              DISPLAY_IR_FUNCTION_SET_4BITS );
+            delay( 1 );  
+
+            initial8BitCommunicationIsCompleted = TRUE;  
+
+            displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                              DISPLAY_IR_FUNCTION_SET | 
+                              DISPLAY_IR_FUNCTION_SET_4BITS | 
+                              DISPLAY_IR_FUNCTION_SET_2LINES |
+                              DISPLAY_IR_FUNCTION_SET_5x8DOTS );
+            delay( 1 );                                      
+        break;
+    }
+
+    displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                      DISPLAY_IR_DISPLAY_CONTROL |
+                      DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_OFF |      
+                      DISPLAY_IR_DISPLAY_CONTROL_CURSOR_OFF |       
+                      DISPLAY_IR_DISPLAY_CONTROL_BLINK_OFF );       
+    delay( 1 );          
+
+    displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                      DISPLAY_IR_CLEAR_DISPLAY );       
+    delay( 1 ); 
+
+	displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+	                  DISPLAY_IR_ENTRY_MODE_SET |
+	                  DISPLAY_IR_ENTRY_MODE_SET_INCREMENT |       
+	                  DISPLAY_IR_ENTRY_MODE_SET_NO_SHIFT );                  
+    delay( 1 );           
+
+    displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                      DISPLAY_IR_DISPLAY_CONTROL |
+	                  DISPLAY_IR_DISPLAY_CONTROL_DISPLAY_ON |      
+	                  DISPLAY_IR_DISPLAY_CONTROL_CURSOR_OFF |    
+	                  DISPLAY_IR_DISPLAY_CONTROL_BLINK_OFF );    
+    delay( 1 );  
+}
+
+void displayCharPositionWrite( uint8_t charPositionX, uint8_t charPositionY )
+{    
+    switch( charPositionY ) {
+        case 0:
+            displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                              DISPLAY_IR_SET_DDRAM_ADDR |
+                              ( DISPLAY_20x4_LINE1_FIRST_CHARACTER_ADDRESS +
+                                charPositionX ) );
+            delay( 1 );         
+        break;
+       
+        case 1:
+            displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                              DISPLAY_IR_SET_DDRAM_ADDR |
+                              ( DISPLAY_20x4_LINE2_FIRST_CHARACTER_ADDRESS +
+                                charPositionX ) );
+            delay( 1 );         
+        break;
+       
+        case 2:
+            displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                              DISPLAY_IR_SET_DDRAM_ADDR |
+                              ( DISPLAY_20x4_LINE3_FIRST_CHARACTER_ADDRESS +
+                                charPositionX ) );
+            delay( 1 );         
+        break;
+
+        case 3:
+            displayCodeWrite( DISPLAY_RS_INSTRUCTION, 
+                              DISPLAY_IR_SET_DDRAM_ADDR |
+                              ( DISPLAY_20x4_LINE4_FIRST_CHARACTER_ADDRESS +
+                                charPositionX ) );
+            delay( 1 );         
+        break;
+    }
+}
+
+void displayStringWrite( char const * str )
+{
+    while (*str) {
+        displayCodeWrite(DISPLAY_RS_DATA, *str++);
+    }
+}
+
+//=====[Implementations of private functions]==================================
+
+static void displayCodeWrite( bool type, uint8_t dataBus )
+{
+    if ( type == DISPLAY_RS_INSTRUCTION )
+        displayPinWrite( DISPLAY_PIN_RS, DISPLAY_RS_INSTRUCTION);
+        else
+        displayPinWrite( DISPLAY_PIN_RS, DISPLAY_RS_DATA);
+    displayPinWrite( DISPLAY_PIN_RW, DISPLAY_RW_WRITE );
+    displayDataBusWrite( dataBus );
+}
+
+static void displayPinWrite( uint8_t pinName, int value )
+{
+    switch( display.connection ) {
+        case DISPLAY_CONNECTION_GPIO_8BITS:
+            switch( pinName ) {
+                case DISPLAY_PIN_D0: displayD0 = value;   break;
+                case DISPLAY_PIN_D1: displayD1 = value;   break;
+                case DISPLAY_PIN_D2: displayD2 = value;   break;
+                case DISPLAY_PIN_D3: displayD3 = value;   break;
+                case DISPLAY_PIN_D4: displayD4 = value;   break;
+                case DISPLAY_PIN_D5: displayD5 = value;   break;
+                case DISPLAY_PIN_D6: displayD6 = value;   break;
+                case DISPLAY_PIN_D7: displayD7 = value;   break;
+                case DISPLAY_PIN_RS: displayRS = value;   break;
+                case DISPLAY_PIN_EN: displayEN = value;   break;
+                case DISPLAY_PIN_RW: break; 
+                default: break;
+            }
+        case DISPLAY_CONNECTION_GPIO_4BITS:
+            switch( pinName ) {
+                case DISPLAY_PIN_D4: displayD4 = value;   break;
+                case DISPLAY_PIN_D5: displayD5 = value;   break;
+                case DISPLAY_PIN_D6: displayD6 = value;   break;
+                case DISPLAY_PIN_D7: displayD7 = value;   break;
+                case DISPLAY_PIN_RS: displayRS = value;   break;
+                case DISPLAY_PIN_EN: displayEN = value;   break;
+                case DISPLAY_PIN_RW: break; 
+                default: break;
+            }
+        break;
+
+        case DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER:
+           if ( value ) {
+                switch( pinName ) {
+                    case DISPLAY_PIN_D4: pcf8574.displayPin_D4 = ON; break;
+                    case DISPLAY_PIN_D5: pcf8574.displayPin_D5 = ON; break;
+                    case DISPLAY_PIN_D6: pcf8574.displayPin_D6 = ON; break;
+                    case DISPLAY_PIN_D7: pcf8574.displayPin_D7 = ON; break;
+                    case DISPLAY_PIN_RS: pcf8574.displayPin_RS = ON; break;
+                    case DISPLAY_PIN_EN: pcf8574.displayPin_EN = ON; break;
+                    case DISPLAY_PIN_RW: pcf8574.displayPin_RW = ON; break;
+                    case DISPLAY_PIN_A_PCF8574: pcf8574.displayPin_A = ON; break;
+                    default: break;
+                }
+            }
+            else {
+                switch( pinName ) {
+                    case DISPLAY_PIN_D4: pcf8574.displayPin_D4 = OFF; break;
+                    case DISPLAY_PIN_D5: pcf8574.displayPin_D5 = OFF; break;
+                    case DISPLAY_PIN_D6: pcf8574.displayPin_D6 = OFF; break;
+                    case DISPLAY_PIN_D7: pcf8574.displayPin_D7 = OFF; break;
+                    case DISPLAY_PIN_RS: pcf8574.displayPin_RS = OFF; break;
+                    case DISPLAY_PIN_EN: pcf8574.displayPin_EN = OFF; break;
+                    case DISPLAY_PIN_RW: pcf8574.displayPin_RW = OFF; break;
+                    case DISPLAY_PIN_A_PCF8574: pcf8574.displayPin_A = OFF; break;
+                    default: break;
+                }
+            }     
+            pcf8574.data = 0b00000000;
+            if ( pcf8574.displayPin_RS ) pcf8574.data |= 0b00000001; 
+            if ( pcf8574.displayPin_RW ) pcf8574.data |= 0b00000010; 
+            if ( pcf8574.displayPin_EN ) pcf8574.data |= 0b00000100; 
+            if ( pcf8574.displayPin_A  ) pcf8574.data |= 0b00001000; 
+            if ( pcf8574.displayPin_D4 ) pcf8574.data |= 0b00010000; 
+            if ( pcf8574.displayPin_D5 ) pcf8574.data |= 0b00100000; 
+            if ( pcf8574.displayPin_D6 ) pcf8574.data |= 0b01000000; 
+            if ( pcf8574.displayPin_D7 ) pcf8574.data |= 0b10000000;                                     
+            I2C_PCF8574.write( pcf8574.address, &pcf8574.data, 1);    
+        break; 
+    }
+}
+
+static void displayDataBusWrite( uint8_t dataBus )
+{
+    displayPinWrite( DISPLAY_PIN_EN, OFF );
+    displayPinWrite( DISPLAY_PIN_D7, dataBus & 0b10000000 );
+    displayPinWrite( DISPLAY_PIN_D6, dataBus & 0b01000000 );
+    displayPinWrite( DISPLAY_PIN_D5, dataBus & 0b00100000 );
+    displayPinWrite( DISPLAY_PIN_D4, dataBus & 0b00010000 );
+    switch( display.connection ) {
+        case DISPLAY_CONNECTION_GPIO_8BITS:
+            displayPinWrite( DISPLAY_PIN_D3, dataBus & 0b00001000 );
+            displayPinWrite( DISPLAY_PIN_D2, dataBus & 0b00000100 );  
+            displayPinWrite( DISPLAY_PIN_D1, dataBus & 0b00000010 );      
+            displayPinWrite( DISPLAY_PIN_D0, dataBus & 0b00000001 );
+        break; 
+              
+        case DISPLAY_CONNECTION_GPIO_4BITS:
+        case DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER:
+            if ( initial8BitCommunicationIsCompleted == TRUE) {
+            	displayPinWrite( DISPLAY_PIN_EN, ON );         
+            	delay( 1 );
+            	displayPinWrite( DISPLAY_PIN_EN, OFF );              
+            	delay( 1 );        
+                displayPinWrite( DISPLAY_PIN_D7, dataBus & 0b00001000 );
+                displayPinWrite( DISPLAY_PIN_D6, dataBus & 0b00000100 );  
+                displayPinWrite( DISPLAY_PIN_D5, dataBus & 0b00000010 );      
+                displayPinWrite( DISPLAY_PIN_D4, dataBus & 0b00000001 );                
+            }
+        break;
+    
+    }
+    displayPinWrite( DISPLAY_PIN_EN, ON );              
+    delay( 1 );
+    displayPinWrite( DISPLAY_PIN_EN, OFF );  
+    delay( 1 );                   
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/display/display.h	Fri May 14 17:27:28 2021 +0000
@@ -0,0 +1,34 @@
+//=====[#include guards - begin]===============================================
+
+#ifndef _DISPLAY_H_
+#define _DISPLAY_H_
+
+//=====[Libraries]=============================================================
+
+#include "mbed.h"
+
+//=====[Declaration of public defines]=======================================
+
+//=====[Declaration of public data types]======================================
+
+typedef enum {
+     DISPLAY_CONNECTION_GPIO_4BITS,
+     DISPLAY_CONNECTION_GPIO_8BITS,
+     DISPLAY_CONNECTION_I2C_PCF8574_IO_EXPANDER,
+} displayConnection_t;
+
+typedef struct {
+   displayConnection_t connection;                                                 
+} display_t;
+
+//=====[Declarations (prototypes) of public functions]=========================
+
+void displayInit( displayConnection_t connection );
+ 
+void displayCharPositionWrite( uint8_t charPositionX, uint8_t charPositionY );
+
+void displayStringWrite( char const * str );
+
+//=====[#include guards - end]=================================================
+
+#endif // _DISPLAY_H_
\ No newline at end of file
Binary file resources/official_armmbed_example_badge.png has changed