Personal Test Environment

Dependencies:   LCD_DISCO_F746NG TS_DISCO_F746NG mbed

Files at this revision

API Documentation at this revision

Comitter:
DirtyGray
Date:
Tue Mar 06 18:24:17 2018 +0000
Child:
1:c00262e1ef4c
Commit message:
main.cpp

Changed in this revision

BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
LCD_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
TS_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
TempSense.h Show annotated file Show diff for this revision Revisions of this file
drawMe.h Show annotated file Show diff for this revision Revisions of this file
globals.h 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.lib Show annotated file Show diff for this revision Revisions of this file
pixelRun.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F746NG.lib	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/DirtyGray/code/BSP_DISCO_F746NG/#3f0dba57dd82
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_DISCO_F746NG.lib	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TS_DISCO_F746NG.lib	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/ST/code/TS_DISCO_F746NG/#fe0cf5e2960f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TempSense.h	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,156 @@
+#include "mbed.h"
+
+//---------------------------------------------------------
+//Enter amount of minutes between each log
+int minutesPerLog = 15;
+
+//Enter amount of seconds for the log screen to show
+int logTimer = 20;
+//---------------------------------------------------------
+
+//I2C pins
+I2C i2c(PB_9, PB_8); //SDA, SCL | D14 , D15
+
+int getTemp(void);
+void displayLog(int *);
+void initScreen(void);
+
+LCD_DISCO_F746NG LCDscreen;
+TS_StateTypeDef touchStatus;
+TS_DISCO_F746NG LCDtouchScreen;
+
+/**
+  * @brief  Displays the temperature
+  * @retval None
+  */
+void tempDisplay(void)
+{
+    //If the log is recording every 0 minutes do not show log
+    if (minutesPerLog == 0) {
+        return;
+    }
+
+    initScreen();
+    i2c.frequency(100000);
+
+    int counter = 0;
+    unsigned short StringX = 0;
+    unsigned short StringY = 250;
+    unsigned char helpDisplay[100] = {"Hold screen for Log"};
+    unsigned char tempDisplay[100];
+    int tempLog[10] = {0};
+
+    //Reset screen after log display
+back:
+    LCDscreen.Clear(LCD_COLOR_BLUE);
+    LCDscreen.DisplayStringAt(0, 0, helpDisplay, LEFT_MODE);
+
+    //Main loop
+    while(1) {
+        counter++;
+        //Grabs temp and puts it into display portion of log [0], also adds one
+        //second delay
+        int temp = getTemp();
+        tempLog[0] = temp;
+
+        //Checks to see if time has been met for a log update
+        if (counter >= (minutesPerLog * 60)) {
+            for (int i = 9; i > 0; i--) {
+                tempLog[i] = tempLog[i - 1];
+            }
+            counter = 0;
+        }
+
+        //Displays the current temperature
+        if (temp < 100) {
+            sprintf((char*)tempDisplay, "Current Temperature = %dF", temp);
+        } else if (temp >= 100) {
+            sprintf((char*)tempDisplay, "Current Temperature =%dF", temp);
+        }
+        LCDscreen.DisplayStringAt(StringX, StringY, tempDisplay, LEFT_MODE);
+
+        //Checks for touch to display log
+        LCDtouchScreen.GetState(&touchStatus);
+        if (touchStatus.touchDetected) {
+            displayLog(tempLog);
+            counter = counter + logTimer;
+            goto back;
+        }
+    }
+}
+
+/**
+  * @brief  Retrieves temperature from chip
+  * @retval Temperature
+  */
+int getTemp(void)
+{
+    char tempData[2];
+    char getTemp[1] = {0xAA};
+    char stopConvert[1] = {0x22};
+    char startConvert[1] = {0xEE};
+    int temp;
+
+    //Grabs the temperature from the DS1621, converts to F and returns value
+    //Convert tells the DS1621 to update its temperature reading
+    //Read and Write have different addresses because I2C communication address
+    //uses a 1 for write and a 0 for read at end of binary address
+    i2c.write(145, startConvert, 1, false);
+    wait(1);
+    i2c.write(145, stopConvert, 1, false);
+    i2c.write(145, getTemp, 1, false);
+    i2c.read(144, tempData, 1);
+    temp = (tempData[0] * 1.8) + 32;
+    return (temp);
+}
+
+/**
+  * @brief  Displays the temperature log
+  * @param  tempLog[10]: Array of temperature logs
+  * @retval None
+  */
+void displayLog(int tempLog[10])
+{
+    LCDscreen.SetBackColor(LCD_COLOR_BLUE);
+    LCDscreen.SetTextColor(LCD_COLOR_WHITE);
+
+    unsigned char logDisplay[500];
+    unsigned char helpDisplay2[100];
+
+    sprintf((char*)helpDisplay2, "Log is updated every %d minutes", minutesPerLog);
+
+    //Displays 10 logs, the first log is the current temperature. If the time
+    //of one log is divisible by 60 it will note that log as being one hour ago
+    //Each log is added to the master string "logDisplay"
+    LCDscreen.Clear(LCD_COLOR_BLUE);
+    sprintf((char*)logDisplay, "Log:");
+    LCDscreen.DisplayStringAt(0, 0, logDisplay, LEFT_MODE);
+    for (int i = 0; i < 10; i++) {
+        if (i == 0) {
+            sprintf((char*)logDisplay, "%dF - Current Temperature", tempLog[i]);
+        } else if (i == (60 / minutesPerLog)) {
+            sprintf((char*)logDisplay, "%d: %dF - One Hour Ago", i, tempLog[i]);
+        } else {
+            sprintf((char*)logDisplay, "%d: %dF", i, tempLog[i]);
+        }
+        LCDscreen.DisplayStringAt(0, (i + 1) * 20, logDisplay, LEFT_MODE);
+    }
+    LCDscreen.SetFont(&Font20);
+    LCDscreen.DisplayStringAt(0, 240, helpDisplay2, LEFT_MODE);
+    LCDscreen.SetFont(&Font24);
+
+    wait(logTimer);
+}
+
+/**
+  * @brief  Initializes display
+  * @retval None
+  */
+void initScreen(void)
+{
+    LCDscreen.Clear(LCD_COLOR_WHITE);
+    LCDscreen.SetBackColor(LCD_COLOR_BLUE);
+    LCDscreen.SetTextColor(LCD_COLOR_WHITE);
+    LCDscreen.SetFont(&Font24);
+    LCDscreen.Clear(LCD_COLOR_BLUE);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/drawMe.h	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,95 @@
+void drawGame()
+{
+//INITIATE LCD SCREEN
+    LCD_DISCO_F746NG LCDscreen;
+    TS_DISCO_F746NG LCDtouchScreen;
+    TS_StateTypeDef touchStatus;
+    LCDtouchScreen.Init(480, 272);
+
+//DECLARE VARIABLES
+    int circleDiameter = 5;
+    int counter = 0;
+    int screenColor = 1;
+//unsigned short xPrint;
+//unsigned short yPrint;
+
+//SET LCD SCREEN
+    LCDscreen.Clear(LCD_COLOR_BLACK);
+    LCDscreen.SetBackColor(LCD_COLOR_BLACK);
+    wait(1);
+
+    while(1) {
+//CLEAR THE SCREEN AND DRAW THE CIRCLES
+        LCDscreen.Clear(LCD_COLOR_BLACK);
+        LCDscreen.SetTextColor(LCD_COLOR_BLUE);
+        LCDscreen.FillCircle(20, 20, 20);
+        LCDscreen.SetTextColor(LCD_COLOR_RED);
+        LCDscreen.FillCircle(20, 60, 20);
+        LCDscreen.SetTextColor(LCD_COLOR_YELLOW);
+        LCDscreen.FillCircle(20, 100, 20);
+        LCDscreen.SetTextColor(LCD_COLOR_GREEN);
+        LCDscreen.FillCircle(20, 140, 20);
+        LCDscreen.SetTextColor(LCD_COLOR_WHITE);
+        LCDscreen.FillCircle(20, 180, 20);
+        LCDscreen.SetTextColor(LCD_COLOR_SADDLE_BROWN);
+        LCDscreen.FillCircle(20, 220, 20);
+
+//WHILE COUNTER IS INCRIMENTING, CHECK FOR INPUT AND DRAW CIRCLE WHERE TOUCH IS
+        while(counter < 10000) {
+            switch (screenColor) {
+                case 1:
+                    LCDscreen.SetTextColor(LCD_COLOR_BLUE);
+                    break;
+                case 2:
+                    LCDscreen.SetTextColor(LCD_COLOR_RED);
+                    break;
+                case 3:
+                    LCDscreen.SetTextColor(LCD_COLOR_YELLOW);
+                    break;
+                case 4:
+                    LCDscreen.SetTextColor(LCD_COLOR_GREEN);
+                    break;
+                case 5:
+                    LCDscreen.SetTextColor(LCD_COLOR_WHITE);
+                    break;
+                case 6:
+                    LCDscreen.SetTextColor(LCD_COLOR_SADDLE_BROWN);
+                    break;
+            }
+
+            LCDtouchScreen.GetState(&touchStatus);
+            if (touchStatus.touchDetected) {
+                if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] <= 40))
+                    screenColor = 1;
+                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 40) && (touchStatus.touchY[0] <= 80))
+                    screenColor = 2;
+                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 80) && (touchStatus.touchY[0] <= 120))
+                    screenColor = 3;
+                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 120) && (touchStatus.touchY[0] <= 160))
+                    screenColor = 4;
+                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 160) && (touchStatus.touchY[0] <= 200))
+                    screenColor = 5;
+                else if ((touchStatus.touchX[0] <= 40) && (touchStatus.touchY[0] >= 200) && (touchStatus.touchY[0] <= 240))
+                    screenColor = 6;
+                if (touchStatus.touchY[0] < circleDiameter)
+                    counter = 0;
+                else if (touchStatus.touchX[0] > (480 - circleDiameter))
+                    counter = 0;
+                else if (touchStatus.touchX[0] < circleDiameter)
+                    counter = 0;
+                else if (touchStatus.touchY[0] > (272 - circleDiameter))
+                    counter = 0;
+                else {
+                    LCDscreen.FillCircle(touchStatus.touchX[0], touchStatus.touchY[0], circleDiameter);
+                    counter = 0;
+                    // xPrint = touchStatus.touchX[0];
+                    // yPrint = touchStatus.touchY[0];
+                    // printf("%hu %hu", xPrint, yPrint);
+                }
+            } else {
+                counter++;
+            }
+        }
+        counter = 0;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/globals.h	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,7 @@
+#ifndef GLOBALS_H
+#define GLOBALS_H
+
+extern LCD_DISCO_F746NG LCDscreen;
+extern TS_DISCO_F746NG LCDtouchScreen;
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,95 @@
+#include "mbed.h"
+#include "TS_DISCO_F746NG.h"
+#include "LCD_DISCO_F746NG.h"
+#include "globals.h"
+
+#include "drawMe.h"
+#include "pixelRun.h"
+#include "TempSense.h"
+
+void showButton(uint32_t, uint32_t, int, uint8_t *);
+
+uint16_t butHeight = 80;
+uint16_t butWidth = 80;
+
+//LCD_DISCO_F746NG LCDscreen;
+//TS_DISCO_F746NG LCDtouchScreen;
+
+int main()
+{
+//init LCD screen
+TS_StateTypeDef touchStatus;
+LCDtouchScreen.Init(LCDscreen.GetXSize(), LCDscreen.GetYSize());
+
+    //set button text
+    uint8_t but1Text[30] = " Draw Game";
+    uint8_t but2Text[30] = " Pixel Run";
+    uint8_t but3Text[30] = "Temperature";
+
+    //set background to black
+    LCDscreen.Clear(LCD_COLOR_BLACK);
+
+    //draw buttons
+    showButton(LCD_COLOR_BLUE, LCD_COLOR_WHITE, 1, but1Text);           //draw
+    showButton(LCD_COLOR_GREEN, LCD_COLOR_WHITE, 2, but2Text);          //pixel
+    showButton(LCD_COLOR_YELLOW, LCD_COLOR_WHITE, 3, but3Text);         //temperature
+
+    //loop that checks for button presses
+    while(1) {
+        LCDtouchScreen.GetState(&touchStatus);
+        if (touchStatus.touchDetected) {
+            if ((touchStatus.touchX[0] <= 80)  && (touchStatus.touchY[0] <= 80)) {
+                drawGame();
+            } else if ((touchStatus.touchX[0] <= 80) && (touchStatus.touchY[0] <= 160)) {
+                pixelScan();
+            } else if ((touchStatus.touchX[0] <= 80) && (touchStatus.touchY[0] <= 240)){
+               tempDisplay();
+            }
+        }
+    }
+}
+
+void showButton(uint32_t backColor, uint32_t textColor, int position, uint8_t *text)
+{
+    LCDscreen.SetBackColor(backColor);
+    LCDscreen.SetTextColor(backColor);
+    LCDscreen.SetFont(&Font12);
+
+    if (position == 1) {
+        LCDscreen.FillRect(0, 0, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(0, 40, text, LEFT_MODE);
+    } else if (position == 2) {
+        LCDscreen.FillRect(0, 80, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(0, 120, text, LEFT_MODE);
+    } else if (position == 3) {
+        LCDscreen.FillRect(0, 160, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(0, 200, text, LEFT_MODE);
+    } else if (position == 4) {
+        LCDscreen.FillRect(80, 0, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(80, 40, text, LEFT_MODE);
+    } else if (position == 5) {
+        LCDscreen.FillRect(80, 80, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(80, 120, text, LEFT_MODE);
+    } else if (position == 6) {
+        LCDscreen.FillRect(80, 160, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(80, 200, text, LEFT_MODE);
+    } else if (position == 7) {
+        LCDscreen.FillRect(160, 0, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(160, 40, text, LEFT_MODE);
+    } else if (position == 8) {
+        LCDscreen.FillRect(160, 80, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(160, 120, text, LEFT_MODE);
+    } else if (position == 9) {
+        LCDscreen.FillRect(160, 160, butWidth, butHeight);
+        LCDscreen.SetTextColor(textColor);
+        LCDscreen.DisplayStringAt(160, 200, text, LEFT_MODE);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-dev/#a46dc6708fb5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pixelRun.h	Tue Mar 06 18:24:17 2018 +0000
@@ -0,0 +1,39 @@
+void pixelScan(void)
+{
+
+    LCD_DISCO_F746NG LCDscreen;
+
+    uint8_t currentCoordinates[30];
+    uint16_t StringX = 0;
+    uint16_t StringY = 250;
+    uint16_t pixX = 0;
+    uint16_t pixY = 0;
+    LCDscreen.Clear(LCD_COLOR_WHITE);
+    LCDscreen.SetBackColor(LCD_COLOR_WHITE);
+    LCDscreen.SetTextColor(LCD_COLOR_BLUE);
+    wait(1);
+    LCDscreen.Clear(LCD_COLOR_BLUE);
+
+    while(1) {
+        if (pixX > 99) {
+            sprintf((char*)currentCoordinates, "X:%d Y:%d", pixX, pixY);
+        } else if (pixX > 9) {
+            sprintf((char*)currentCoordinates, "X: %d Y:%d", pixX, pixY);
+        } else {
+            sprintf((char*)currentCoordinates, "X:  %d Y:%d", pixX, pixY);
+        }
+        LCDscreen.DrawPixel(pixX, pixY, LCD_COLOR_GREEN);
+        LCDscreen.DisplayStringAt(StringX, StringY, currentCoordinates, LEFT_MODE);
+        pixX++;
+        if (pixX == 481) {
+            pixX = 0;
+            pixY++;
+        }
+        if (pixY == 272) {
+            LCDscreen.Clear(LCD_COLOR_BLUE);
+            pixX = 0;
+            pixY = 0;
+        }
+        wait(0.01);
+    }
+}