Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TTU_CSC1300.h@0:1201a9a37799, 2020-06-28 (annotated)
- Committer:
- jwbruce
- Date:
- Sun Jun 28 21:13:40 2020 +0000
- Revision:
- 0:1201a9a37799
- Child:
- 1:62c831ab7306
Initial commit - TextLCD, and seven-segment LEDs work. Along with switches and discrete LEDs.; ; TODO: Need to add API documentation
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jwbruce | 0:1201a9a37799 | 1 | // macros, defines, globals,and prototypes for the TTU_F031 library |
| jwbruce | 0:1201a9a37799 | 2 | |
| jwbruce | 0:1201a9a37799 | 3 | #ifndef TTU_CSC1300_H |
| jwbruce | 0:1201a9a37799 | 4 | #define TTU_CSC1300_H |
| jwbruce | 0:1201a9a37799 | 5 | |
| jwbruce | 0:1201a9a37799 | 6 | #include "mbed.h" |
| jwbruce | 0:1201a9a37799 | 7 | |
| jwbruce | 0:1201a9a37799 | 8 | /************************************************************************* |
| jwbruce | 0:1201a9a37799 | 9 | * |
| jwbruce | 0:1201a9a37799 | 10 | * DEFINES and MACROS |
| jwbruce | 0:1201a9a37799 | 11 | * |
| jwbruce | 0:1201a9a37799 | 12 | **************************************************************************/ |
| jwbruce | 0:1201a9a37799 | 13 | #define FALSE 0 |
| jwbruce | 0:1201a9a37799 | 14 | #define TRUE (~FALSE) |
| jwbruce | 0:1201a9a37799 | 15 | #define BIT0 0x00000001 |
| jwbruce | 0:1201a9a37799 | 16 | #define BIT1 0x00000002 |
| jwbruce | 0:1201a9a37799 | 17 | #define BIT2 0x00000004 |
| jwbruce | 0:1201a9a37799 | 18 | #define BIT3 0x00000008 |
| jwbruce | 0:1201a9a37799 | 19 | |
| jwbruce | 0:1201a9a37799 | 20 | #define SEG_A 0xFE |
| jwbruce | 0:1201a9a37799 | 21 | #define SEG_B 0xFD |
| jwbruce | 0:1201a9a37799 | 22 | #define SEG_C 0xFB |
| jwbruce | 0:1201a9a37799 | 23 | #define SEG_D 0xF7 |
| jwbruce | 0:1201a9a37799 | 24 | #define SEG_E 0xEF |
| jwbruce | 0:1201a9a37799 | 25 | #define SEG_F 0xDF |
| jwbruce | 0:1201a9a37799 | 26 | #define SEG_G 0xBF |
| jwbruce | 0:1201a9a37799 | 27 | #define SEG_DP 0x7F |
| jwbruce | 0:1201a9a37799 | 28 | |
| jwbruce | 0:1201a9a37799 | 29 | #define PATTERN_BLANK 0xFF |
| jwbruce | 0:1201a9a37799 | 30 | #define PATTERN_0 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F) |
| jwbruce | 0:1201a9a37799 | 31 | #define PATTERN_1 (SEG_B & SEG_C) |
| jwbruce | 0:1201a9a37799 | 32 | #define PATTERN_2 (SEG_A & SEG_B & SEG_D & SEG_E & SEG_G) |
| jwbruce | 0:1201a9a37799 | 33 | #define PATTERN_3 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_G) |
| jwbruce | 0:1201a9a37799 | 34 | #define PATTERN_4 (SEG_B & SEG_C & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 35 | #define PATTERN_5 (SEG_A & SEG_C & SEG_D & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 36 | #define PATTERN_6 (SEG_A & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 37 | #define PATTERN_7 (SEG_A & SEG_B & SEG_C) |
| jwbruce | 0:1201a9a37799 | 38 | #define PATTERN_8 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 39 | #define PATTERN_9 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 40 | #define PATTERN_A (SEG_A & SEG_B & SEG_C & SEG_E & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 41 | #define PATTERN_B (SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 42 | #define PATTERN_C (SEG_A & SEG_D & SEG_E & SEG_F) |
| jwbruce | 0:1201a9a37799 | 43 | #define PATTERN_D (SEG_B & SEG_C & SEG_D & SEG_E & SEG_G) |
| jwbruce | 0:1201a9a37799 | 44 | #define PATTERN_E (SEG_A & SEG_D & SEG_E & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 45 | #define PATTERN_F (SEG_A & SEG_E & SEG_F & SEG_G) |
| jwbruce | 0:1201a9a37799 | 46 | |
| jwbruce | 0:1201a9a37799 | 47 | /************************************************************************* |
| jwbruce | 0:1201a9a37799 | 48 | * |
| jwbruce | 0:1201a9a37799 | 49 | * HW to peripheral pin mappings |
| jwbruce | 0:1201a9a37799 | 50 | * |
| jwbruce | 0:1201a9a37799 | 51 | **************************************************************************/ |
| jwbruce | 0:1201a9a37799 | 52 | #define SCL_PIN PA_9 |
| jwbruce | 0:1201a9a37799 | 53 | #define SDA_PIN PA_10 |
| jwbruce | 0:1201a9a37799 | 54 | #define LED0_PIN PA_12 |
| jwbruce | 0:1201a9a37799 | 55 | #define LED1_PIN PB_0 |
| jwbruce | 0:1201a9a37799 | 56 | #define LED3_PIN PB_7 |
| jwbruce | 0:1201a9a37799 | 57 | #define PWM1_PIN PB_1 |
| jwbruce | 0:1201a9a37799 | 58 | #define LED2_PIN PF_0 |
| jwbruce | 0:1201a9a37799 | 59 | #define CS_SD_PIN PF_1 |
| jwbruce | 0:1201a9a37799 | 60 | #define SPK_PIN PA_8 |
| jwbruce | 0:1201a9a37799 | 61 | #define CS_LCD_PIN PA_11 |
| jwbruce | 0:1201a9a37799 | 62 | #define MOSI_PIN PB_5 |
| jwbruce | 0:1201a9a37799 | 63 | #define MISO_PIN PB_4 |
| jwbruce | 0:1201a9a37799 | 64 | #define SCLK_PIN PB_3 |
| jwbruce | 0:1201a9a37799 | 65 | #define LGT_SENS_PIN PA_0 |
| jwbruce | 0:1201a9a37799 | 66 | #define POT_PIN PA_1 |
| jwbruce | 0:1201a9a37799 | 67 | #define TEMP_SENS_PIN PA_3 |
| jwbruce | 0:1201a9a37799 | 68 | #define PWM2_PIN PA_4 |
| jwbruce | 0:1201a9a37799 | 69 | #define SW4_PIN PA_5 |
| jwbruce | 0:1201a9a37799 | 70 | #define SW5_PIN PA_6 |
| jwbruce | 0:1201a9a37799 | 71 | #define CS_7SEG_PIN PA_7 |
| jwbruce | 0:1201a9a37799 | 72 | #define TX_PIN PA_12 |
| jwbruce | 0:1201a9a37799 | 73 | #define RX_PIN PA_15 |
| jwbruce | 0:1201a9a37799 | 74 | |
| jwbruce | 0:1201a9a37799 | 75 | /************************************************************************* |
| jwbruce | 0:1201a9a37799 | 76 | * |
| jwbruce | 0:1201a9a37799 | 77 | * Other useful defines |
| jwbruce | 0:1201a9a37799 | 78 | * |
| jwbruce | 0:1201a9a37799 | 79 | **************************************************************************/ |
| jwbruce | 0:1201a9a37799 | 80 | #define I2C_SPEED_STD 100000 |
| jwbruce | 0:1201a9a37799 | 81 | #define I2C_SPEED_FAST 400000 |
| jwbruce | 0:1201a9a37799 | 82 | #define I2C_SPEED_FASTPLUS 1000000 |
| jwbruce | 0:1201a9a37799 | 83 | |
| jwbruce | 0:1201a9a37799 | 84 | #define SPI_SPEED_100KBPS 100000 |
| jwbruce | 0:1201a9a37799 | 85 | #define SPI_SPEED_500KBPS 500000 |
| jwbruce | 0:1201a9a37799 | 86 | #define SPI_SPEED_1MBPS 1000000 |
| jwbruce | 0:1201a9a37799 | 87 | |
| jwbruce | 0:1201a9a37799 | 88 | /************************************************************************* |
| jwbruce | 0:1201a9a37799 | 89 | * |
| jwbruce | 0:1201a9a37799 | 90 | * USEFUL MACROS |
| jwbruce | 0:1201a9a37799 | 91 | * |
| jwbruce | 0:1201a9a37799 | 92 | *************************************************************************/ |
| jwbruce | 0:1201a9a37799 | 93 | |
| jwbruce | 0:1201a9a37799 | 94 | /************************************************************************* |
| jwbruce | 0:1201a9a37799 | 95 | * |
| jwbruce | 0:1201a9a37799 | 96 | * G L O B A L V A R I A B L E S |
| jwbruce | 0:1201a9a37799 | 97 | * |
| jwbruce | 0:1201a9a37799 | 98 | *************************************************************************/ |
| jwbruce | 0:1201a9a37799 | 99 | extern SPI spi; |
| jwbruce | 0:1201a9a37799 | 100 | //extern I2C i2c; |
| jwbruce | 0:1201a9a37799 | 101 | extern Serial pc; |
| jwbruce | 0:1201a9a37799 | 102 | |
| jwbruce | 0:1201a9a37799 | 103 | // create the LEDs |
| jwbruce | 0:1201a9a37799 | 104 | extern DigitalOut led0; |
| jwbruce | 0:1201a9a37799 | 105 | extern DigitalOut led1; |
| jwbruce | 0:1201a9a37799 | 106 | extern DigitalOut led2; |
| jwbruce | 0:1201a9a37799 | 107 | /* only uncomment the following line if your Nucleo32 F031K6 |
| jwbruce | 0:1201a9a37799 | 108 | ** has removed the solder jumper SB18 on the underside |
| jwbruce | 0:1201a9a37799 | 109 | */ |
| jwbruce | 0:1201a9a37799 | 110 | extern DigitalOut led3; |
| jwbruce | 0:1201a9a37799 | 111 | |
| jwbruce | 0:1201a9a37799 | 112 | // create the speaker |
| jwbruce | 0:1201a9a37799 | 113 | extern DigitalOut speaker; |
| jwbruce | 0:1201a9a37799 | 114 | |
| jwbruce | 0:1201a9a37799 | 115 | //create the chip-selects |
| jwbruce | 0:1201a9a37799 | 116 | extern DigitalOut cs_sd; |
| jwbruce | 0:1201a9a37799 | 117 | extern DigitalOut cs_lcd; |
| jwbruce | 0:1201a9a37799 | 118 | extern DigitalOut cs_7seg; |
| jwbruce | 0:1201a9a37799 | 119 | |
| jwbruce | 0:1201a9a37799 | 120 | // create the switches |
| jwbruce | 0:1201a9a37799 | 121 | extern DigitalIn sw4; |
| jwbruce | 0:1201a9a37799 | 122 | extern DigitalIn sw5; |
| jwbruce | 0:1201a9a37799 | 123 | |
| jwbruce | 0:1201a9a37799 | 124 | // create the analog sensors |
| jwbruce | 0:1201a9a37799 | 125 | extern AnalogIn lightSensor; |
| jwbruce | 0:1201a9a37799 | 126 | extern AnalogIn pot; |
| jwbruce | 0:1201a9a37799 | 127 | extern AnalogIn tempSensor; |
| jwbruce | 0:1201a9a37799 | 128 | |
| jwbruce | 0:1201a9a37799 | 129 | /************************************************************************* |
| jwbruce | 0:1201a9a37799 | 130 | * |
| jwbruce | 0:1201a9a37799 | 131 | * P R O T O T Y P E S |
| jwbruce | 0:1201a9a37799 | 132 | * |
| jwbruce | 0:1201a9a37799 | 133 | *************************************************************************/ |
| jwbruce | 0:1201a9a37799 | 134 | void init_spi(int i_spiBaud); |
| jwbruce | 0:1201a9a37799 | 135 | //void init_i2c(int i_i2cBaud); |
| jwbruce | 0:1201a9a37799 | 136 | void init_serial(int i_serialBaud); |
| jwbruce | 0:1201a9a37799 | 137 | void init_leds(void); |
| jwbruce | 0:1201a9a37799 | 138 | void init_all(void); |
| jwbruce | 0:1201a9a37799 | 139 | |
| jwbruce | 0:1201a9a37799 | 140 | /* TEXTLCD |
| jwbruce | 0:1201a9a37799 | 141 | * |
| jwbruce | 0:1201a9a37799 | 142 | * A TextLCD library targeted the F031K6 + Edubase-V2 combination |
| jwbruce | 0:1201a9a37799 | 143 | * implmements a 16x2 HD44780 LCD module using a 4-bit inteface |
| jwbruce | 0:1201a9a37799 | 144 | * connected via a 74HC595 using the chip's SPI |
| jwbruce | 0:1201a9a37799 | 145 | * |
| jwbruce | 0:1201a9a37799 | 146 | * This work is based upon the TextLCD mbed library by Simon Ford |
| jwbruce | 0:1201a9a37799 | 147 | * found at https://os.mbed.com/users/simon/code/TextLCD/ |
| jwbruce | 0:1201a9a37799 | 148 | * |
| jwbruce | 0:1201a9a37799 | 149 | * Copyright (c) 2007-2010, sford, http://mbed.org |
| jwbruce | 0:1201a9a37799 | 150 | * Copyright (c) 2020, jwbruce (jwbruce@tntech.edu) |
| jwbruce | 0:1201a9a37799 | 151 | * |
| jwbruce | 0:1201a9a37799 | 152 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| jwbruce | 0:1201a9a37799 | 153 | * of this software and associated documentation files (the "Software"), to deal |
| jwbruce | 0:1201a9a37799 | 154 | * in the Software without restriction, including without limitation the rights |
| jwbruce | 0:1201a9a37799 | 155 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| jwbruce | 0:1201a9a37799 | 156 | * copies of the Software, and to permit persons to whom the Software is |
| jwbruce | 0:1201a9a37799 | 157 | * furnished to do so, subject to the following conditions: |
| jwbruce | 0:1201a9a37799 | 158 | * |
| jwbruce | 0:1201a9a37799 | 159 | * The above copyright notice and this permission notice shall be included in |
| jwbruce | 0:1201a9a37799 | 160 | * all copies or substantial portions of the Software. |
| jwbruce | 0:1201a9a37799 | 161 | * |
| jwbruce | 0:1201a9a37799 | 162 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| jwbruce | 0:1201a9a37799 | 163 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| jwbruce | 0:1201a9a37799 | 164 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| jwbruce | 0:1201a9a37799 | 165 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| jwbruce | 0:1201a9a37799 | 166 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| jwbruce | 0:1201a9a37799 | 167 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| jwbruce | 0:1201a9a37799 | 168 | * THE SOFTWARE. |
| jwbruce | 0:1201a9a37799 | 169 | */ |
| jwbruce | 0:1201a9a37799 | 170 | |
| jwbruce | 0:1201a9a37799 | 171 | /** A TextLCD interface for driving 4-bit HD44780-based LCDs |
| jwbruce | 0:1201a9a37799 | 172 | * |
| jwbruce | 0:1201a9a37799 | 173 | * Supports only the 16x2 display on the EduBase-V2 board |
| jwbruce | 0:1201a9a37799 | 174 | * |
| jwbruce | 0:1201a9a37799 | 175 | * @code |
| jwbruce | 0:1201a9a37799 | 176 | * #include "mbed.h" |
| jwbruce | 0:1201a9a37799 | 177 | * #include "TextLCD.h" |
| jwbruce | 0:1201a9a37799 | 178 | * |
| jwbruce | 0:1201a9a37799 | 179 | * TextLCD lcd(TextLCD::LCD_CURSOR_ON_BLINKING_ON); // select your cursor style |
| jwbruce | 0:1201a9a37799 | 180 | * |
| jwbruce | 0:1201a9a37799 | 181 | * int main() { |
| jwbruce | 0:1201a9a37799 | 182 | * lcd.printf("Hello World!\n"); |
| jwbruce | 0:1201a9a37799 | 183 | * } |
| jwbruce | 0:1201a9a37799 | 184 | * @endcode |
| jwbruce | 0:1201a9a37799 | 185 | */ |
| jwbruce | 0:1201a9a37799 | 186 | class TextLCD : public Stream { |
| jwbruce | 0:1201a9a37799 | 187 | public: |
| jwbruce | 0:1201a9a37799 | 188 | |
| jwbruce | 0:1201a9a37799 | 189 | typedef enum { |
| jwbruce | 0:1201a9a37799 | 190 | LCD_CURSOR_OFF_BLINKING_OFF = 0, |
| jwbruce | 0:1201a9a37799 | 191 | LCD_CURSOR_OFF_BLINKING_ON = 0x01, |
| jwbruce | 0:1201a9a37799 | 192 | LCD_CURSOR_ON_BLINKING_OFF = 0x02, |
| jwbruce | 0:1201a9a37799 | 193 | LCD_CURSOR_ON_BLINKING_ON = 0x03, |
| jwbruce | 0:1201a9a37799 | 194 | LCD_CURSOR_DEFAULT = 0x03 |
| jwbruce | 0:1201a9a37799 | 195 | } LCDCursor; |
| jwbruce | 0:1201a9a37799 | 196 | |
| jwbruce | 0:1201a9a37799 | 197 | /** Declare a TextLCD interface */ |
| jwbruce | 0:1201a9a37799 | 198 | TextLCD(LCDCursor cur); // default constructor |
| jwbruce | 0:1201a9a37799 | 199 | |
| jwbruce | 0:1201a9a37799 | 200 | #if DOXYGEN_ONLY |
| jwbruce | 0:1201a9a37799 | 201 | /** Write a character to the LCD |
| jwbruce | 0:1201a9a37799 | 202 | * |
| jwbruce | 0:1201a9a37799 | 203 | * @param c The character to write to the display |
| jwbruce | 0:1201a9a37799 | 204 | */ |
| jwbruce | 0:1201a9a37799 | 205 | int putc(int c); |
| jwbruce | 0:1201a9a37799 | 206 | |
| jwbruce | 0:1201a9a37799 | 207 | /** Write a formated string to the LCD |
| jwbruce | 0:1201a9a37799 | 208 | * |
| jwbruce | 0:1201a9a37799 | 209 | * @param format A printf-style format string, followed by the |
| jwbruce | 0:1201a9a37799 | 210 | * variables to use in formating the string. |
| jwbruce | 0:1201a9a37799 | 211 | */ |
| jwbruce | 0:1201a9a37799 | 212 | int printf(const char* format, ...); |
| jwbruce | 0:1201a9a37799 | 213 | #endif |
| jwbruce | 0:1201a9a37799 | 214 | |
| jwbruce | 0:1201a9a37799 | 215 | /** Locate to a screen column and row |
| jwbruce | 0:1201a9a37799 | 216 | * |
| jwbruce | 0:1201a9a37799 | 217 | * @param column The horizontal position from the left, indexed from 0 |
| jwbruce | 0:1201a9a37799 | 218 | * @param row The vertical position from the top, indexed from 0 |
| jwbruce | 0:1201a9a37799 | 219 | */ |
| jwbruce | 0:1201a9a37799 | 220 | void setLocation(int column, int row); |
| jwbruce | 0:1201a9a37799 | 221 | |
| jwbruce | 0:1201a9a37799 | 222 | /** Clear the screen and locate to 0,0 */ |
| jwbruce | 0:1201a9a37799 | 223 | void cls(); |
| jwbruce | 0:1201a9a37799 | 224 | |
| jwbruce | 0:1201a9a37799 | 225 | /** low-level single character putter **/ |
| jwbruce | 0:1201a9a37799 | 226 | void setCharacter(int row, int column, int c); |
| jwbruce | 0:1201a9a37799 | 227 | void setCursor(LCDCursor c); |
| jwbruce | 0:1201a9a37799 | 228 | |
| jwbruce | 0:1201a9a37799 | 229 | protected: |
| jwbruce | 0:1201a9a37799 | 230 | |
| jwbruce | 0:1201a9a37799 | 231 | // Stream implementation functions |
| jwbruce | 0:1201a9a37799 | 232 | virtual int _putc(int value); |
| jwbruce | 0:1201a9a37799 | 233 | virtual int _getc(); |
| jwbruce | 0:1201a9a37799 | 234 | |
| jwbruce | 0:1201a9a37799 | 235 | int address(int column, int row); |
| jwbruce | 0:1201a9a37799 | 236 | void writeNibble(char incoming, unsigned char rs); |
| jwbruce | 0:1201a9a37799 | 237 | void writeCommand(int command); |
| jwbruce | 0:1201a9a37799 | 238 | void writeData(int data); |
| jwbruce | 0:1201a9a37799 | 239 | |
| jwbruce | 0:1201a9a37799 | 240 | int _column; |
| jwbruce | 0:1201a9a37799 | 241 | int _row; |
| jwbruce | 0:1201a9a37799 | 242 | int _maxColumns; |
| jwbruce | 0:1201a9a37799 | 243 | int _maxRows; |
| jwbruce | 0:1201a9a37799 | 244 | int _cursorState; |
| jwbruce | 0:1201a9a37799 | 245 | |
| jwbruce | 0:1201a9a37799 | 246 | }; |
| jwbruce | 0:1201a9a37799 | 247 | |
| jwbruce | 0:1201a9a37799 | 248 | |
| jwbruce | 0:1201a9a37799 | 249 | /* F031K6 + Edubase-V2 7-segment LED Library |
| jwbruce | 0:1201a9a37799 | 250 | * for the 4 seven-segment LEDs inteface connected via two 74HC595s using SPI |
| jwbruce | 0:1201a9a37799 | 251 | * |
| jwbruce | 0:1201a9a37799 | 252 | * Copyright (c) 2020, jwbruce (jwbruce@tntech.edu) |
| jwbruce | 0:1201a9a37799 | 253 | * |
| jwbruce | 0:1201a9a37799 | 254 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| jwbruce | 0:1201a9a37799 | 255 | * of this software and associated documentation files (the "Software"), to deal |
| jwbruce | 0:1201a9a37799 | 256 | * in the Software without restriction, including without limitation the rights |
| jwbruce | 0:1201a9a37799 | 257 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| jwbruce | 0:1201a9a37799 | 258 | * copies of the Software, and to permit persons to whom the Software is |
| jwbruce | 0:1201a9a37799 | 259 | * furnished to do so, subject to the following conditions: |
| jwbruce | 0:1201a9a37799 | 260 | * |
| jwbruce | 0:1201a9a37799 | 261 | * The above copyright notice and this permission notice shall be included in |
| jwbruce | 0:1201a9a37799 | 262 | * all copies or substantial portions of the Software. |
| jwbruce | 0:1201a9a37799 | 263 | * |
| jwbruce | 0:1201a9a37799 | 264 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| jwbruce | 0:1201a9a37799 | 265 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| jwbruce | 0:1201a9a37799 | 266 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| jwbruce | 0:1201a9a37799 | 267 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| jwbruce | 0:1201a9a37799 | 268 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| jwbruce | 0:1201a9a37799 | 269 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| jwbruce | 0:1201a9a37799 | 270 | * THE SOFTWARE. |
| jwbruce | 0:1201a9a37799 | 271 | */ |
| jwbruce | 0:1201a9a37799 | 272 | |
| jwbruce | 0:1201a9a37799 | 273 | /** A 7-segment LED interface for driving 4 connected seven-segment LEDs |
| jwbruce | 0:1201a9a37799 | 274 | * |
| jwbruce | 0:1201a9a37799 | 275 | * @code |
| jwbruce | 0:1201a9a37799 | 276 | * #include "mbed.h" |
| jwbruce | 0:1201a9a37799 | 277 | * #include "TextLCD.h" |
| jwbruce | 0:1201a9a37799 | 278 | * |
| jwbruce | 0:1201a9a37799 | 279 | * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d4-d7 |
| jwbruce | 0:1201a9a37799 | 280 | * |
| jwbruce | 0:1201a9a37799 | 281 | * int main() { |
| jwbruce | 0:1201a9a37799 | 282 | * lcd.printf("Hello World!\n"); |
| jwbruce | 0:1201a9a37799 | 283 | * } |
| jwbruce | 0:1201a9a37799 | 284 | * @endcode |
| jwbruce | 0:1201a9a37799 | 285 | */ |
| jwbruce | 0:1201a9a37799 | 286 | class SSLED { |
| jwbruce | 0:1201a9a37799 | 287 | public: |
| jwbruce | 0:1201a9a37799 | 288 | |
| jwbruce | 0:1201a9a37799 | 289 | typedef enum { |
| jwbruce | 0:1201a9a37799 | 290 | LED_PATTERN_0 = ~0x3F, |
| jwbruce | 0:1201a9a37799 | 291 | LED_PATTERN_1 = ~0x06, |
| jwbruce | 0:1201a9a37799 | 292 | LED_PATTERN_2 = ~0x5B, |
| jwbruce | 0:1201a9a37799 | 293 | LED_PATTERN_3 = ~0x4F, |
| jwbruce | 0:1201a9a37799 | 294 | LED_PATTERN_4 = ~0x66, |
| jwbruce | 0:1201a9a37799 | 295 | LED_PATTERN_5 = ~0x6D, |
| jwbruce | 0:1201a9a37799 | 296 | LED_PATTERN_6 = ~0x7D, |
| jwbruce | 0:1201a9a37799 | 297 | LED_PATTERN_7 = ~0x07, |
| jwbruce | 0:1201a9a37799 | 298 | LED_PATTERN_8 = ~0x7F, |
| jwbruce | 0:1201a9a37799 | 299 | LED_PATTERN_9 = ~0x6F, |
| jwbruce | 0:1201a9a37799 | 300 | LED_PATTERN_A = ~0x77, |
| jwbruce | 0:1201a9a37799 | 301 | LED_PATTERN_B = ~0x7C, |
| jwbruce | 0:1201a9a37799 | 302 | LED_PATTERN_C = ~0x39, |
| jwbruce | 0:1201a9a37799 | 303 | LED_PATTERN_D = ~0x5E, |
| jwbruce | 0:1201a9a37799 | 304 | LED_PATTERN_E = ~0x79, |
| jwbruce | 0:1201a9a37799 | 305 | LED_PATTERN_F = ~0x71, |
| jwbruce | 0:1201a9a37799 | 306 | LED_PATTERN_G = ~0x40, |
| jwbruce | 0:1201a9a37799 | 307 | LED_PATTERN_H = ~0x76, |
| jwbruce | 0:1201a9a37799 | 308 | LED_PATTERN_I = ~0x30, |
| jwbruce | 0:1201a9a37799 | 309 | LED_PATTERN_J = ~0x1E, |
| jwbruce | 0:1201a9a37799 | 310 | LED_PATTERN_L = ~0x38, |
| jwbruce | 0:1201a9a37799 | 311 | LED_PATTERN_N = ~0x54, |
| jwbruce | 0:1201a9a37799 | 312 | LED_PATTERN_O = ~0x3F, |
| jwbruce | 0:1201a9a37799 | 313 | LED_PATTERN_P = ~0x73, |
| jwbruce | 0:1201a9a37799 | 314 | LED_PATTERN_Q = ~0x67, |
| jwbruce | 0:1201a9a37799 | 315 | LED_PATTERN_R = ~0x50, |
| jwbruce | 0:1201a9a37799 | 316 | LED_PATTERN_S = LED_PATTERN_5, |
| jwbruce | 0:1201a9a37799 | 317 | LED_PATTERN_T = ~0x78, |
| jwbruce | 0:1201a9a37799 | 318 | LED_PATTERN_U = ~0x1C, |
| jwbruce | 0:1201a9a37799 | 319 | LED_PATTERN_V = ~0x2A, |
| jwbruce | 0:1201a9a37799 | 320 | LED_PATTERN_Y = ~0x6E, |
| jwbruce | 0:1201a9a37799 | 321 | LED_PATTERN_BLANK = ~0x00, |
| jwbruce | 0:1201a9a37799 | 322 | LED_PATTERN_SPACE = LED_PATTERN_BLANK, |
| jwbruce | 0:1201a9a37799 | 323 | LED_PATTERN_DASH = ~0x40, |
| jwbruce | 0:1201a9a37799 | 324 | LED_PATTERN_DEGREES = ~0xC3, |
| jwbruce | 0:1201a9a37799 | 325 | LED_PATTERN_DECIMALPT = ~0x80, |
| jwbruce | 0:1201a9a37799 | 326 | LED_PATTERN_QUESTION = ~0x53 |
| jwbruce | 0:1201a9a37799 | 327 | } LEDPattern; |
| jwbruce | 0:1201a9a37799 | 328 | |
| jwbruce | 0:1201a9a37799 | 329 | /** Declare a 7-segment LED interface */ |
| jwbruce | 0:1201a9a37799 | 330 | // constructor |
| jwbruce | 0:1201a9a37799 | 331 | SSLED(int display, int pattern); |
| jwbruce | 0:1201a9a37799 | 332 | |
| jwbruce | 0:1201a9a37799 | 333 | /** Write a pattern to a chosen display */ |
| jwbruce | 0:1201a9a37799 | 334 | void setDisplay(int display, int pattern); // change patterns to blank and write the displays |
| jwbruce | 0:1201a9a37799 | 335 | }; |
| jwbruce | 0:1201a9a37799 | 336 | |
| jwbruce | 0:1201a9a37799 | 337 | |
| jwbruce | 0:1201a9a37799 | 338 | |
| jwbruce | 0:1201a9a37799 | 339 | #endif |