motor dc driver with lcd nextion nx8048t050_011

Dependencies:   mbed QEI_hw NVIC_set_all_priorities SoftPWM

https://os.mbed.com/media/uploads/exarkun/wp_20180730_002.jpg https://os.mbed.com/media/uploads/exarkun/wp_20180823_003.jpg https://os.mbed.com/media/uploads/exarkun/wp_20180730_007.jpg https://os.mbed.com/media/uploads/exarkun/wp_20171120_004.jpg

https://os.mbed.com/media/uploads/exarkun/wp_20191002_006.jpg https://os.mbed.com/media/uploads/exarkun/wp_20191002_003.jpg https://os.mbed.com/media/uploads/exarkun/wp_20191002_004.jpg https://os.mbed.com/media/uploads/exarkun/wp_20191002_005.jpg https://os.mbed.com/media/uploads/exarkun/wp_20190322_003.jpg https://os.mbed.com/media/uploads/exarkun/wp_20180925_002.jpg https://os.mbed.com/media/uploads/exarkun/wp_20181010_006.jpg https://os.mbed.com/media/uploads/exarkun/wp_20181220_001.jpg

https://os.mbed.com/media/uploads/exarkun/wp_20181220_002.jpg

Committer:
exarkun
Date:
Thu Jul 09 08:30:19 2020 +0000
Revision:
2:e72b06f87c8b
Parent:
1:2fe82be93e80
driver motor with lcd control nextion nx8048t050

Who changed what in which revision?

UserRevisionLine numberNew contents of line
exarkun 1:2fe82be93e80 1 /* NextionLCD Library v1.0
exarkun 1:2fe82be93e80 2 * Copyright (c) 2018 Grant Phillips
exarkun 1:2fe82be93e80 3 * grant.phillips@mandela.ac.za
exarkun 1:2fe82be93e80 4 *
exarkun 1:2fe82be93e80 5 *
exarkun 1:2fe82be93e80 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
exarkun 1:2fe82be93e80 7 * of this software and associated documentation files (the "Software"), to deal
exarkun 1:2fe82be93e80 8 * in the Software without restriction, including without limitation the rights
exarkun 1:2fe82be93e80 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
exarkun 1:2fe82be93e80 10 * copies of the Software, and to permit persons to whom the Software is
exarkun 1:2fe82be93e80 11 * furnished to do so, subject to the following conditions:
exarkun 1:2fe82be93e80 12 *
exarkun 1:2fe82be93e80 13 * The above copyright notice and this permission notice shall be included in
exarkun 1:2fe82be93e80 14 * all copies or substantial portions of the Software.
exarkun 1:2fe82be93e80 15 *
exarkun 1:2fe82be93e80 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
exarkun 1:2fe82be93e80 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
exarkun 1:2fe82be93e80 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
exarkun 1:2fe82be93e80 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
exarkun 1:2fe82be93e80 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
exarkun 1:2fe82be93e80 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
exarkun 1:2fe82be93e80 22 * THE SOFTWARE.
exarkun 1:2fe82be93e80 23 */
exarkun 1:2fe82be93e80 24
exarkun 1:2fe82be93e80 25 #ifndef NEXTIONLCD_H
exarkun 1:2fe82be93e80 26 #define NEXTIONLCD_H
exarkun 1:2fe82be93e80 27
exarkun 1:2fe82be93e80 28 #include "mbed.h"
exarkun 1:2fe82be93e80 29
exarkun 1:2fe82be93e80 30 #define BLACK 0
exarkun 1:2fe82be93e80 31 #define BLUE 31
exarkun 1:2fe82be93e80 32 #define BROWN 48192
exarkun 1:2fe82be93e80 33 #define GREEN 2016
exarkun 1:2fe82be93e80 34 #define YELLOW 65504
exarkun 1:2fe82be93e80 35 #define RED 63488
exarkun 1:2fe82be93e80 36 #define GRAY 33840
exarkun 1:2fe82be93e80 37 #define WHITE 65535
exarkun 1:2fe82be93e80 38
exarkun 1:2fe82be93e80 39
exarkun 1:2fe82be93e80 40 /** Class library for a Nextion graphics LCD to provide basic graphics and touch functions.
exarkun 1:2fe82be93e80 41 * This library DOES NOT provide the HMI functionality that is included with Nextion LCDs.
exarkun 1:2fe82be93e80 42 *
exarkun 1:2fe82be93e80 43 * Example:
exarkun 1:2fe82be93e80 44 * @code
exarkun 1:2fe82be93e80 45 * #include "mbed.h"
exarkun 1:2fe82be93e80 46 * #include "NextionLCD.h"
exarkun 1:2fe82be93e80 47 *
exarkun 1:2fe82be93e80 48 * NextionLCD lcd(PB_6, PB_7); //Tx, Rx
exarkun 1:2fe82be93e80 49 *
exarkun 1:2fe82be93e80 50 * int main()
exarkun 1:2fe82be93e80 51 * {
exarkun 1:2fe82be93e80 52 * char str[20];
exarkun 1:2fe82be93e80 53 *
exarkun 1:2fe82be93e80 54 * lcd.ClrScr(BLACK); //clear the display and fill it with BLACK pixels
exarkun 1:2fe82be93e80 55 *
exarkun 1:2fe82be93e80 56 * //draw some shapes
exarkun 1:2fe82be93e80 57 * lcd.FillCircle(100,100,50,RED);
exarkun 1:2fe82be93e80 58 * lcd.DrawPixel(100,100,WHITE);
exarkun 1:2fe82be93e80 59 * lcd.DrawRectangle(50,50,100,100,BLUE);
exarkun 1:2fe82be93e80 60 * lcd.DrawLine(50,50,100,150,YELLOW);
exarkun 1:2fe82be93e80 61 *
exarkun 1:2fe82be93e80 62 * while(1)
exarkun 1:2fe82be93e80 63 * {
exarkun 1:2fe82be93e80 64 * if (lcd.Touch()) //test if the lcd was touched
exarkun 1:2fe82be93e80 65 * {
exarkun 1:2fe82be93e80 66 * sprintf(str, "Touched: %d,%d", lcd.TouchX(), lcd.TouchY()); //print to string buffer
exarkun 1:2fe82be93e80 67 * lcd.DrawString(0,0,200,30,0,GREEN,GRAY,0,0,str); //display string on LCD:
exarkun 1:2fe82be93e80 68 * // x,y : 0,0
exarkun 1:2fe82be93e80 69 * // width, height: 200, 300
exarkun 1:2fe82be93e80 70 * // font : 0
exarkun 1:2fe82be93e80 71 * // fontcolor : GREEN
exarkun 1:2fe82be93e80 72 * // backcolor : GRAY
exarkun 1:2fe82be93e80 73 * // x alignment : 0 (left)
exarkun 1:2fe82be93e80 74 * // y alignment : 0 (top)
exarkun 1:2fe82be93e80 75 * }
exarkun 1:2fe82be93e80 76 * else
exarkun 1:2fe82be93e80 77 * {
exarkun 1:2fe82be93e80 78 * lcd.DrawString(0,0,200,30,0,BLACK,BLACK,0,0,""); //blank display area when not touched
exarkun 1:2fe82be93e80 79 * }
exarkun 1:2fe82be93e80 80 * }
exarkun 1:2fe82be93e80 81 * }
exarkun 1:2fe82be93e80 82 * @endcode
exarkun 1:2fe82be93e80 83 */
exarkun 1:2fe82be93e80 84
exarkun 1:2fe82be93e80 85 class NextionLCD {
exarkun 1:2fe82be93e80 86 public:
exarkun 1:2fe82be93e80 87 /** Create a NextionLCD object for a graphics LCD connected to the specified pins.
exarkun 1:2fe82be93e80 88 * @param Tx USART TX pin used to connect to Nextion LCD's RX pin
exarkun 1:2fe82be93e80 89 * @param Rx USART RX pin used to connect to Nextion LCD's TX pin
exarkun 1:2fe82be93e80 90 */
exarkun 1:2fe82be93e80 91 NextionLCD(PinName Tx, PinName Rx);
exarkun 1:2fe82be93e80 92
exarkun 1:2fe82be93e80 93 /** Clears the lcd by filling it with the specified color pixels.
exarkun 1:2fe82be93e80 94 * @param Color Integer value (0 to 65535) to represent the color to fill the screen with - represented in 16-bit 565 color format
exarkun 1:2fe82be93e80 95 */
exarkun 1:2fe82be93e80 96 void ClrScr(uint16_t color);
exarkun 1:2fe82be93e80 97
exarkun 1:2fe82be93e80 98 /** Draws a string on the lcd at the specified xy position.
exarkun 1:2fe82be93e80 99 * @param x x position.
exarkun 1:2fe82be93e80 100 * @param y y position.
exarkun 1:2fe82be93e80 101 * @param w Width of string area.
exarkun 1:2fe82be93e80 102 * @param h Height of string area.
exarkun 1:2fe82be93e80 103 * @param font Font ID to use (0:smallest - 7:largest).
exarkun 1:2fe82be93e80 104 * @param fontcolor Color Integer value (0 to 65535) to represent the font color of the string - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 105 * @param backcolor Color Integer value (0 to 65535) to represent the background color of the string - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 106 * @param xcenter Horizontal alignment (0: left-aligned, 1: entered, 2: right-aligned).
exarkun 1:2fe82be93e80 107 * @param ycenter Vertical alignment (0: upper-aligned, 1: entered, 2: lower-aligned).
exarkun 1:2fe82be93e80 108 * @param str String content.
exarkun 1:2fe82be93e80 109 */
exarkun 1:2fe82be93e80 110 void DrawString(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t font, uint16_t fontcolor, uint16_t backcolor, uint8_t xcenter, uint8_t ycenter, char *str);
exarkun 1:2fe82be93e80 111
exarkun 1:2fe82be93e80 112 /** Draws a pixel on the lcd at the specified xy position.
exarkun 1:2fe82be93e80 113 * @param x x position
exarkun 1:2fe82be93e80 114 * @param y y position
exarkun 1:2fe82be93e80 115 * @param color Color of the pixel (0 to 65535) - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 116 */
exarkun 1:2fe82be93e80 117 void DrawPixel(uint16_t x, uint16_t y, uint16_t color);
exarkun 1:2fe82be93e80 118
exarkun 1:2fe82be93e80 119 /** Draws a line on the lcd from x1,y1 to x2,y2.
exarkun 1:2fe82be93e80 120 * @param x1 x coordinate starting position
exarkun 1:2fe82be93e80 121 * @param y1 y coordinate starting position
exarkun 1:2fe82be93e80 122 * @param x2 x coordinate ending position
exarkun 1:2fe82be93e80 123 * @param y2 y coordinate ending position
exarkun 1:2fe82be93e80 124 * @param color Color of the line (0 to 65535) - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 125 */
exarkun 1:2fe82be93e80 126 void DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
exarkun 1:2fe82be93e80 127
exarkun 1:2fe82be93e80 128 /** Draws a rectangle on the lcd from x,y with width w and height h.
exarkun 1:2fe82be93e80 129 * @param x x coordinate of top-left corner position
exarkun 1:2fe82be93e80 130 * @param y y coordinate of top-left corner position
exarkun 1:2fe82be93e80 131 * @param w Width of the rectangle
exarkun 1:2fe82be93e80 132 * @param h Height of the rectangle
exarkun 1:2fe82be93e80 133 * @param color Color of the rectangle (0 to 65535) - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 134 */
exarkun 1:2fe82be93e80 135 void DrawRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
exarkun 1:2fe82be93e80 136
exarkun 1:2fe82be93e80 137 /** Draws a filled rectangle on the lcd from x,y with width w and height h.
exarkun 1:2fe82be93e80 138 * @param x x coordinate of top-left corner position
exarkun 1:2fe82be93e80 139 * @param y y coordinate of top-left corner position
exarkun 1:2fe82be93e80 140 * @param w Width of the rectangle
exarkun 1:2fe82be93e80 141 * @param h Height of the rectangle
exarkun 1:2fe82be93e80 142 * @param color Color of the rectangle (0 to 65535) - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 143 */
exarkun 1:2fe82be93e80 144 void FillRectangle(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color);
exarkun 1:2fe82be93e80 145
exarkun 1:2fe82be93e80 146 /** Draws a circle on the lcd at x,y with a radius of r.
exarkun 1:2fe82be93e80 147 * @param x x coordinate position
exarkun 1:2fe82be93e80 148 * @param y y coordinate position
exarkun 1:2fe82be93e80 149 * @param r Radius of the circle
exarkun 1:2fe82be93e80 150 * @param color Color of the circle (0 to 65535) - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 151 */
exarkun 1:2fe82be93e80 152 void DrawCircle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
exarkun 1:2fe82be93e80 153
exarkun 1:2fe82be93e80 154 /** Draws a filled circle on the lcd at x,y with a radius of r.
exarkun 1:2fe82be93e80 155 * @param x x coordinate position
exarkun 1:2fe82be93e80 156 * @param y y coordinate position
exarkun 1:2fe82be93e80 157 * @param r Radius of the circle
exarkun 1:2fe82be93e80 158 * @param color Color of the circle (0 to 65535) - represented in 16-bit 565 color format.
exarkun 1:2fe82be93e80 159 */
exarkun 1:2fe82be93e80 160 void FillCircle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
exarkun 1:2fe82be93e80 161
exarkun 1:2fe82be93e80 162 /** Determines if the touchscreen is being touched or not.
exarkun 1:2fe82be93e80 163 *
exarkun 1:2fe82be93e80 164 * @retval true LCD is being touched.
exarkun 1:2fe82be93e80 165 * @retval false LCD is not being touched.
exarkun 1:2fe82be93e80 166 */
exarkun 1:2fe82be93e80 167 bool Touch(void);
exarkun 1:2fe82be93e80 168
exarkun 1:2fe82be93e80 169 /** Get the X coordinate of the last touch on the touchscreen.
exarkun 1:2fe82be93e80 170 *
exarkun 1:2fe82be93e80 171 * @retval Integer indicating the X coordinate of the last touch.
exarkun 1:2fe82be93e80 172 */
exarkun 1:2fe82be93e80 173 int TouchX(void);
exarkun 1:2fe82be93e80 174
exarkun 1:2fe82be93e80 175 /** Get the Y coordinate of the last touch on the touchscreen.
exarkun 1:2fe82be93e80 176 *
exarkun 1:2fe82be93e80 177 * @retval Integer indicating the X coordinate of the last touch.
exarkun 1:2fe82be93e80 178 */
exarkun 1:2fe82be93e80 179 int TouchY(void);
exarkun 1:2fe82be93e80 180
exarkun 1:2fe82be93e80 181 private:
exarkun 1:2fe82be93e80 182 RawSerial lcd; //Serial object for connecting to Nextion LCD
exarkun 1:2fe82be93e80 183 //Serial pc;
exarkun 1:2fe82be93e80 184 bool mTouch;
exarkun 1:2fe82be93e80 185 int mTouchX, mTouchY;
exarkun 1:2fe82be93e80 186 char mRxMsg[40];
exarkun 1:2fe82be93e80 187 int mRxIdx;
exarkun 1:2fe82be93e80 188 void RxInterrupt(void); //Rx Interrupt
exarkun 1:2fe82be93e80 189 };
exarkun 1:2fe82be93e80 190
exarkun 1:2fe82be93e80 191 #endif