├── .gitattributes ├── .gitignore ├── README.md ├── examples ├── Bubble_Display_Counter │ └── Bubble_Display_Counter.ino ├── Bubble_Display_SHT15 │ └── Bubble_Display_SHT15.ino ├── Bubble_Display_Text │ └── Bubble_Display_Text.ino ├── Example.jpg └── SevSeg_Counter │ └── SevSeg_Counter.ino ├── keywords.txt ├── library.properties └── src ├── SevSeg.cpp └── SevSeg.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This library allows an Arduino to easily display numbers and characters on a 4 digit 7-segment display without a separate 7-segment display controller. 2 | It works for any digital pin arrangement, common anode and common cathode displays. It also has character support including letters A-F and many symbols. 3 | 4 | Hardware Setup 5 | -------------- 6 | 4 digit 7 segment displays use 12 digital pins. You may need more pins if your display has colons or apostrophes. 7 | 8 | There are 4 digit pins and 8 segment pins. Digit pins are connected to the cathodes for common cathode displays, or anodes for common anode displays. 8 pins control the individual segments (seven segments plus the decimal point). 9 | 10 | Connect the four digit pins with four limiting resistors in series to any digital or analog pins. Connect the eight segment pins to any digital or analog pins (no limiting resistors needed). See the SevSeg example for more connection information. 11 | 12 | Repository Contents 13 | ------------------- 14 | 15 | * **/examples** - Arduino example sketches 16 | * **/src** - Source files for Arduino library 17 | 18 | Documentation 19 | -------------- 20 | * **[Hookup Guide](https://learn.sparkfun.com/tutorials/using-the-serial-7-segment-display)** - Basic hookup guide for the Serial Segment Displays. 21 | * **[Compatible Displays](https://www.sparkfun.com/wish_lists/120699)** - Products that work with this code. 22 | 23 | License Information 24 | ------------------- 25 | Original Library by Dean Reading (deanreading@hotmail.com: http://arduino.cc/playground/Main/SevenSegmentLibrary), 2012 26 | 27 | Improvements by Nathan Seidle, 2012 28 | 29 | All code is open source so please feel free to do anything you want with it; you buy me a beer if you use this and we meet someday ([Beerware license](http://en.wikipedia.org/wiki/Beerware)). 30 | -------------------------------------------------------------------------------- /examples/Bubble_Display_Counter/Bubble_Display_Counter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | March 6, 2014 3 | Spark Fun Electronics 4 | Nathan Seidle 5 | Updates by Joel Bartlett 6 | 7 | This code is originally based Dean Reading's Library deanreading@hotmail.com 8 | http://arduino.cc/playground/Main/SevenSegmentLibrary 9 | He didn't have a license on it so I hope he doesn't mind me making it public domain: 10 | This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 11 | 12 | This sketch provides a simple counter example for the HP Bubble display from SparkFun. 13 | https://www.sparkfun.com/products/12710 14 | 15 | Pinout for HP Bubble Display: 16 | 1: Cathode 1 17 | 2: Anode E 18 | 3: Anode C 19 | 4: Cathode 3 20 | 5: Anode dp 21 | 6: Cathode 4 22 | 7: Anode G 23 | 8: Anode D 24 | 9: Anode F 25 | 10: Cathode 2 26 | 11: Anode B 27 | 12: Anode A 28 | */ 29 | 30 | #include "SevSeg.h" 31 | 32 | //Create an instance of the object. 33 | SevSeg myDisplay; 34 | 35 | //Create global variables 36 | unsigned long timer; 37 | int deciSecond = 0; 38 | 39 | void setup() 40 | { 41 | 42 | int displayType = COMMON_CATHODE; //Your display is either common cathode or common anode 43 | 44 | 45 | //This pinout is for a bubble dispaly 46 | //Declare what pins are connected to the GND pins (cathodes) 47 | int digit1 = 8; //Pin 1 48 | int digit2 = 5; //Pin 10 49 | int digit3 = 11; //Pin 4 50 | int digit4 = 13; //Pin 6 51 | 52 | //Declare what pins are connected to the segments (anodes) 53 | int segA = 7; //Pin 12 54 | int segB = 6; //Pin 11 55 | int segC = 10; //Pin 3 56 | int segD = 3; //Pin 8 57 | int segE = 9; //Pin 2 58 | int segF = 4; //Pin 9 59 | int segG = 2; //Pin 7 60 | int segDP= 12; //Pin 5 61 | 62 | int numberOfDigits = 4; //Do you have a 1, 2 or 4 digit display? 63 | 64 | myDisplay.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP); 65 | 66 | myDisplay.SetBrightness(100); //Set the display to 100% brightness level 67 | 68 | timer = millis(); 69 | } 70 | 71 | void loop() 72 | { 73 | //Example ways of displaying a decimal number 74 | char tempString[10]; //Used for sprintf 75 | sprintf(tempString, "%4d", deciSecond); //Convert deciSecond into a string that is right adjusted 76 | //sprintf(tempString, "%d", deciSecond); //Convert deciSecond into a string that is left adjusted 77 | //sprintf(tempString, "%04d", deciSecond); //Convert deciSecond into a string with leading zeros 78 | //sprintf(tempString, "%4d", deciSecond * -1); //Shows a negative sign infront of right adjusted number 79 | //sprintf(tempString, "%4X", deciSecond); //Count in HEX, right adjusted 80 | 81 | //Produce an output on the display 82 | myDisplay.DisplayString(tempString, 4); //(numberToDisplay, decimal point location in binary number [4 means the third digit]) 83 | 84 | //Other examples 85 | //myDisplay.DisplayString(tempString, 0); //Display string, no decimal point 86 | //myDisplay.DisplayString("-235", 2); //Display string, decimal point in second position 87 | //myDisplay.DisplayString("8888", 15); //Everything on! 88 | 89 | //Check if 10ms has elapsed 90 | if (millis() - timer >= 100) 91 | { 92 | timer = millis(); 93 | deciSecond++; 94 | } 95 | 96 | delay(5); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /examples/Bubble_Display_SHT15/Bubble_Display_SHT15.ino: -------------------------------------------------------------------------------- 1 | /* 2 | March 6, 2014 3 | Spark Fun Electronics 4 | Nathan Seidle 5 | Updates by Joel Bartlett 6 | 7 | This code is originally based Dean Reading's Library deanreading@hotmail.com 8 | http://arduino.cc/playground/Main/SevenSegmentLibrary 9 | He didn't have a license on it so I hope he doesn't mind me making it public domain: 10 | This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 11 | 12 | This example gives you a real world scenario in which we take sensor data (in this case temperature and humidity 13 | data from a SHT15) and print it to the bubble display using characters and numbers. 14 | 15 | 16 | Pinout for HP Bubble Display: 17 | 1: Cathode 1 18 | 2: Anode E 19 | 3: Anode C 20 | 4: Cathode 3 21 | 5: Anode dp 22 | 6: Cathode 4 23 | 7: Anode G 24 | 8: Anode D 25 | 9: Anode F 26 | 10: Cathode 2 27 | 11: Anode B 28 | 12: Anode A 29 | 30 | Pinout for SHT15: 31 | Vcc: 3.3V 32 | Data: A4 or SDA on newer Arduino boards 33 | SCK: A5 or SCK on newer Arduino boards 34 | GND: GND 35 | 36 | Here is the character map found in the SevSeg.h file for reference 37 | as to which characters can be displayed and which can't. 38 | 39 | // ABCDEFG Segments 40 | 0b1111110, // 0 41 | 0b0110000, // 1 42 | 0b1101101, // 2 43 | 0b1111001, // 3 44 | 0b0110011, // 4 45 | 0b1011011, // 5 46 | 0b1011111, // 6 47 | 0b1110000, // 7 48 | 0b1111111, // 8 49 | 0b1111011, // 9 50 | 0b1110111, // 10 "A" 51 | 0b0011111, // 11 "B" 52 | 0b1001110, // 12 "C" 53 | 0b0111101, // 13 "D" 54 | 0b1001111, // 14 "E" 55 | 0b1000111, // 15 "F" 56 | 0b0000000, // 16 NO DISPLAY 57 | 0b0000000, // 17 NO DISPLAY 58 | 0b0000000, // 18 NO DISPLAY 59 | 0b0000000, // 19 NO DISPLAY 60 | 0b0000000, // 20 NO DISPLAY 61 | 0b0000000, // 21 NO DISPLAY 62 | 0b0000000, // 22 NO DISPLAY 63 | 0b0000000, // 23 NO DISPLAY 64 | 0b0000000, // 24 NO DISPLAY 65 | 0b0000000, // 25 NO DISPLAY 66 | 0b0000000, // 26 NO DISPLAY 67 | 0b0000000, // 27 NO DISPLAY 68 | 0b0000000, // 28 NO DISPLAY 69 | 0b0000000, // 29 NO DISPLAY 70 | 0b0000000, // 30 NO DISPLAY 71 | 0b0000000, // 31 NO DISPLAY 72 | 0b0000000, // 32 ' ' 73 | 0b0000000, // 33 '!' NO DISPLAY 74 | 0b0100010, // 34 '"' 75 | 0b0000000, // 35 '#' NO DISPLAY 76 | 0b0000000, // 36 '$' NO DISPLAY 77 | 0b0000000, // 37 '%' NO DISPLAY 78 | 0b0000000, // 38 '&' NO DISPLAY 79 | 0b0100000, // 39 ''' 80 | 0b1001110, // 40 '(' 81 | 0b1111000, // 41 ')' 82 | 0b0000000, // 42 '*' NO DISPLAY 83 | 0b0000000, // 43 '+' NO DISPLAY 84 | 0b0000100, // 44 ',' 85 | 0b0000001, // 45 '-' 86 | 0b0000000, // 46 '.' NO DISPLAY 87 | 0b0000000, // 47 '/' NO DISPLAY 88 | 0b1111110, // 48 '0' 89 | 0b0110000, // 49 '1' 90 | 0b1101101, // 50 '2' 91 | 0b1111001, // 51 '3' 92 | 0b0110011, // 52 '4' 93 | 0b1011011, // 53 '5' 94 | 0b1011111, // 54 '6' 95 | 0b1110000, // 55 '7' 96 | 0b1111111, // 56 '8' 97 | 0b1111011, // 57 '9' 98 | 0b0000000, // 58 ':' NO DISPLAY 99 | 0b0000000, // 59 ';' NO DISPLAY 100 | 0b0000000, // 60 '<' NO DISPLAY 101 | 0b0000000, // 61 '=' NO DISPLAY 102 | 0b0000000, // 62 '>' NO DISPLAY 103 | 0b0000000, // 63 '?' NO DISPLAY 104 | 0b0000000, // 64 '@' NO DISPLAY 105 | 0b1110111, // 65 'A' 106 | 0b0011111, // 66 'B' 107 | 0b1001110, // 67 'C' 108 | 0b0111101, // 68 'D' 109 | 0b1001111, // 69 'E' 110 | 0b1000111, // 70 'F' 111 | 0b1011110, // 71 'G' 112 | 0b0110111, // 72 'H' 113 | 0b0110000, // 73 'I' 114 | 0b0111000, // 74 'J' 115 | 0b0000000, // 75 'K' NO DISPLAY 116 | 0b0001110, // 76 'L' 117 | 0b0000000, // 77 'M' NO DISPLAY 118 | 0b0010101, // 78 'N' 119 | 0b1111110, // 79 'O' 120 | 0b1101111, // 80 'P' 121 | 0b1110011, // 81 'Q' 122 | 0b0000101, // 82 'R' 123 | 0b1011011, // 83 'S' 124 | 0b0001111, // 84 'T' 125 | 0b0111110, // 85 'U' 126 | 0b0000000, // 86 'V' NO DISPLAY 127 | 0b0000000, // 87 'W' NO DISPLAY 128 | 0b0000000, // 88 'X' NO DISPLAY 129 | 0b0111011, // 89 'Y' 130 | 0b0000000, // 90 'Z' NO DISPLAY 131 | 0b1001110, // 91 '[' 132 | 0b0000000, // 92 '\' NO DISPLAY 133 | 0b1111000, // 93 ']' 134 | 0b0000000, // 94 '^' NO DISPLAY 135 | 0b0001000, // 95 '_' 136 | 0b0000010, // 96 '`' 137 | 0b1110111, // 97 'a' SAME AS CAP 138 | 0b0011111, // 98 'b' SAME AS CAP 139 | 0b0001101, // 99 'c' 140 | 0b0111101, // 100 'd' SAME AS CAP 141 | 0b1101111, // 101 'e' 142 | 0b1000111, // 102 'f' SAME AS CAP 143 | 0b1011110, // 103 'g' SAME AS CAP 144 | 0b0010111, // 104 'h' 145 | 0b0010000, // 105 'i' 146 | 0b0111000, // 106 'j' SAME AS CAP 147 | 0b0000000, // 107 'k' NO DISPLAY 148 | 0b0110000, // 108 'l' 149 | 0b0000000, // 109 'm' NO DISPLAY 150 | 0b0010101, // 110 'n' SAME AS CAP 151 | 0b0011101, // 111 'o' 152 | 0b1100111, // 112 'p' SAME AS CAP 153 | 0b1110011, // 113 'q' SAME AS CAP 154 | 0b0000101, // 114 'r' SAME AS CAP 155 | 0b1011011, // 115 's' SAME AS CAP 156 | 0b0001111, // 116 't' SAME AS CAP 157 | 0b0011100, // 117 'u' 158 | 0b0000000, // 118 'b' NO DISPLAY 159 | 0b0000000, // 119 'w' NO DISPLAY 160 | 0b0000000, // 120 'x' NO DISPLAY 161 | 0b0000000, // 121 'y' NO DISPLAY 162 | 0b0000000, // 122 'z' NO DISPLAY 163 | 0b0000000, // 123 '0b' NO DISPLAY 164 | 0b0000000, // 124 '|' NO DISPLAY 165 | 0b0000000, // 125 ',' NO DISPLAY 166 | 0b0000000, // 126 '~' NO DISPLAY 167 | 0b0000000, // 127 'DEL' NO DISPLAY 168 | 169 | SHT15 code based on the code found at Wiring.org 170 | http://wiring.org.co/learning/basics/humiditytemperaturesht15.html 171 | 172 | */ 173 | 174 | 175 | #include "SevSeg.h" 176 | 177 | //Create an instance of the object. 178 | SevSeg myDisplay; 179 | 180 | int temperatureCommand = B00000011; // command used to read temperature 181 | int humidityCommand = B00000101; // command used to read humidity 182 | 183 | int clockPin = A5; // pin used for clock 184 | int dataPin = A4; // pin used for data 185 | int ack; // track acknowledgment for errors 186 | int val; 187 | float tempF; 188 | float humidity; 189 | float tempC; 190 | 191 | char tempString[5]; 192 | //------------------------------------------------------------------------------------------- 193 | void setup() 194 | { 195 | int displayType = COMMON_CATHODE; //Your display is either common cathode or common anode 196 | 197 | //This pinout is for a bubble dispaly 198 | //Declare what pins are connected to the GND pins (cathodes) 199 | int digit1 = 8; //Pin 1 200 | int digit2 = 5; //Pin 10 201 | int digit3 = 11; //Pin 4 202 | int digit4 = 13; //Pin 6 203 | 204 | //Declare what pins are connected to the segments (anodes) 205 | int segA = 7; //Pin 12 206 | int segB = 6; //Pin 11 207 | int segC = 10; //Pin 3 208 | int segD = 3; //Pin 8 209 | int segE = 9; //Pin 2 210 | int segF = 4; //Pin 9 211 | int segG = 2; //Pin 7 212 | int segDP= 12; //Pin 5 213 | 214 | int numberOfDigits = 4; //Do you have a 1, 2 or 4 digit display? 215 | 216 | myDisplay.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP); 217 | 218 | myDisplay.SetBrightness(100); //Set the display to 100% brightness level 219 | } 220 | //------------------------------------------------------------------------------------------- 221 | void loop() 222 | { 223 | 224 | sht15(); 225 | clear(); 226 | for(int i =0;i<500;i++) 227 | { 228 | tempString[0] = 'T'; 229 | tempString[1] = 'F'; 230 | 231 | myDisplay.DisplayString(tempString, 0); 232 | 233 | sprintf(tempString, "%4d", (long)tempF, DEC); 234 | myDisplay.DisplayString(tempString, 0); 235 | } 236 | clear(); 237 | for(int i =0;i<500;i++) 238 | { 239 | tempString[0] = 'R'; 240 | tempString[1] = 'H'; 241 | 242 | myDisplay.DisplayString(tempString, 0); 243 | 244 | sprintf(tempString, "%4d", (long)humidity, DEC); 245 | myDisplay.DisplayString(tempString, 0); 246 | } 247 | } 248 | //------------------------------------------------------------------------------------------- 249 | void clear() 250 | { 251 | //write a non-displayable character to each position to clear the display 252 | tempString[0] = 'm'; 253 | tempString[1] = 'm'; 254 | tempString[2] = 'm'; 255 | tempString[3] = 'm'; 256 | 257 | myDisplay.DisplayString(tempString, 0); 258 | } 259 | //------------------------------------------------------------------------------------------- 260 | int sht15() 261 | { 262 | // read the temperature and convert it to centigrades 263 | sendCommandSHT(temperatureCommand, dataPin, clockPin); 264 | waitForResultSHT(dataPin); 265 | val = getData16SHT(dataPin, clockPin); 266 | skipCrcSHT(dataPin, clockPin); 267 | tempC = (float)val * 0.01 - 40; 268 | tempF = (float)tempC * 1.8 + 32; 269 | 270 | //Serial.print("Temperature: "); 271 | //Serial.print((long)tempF, DEC); 272 | //Serial.print("_"); 273 | //Serial.print((char)176); 274 | //Serial.print("F "); 275 | 276 | // read the humidity 277 | sendCommandSHT(humidityCommand, dataPin, clockPin); 278 | waitForResultSHT(dataPin); 279 | val = getData16SHT(dataPin, clockPin); 280 | skipCrcSHT(dataPin, clockPin); 281 | humidity = -4.0 + 0.0405 * val + -0.0000028 * val * val; 282 | 283 | //Serial.print(" Relative Humidity: "); 284 | //Serial.print((long)humidity, DEC); 285 | //Serial.println("%"); 286 | //delay(1000); // wait for 3 sec for next reading 287 | return tempF, tempC, humidity; 288 | } 289 | 290 | 291 | // commands for reading/sending data to a SHTx sensor 292 | 293 | int shiftIn(int dataPin, int clockPin, int numBits) { 294 | int ret = 0; 295 | 296 | for (int i=0; i' NO DISPLAY 98 | 0b0000000, // 63 '?' NO DISPLAY 99 | 0b0000000, // 64 '@' NO DISPLAY 100 | 0b1110111, // 65 'A' 101 | 0b0011111, // 66 'B' 102 | 0b1001110, // 67 'C' 103 | 0b0111101, // 68 'D' 104 | 0b1001111, // 69 'E' 105 | 0b1000111, // 70 'F' 106 | 0b1011110, // 71 'G' 107 | 0b0110111, // 72 'H' 108 | 0b0110000, // 73 'I' 109 | 0b0111000, // 74 'J' 110 | 0b0000000, // 75 'K' NO DISPLAY 111 | 0b0001110, // 76 'L' 112 | 0b0000000, // 77 'M' NO DISPLAY 113 | 0b0010101, // 78 'N' 114 | 0b1111110, // 79 'O' 115 | 0b1101111, // 80 'P' 116 | 0b1110011, // 81 'Q' 117 | 0b0000101, // 82 'R' 118 | 0b1011011, // 83 'S' 119 | 0b0001111, // 84 'T' 120 | 0b0111110, // 85 'U' 121 | 0b0000000, // 86 'V' NO DISPLAY 122 | 0b0000000, // 87 'W' NO DISPLAY 123 | 0b0000000, // 88 'X' NO DISPLAY 124 | 0b0111011, // 89 'Y' 125 | 0b0000000, // 90 'Z' NO DISPLAY 126 | 0b1001110, // 91 '[' 127 | 0b0000000, // 92 '\' NO DISPLAY 128 | 0b1111000, // 93 ']' 129 | 0b0000000, // 94 '^' NO DISPLAY 130 | 0b0001000, // 95 '_' 131 | 0b0000010, // 96 '`' 132 | 0b1110111, // 97 'a' SAME AS CAP 133 | 0b0011111, // 98 'b' SAME AS CAP 134 | 0b0001101, // 99 'c' 135 | 0b0111101, // 100 'd' SAME AS CAP 136 | 0b1101111, // 101 'e' 137 | 0b1000111, // 102 'f' SAME AS CAP 138 | 0b1011110, // 103 'g' SAME AS CAP 139 | 0b0010111, // 104 'h' 140 | 0b0010000, // 105 'i' 141 | 0b0111000, // 106 'j' SAME AS CAP 142 | 0b0000000, // 107 'k' NO DISPLAY 143 | 0b0110000, // 108 'l' 144 | 0b0000000, // 109 'm' NO DISPLAY 145 | 0b0010101, // 110 'n' SAME AS CAP 146 | 0b0011101, // 111 'o' 147 | 0b1100111, // 112 'p' SAME AS CAP 148 | 0b1110011, // 113 'q' SAME AS CAP 149 | 0b0000101, // 114 'r' SAME AS CAP 150 | 0b1011011, // 115 's' SAME AS CAP 151 | 0b0001111, // 116 't' SAME AS CAP 152 | 0b0011100, // 117 'u' 153 | 0b0000000, // 118 'b' NO DISPLAY 154 | 0b0000000, // 119 'w' NO DISPLAY 155 | 0b0000000, // 120 'x' NO DISPLAY 156 | 0b0000000, // 121 'y' NO DISPLAY 157 | 0b0000000, // 122 'z' NO DISPLAY 158 | 0b0000000, // 123 '0b' NO DISPLAY 159 | 0b0000000, // 124 '|' NO DISPLAY 160 | 0b0000000, // 125 ',' NO DISPLAY 161 | 0b0000000, // 126 '~' NO DISPLAY 162 | 0b0000000, // 127 'DEL' NO DISPLAY 163 | */ 164 | 165 | #include "SevSeg.h" 166 | 167 | //Create an instance of the object. 168 | SevSeg myDisplay; 169 | 170 | //Create global variables 171 | unsigned long timer; 172 | int deciSecond = 0; 173 | 174 | void setup() 175 | { 176 | 177 | int displayType = COMMON_CATHODE; //Your display is either common cathode or common anode 178 | 179 | 180 | //This pinout is for a bubble dispaly 181 | //Declare what pins are connected to the GND pins (cathodes) 182 | int digit1 = 8; //Pin 1 183 | int digit2 = 5; //Pin 10 184 | int digit3 = 11; //Pin 4 185 | int digit4 = 13; //Pin 6 186 | 187 | //Declare what pins are connected to the segments (anodes) 188 | int segA = 7; //Pin 12 189 | int segB = 6; //Pin 11 190 | int segC = 10; //Pin 3 191 | int segD = 3; //Pin 8 192 | int segE = 9; //Pin 2 193 | int segF = 4; //Pin 9 194 | int segG = 2; //Pin 7 195 | int segDP= 12; //Pin 5 196 | 197 | int numberOfDigits = 4; //Do you have a 1, 2 or 4 digit display? 198 | 199 | myDisplay.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP); 200 | 201 | myDisplay.SetBrightness(100); //Set the display to 100% brightness level 202 | 203 | timer = millis(); 204 | } 205 | 206 | void loop() 207 | { 208 | char tempString[5] = {'C','O','D','E'}; //Used for sprintf 209 | 210 | for(int i =0;i<100;i++) 211 | { 212 | 213 | myDisplay.DisplayString(tempString, 0); //(numberToDisplay, decimal point location) 214 | 215 | delay(10); 216 | } 217 | 218 | for(int i =0;i<100;i++) 219 | { 220 | tempString[0] = 58; 221 | tempString[1] = 'I'; 222 | tempString[2] = 'S'; 223 | tempString[3] = 58; 224 | 225 | myDisplay.DisplayString(tempString, 0); 226 | 227 | delay(10); 228 | } 229 | for(int i =0;i<100;i++) 230 | { 231 | tempString[0] = 'C'; 232 | tempString[1] = 'O'; 233 | tempString[2] = 'O'; 234 | tempString[3] = 'L'; 235 | 236 | myDisplay.DisplayString(tempString, 0); 237 | 238 | delay(10); 239 | } 240 | 241 | } 242 | 243 | -------------------------------------------------------------------------------- /examples/Example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sparkfun/SevSeg/aeb5fcd281cbf81d700f4232cc060736e6137b6a/examples/Example.jpg -------------------------------------------------------------------------------- /examples/SevSeg_Counter/SevSeg_Counter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 7-23-2012 3 | Spark Fun Electronics 4 | Nathan Seidle 5 | 6 | This code is originally based Dean Reading's Library deanreading@hotmail.com 7 | http://arduino.cc/playground/Main/SevenSegmentLibrary 8 | He didn't have a license on it so I hope he doesn't mind me making it public domain: 9 | This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 10 | 11 | This example is a centi-second counter to demonstrate the use of the SevSeg library. To light 12 | the display you have to call myDisplay.DisplayNumber(#, decimalPlace) multiple times a second. Put this 13 | in the main loop. 14 | 15 | SparkFun has a large, 1" 7-segment display that has four digits. 16 | https://www.sparkfun.com/products/11408 17 | Looking at the display like this: 8.8.8.8. pin 1 is on the lower row, starting from the left. 18 | Pin 12 is the top row, upper left pin. 19 | 20 | Pinout: 21 | 1: Segment E 22 | 2: Segment D 23 | 3: Segment DP 24 | 4: Segment C 25 | 5: Segment G 26 | 6: Digit 4 27 | 7: Segment B 28 | 8: Digit 3 29 | 9: Digit 2 30 | 10: Segment F 31 | 11: Segment A 32 | 12: Digit 1 33 | 34 | ToDo: 35 | Picture of setup with pin 1 indicator 36 | Covert big byte array to binary: http://arduino.cc/forum/index.php/topic,39760.0.html 37 | Measure current going through limiting resistors to make sure we're getting 20mA per segment per digit (should be 80mA for four digits) 38 | 39 | 2264 bytes 40 | 2134 bytes with new BigTime functions 41 | 2214 if full DP support 42 | 43 | */ 44 | 45 | #include "SevSeg.h" 46 | 47 | //Create an instance of the object. 48 | SevSeg myDisplay; 49 | 50 | //Create global variables 51 | unsigned long timer; 52 | int deciSecond = 0; 53 | 54 | void setup() 55 | { 56 | 57 | int displayType = COMMON_CATHODE; //Your display is either common cathode or common anode 58 | 59 | /* 60 | //This pinout is for a regular display 61 | //Declare what pins are connected to the digits 62 | int digit1 = 2; //Pin 12 on my 4 digit display 63 | int digit2 = 3; //Pin 9 on my 4 digit display 64 | int digit3 = 4; //Pin 8 on my 4 digit display 65 | int digit4 = 5; //Pin 6 on my 4 digit display 66 | 67 | //Declare what pins are connected to the segments 68 | int segA = 6; //Pin 11 on my 4 digit display 69 | int segB = 7; //Pin 7 on my 4 digit display 70 | int segC = 8; //Pin 4 on my 4 digit display 71 | int segD = 9; //Pin 2 on my 4 digit display 72 | int segE = 10; //Pin 1 on my 4 digit display 73 | int segF = 11; //Pin 10 on my 4 digit display 74 | int segG = 12; //Pin 5 on my 4 digit display 75 | int segDP= 13; //Pin 3 on my 4 digit display 76 | */ 77 | 78 | //This pinout is for OpenSegment PCB layout 79 | //Declare what pins are connected to the digits 80 | int digit1 = 9; //Pin 12 on my 4 digit display 81 | int digit2 = 16; //Pin 9 on my 4 digit display 82 | int digit3 = 17; //Pin 8 on my 4 digit display 83 | int digit4 = 3; //Pin 6 on my 4 digit display 84 | 85 | //Declare what pins are connected to the segments 86 | int segA = 14; //Pin 11 on my 4 digit display 87 | int segB = 2; //Pin 7 on my 4 digit display 88 | int segC = 8; //Pin 4 on my 4 digit display 89 | int segD = 6; //Pin 2 on my 4 digit display 90 | int segE = 7; //Pin 1 on my 4 digit display 91 | int segF = 15; //Pin 10 on my 4 digit display 92 | int segG = 4; //Pin 5 on my 4 digit display 93 | int segDP= 5; //Pin 3 on my 4 digit display 94 | 95 | int numberOfDigits = 4; //Do you have a 1, 2 or 4 digit display? 96 | 97 | myDisplay.Begin(displayType, numberOfDigits, digit1, digit2, digit3, digit4, segA, segB, segC, segD, segE, segF, segG, segDP); 98 | 99 | myDisplay.SetBrightness(100); //Set the display to 100% brightness level 100 | 101 | timer = millis(); 102 | } 103 | 104 | void loop() 105 | { 106 | //Example ways of displaying a decimal number 107 | char tempString[10]; //Used for sprintf 108 | sprintf(tempString, "%4d", deciSecond); //Convert deciSecond into a string that is right adjusted 109 | //sprintf(tempString, "%d", deciSecond); //Convert deciSecond into a string that is left adjusted 110 | //sprintf(tempString, "%04d", deciSecond); //Convert deciSecond into a string with leading zeros 111 | //sprintf(tempString, "%4d", deciSecond * -1); //Shows a negative sign infront of right adjusted number 112 | //sprintf(tempString, "%4X", deciSecond); //Count in HEX, right adjusted 113 | 114 | //Produce an output on the display 115 | myDisplay.DisplayString(tempString, 3); //(numberToDisplay, decimal point location) 116 | 117 | //Other examples 118 | //myDisplay.DisplayString(tempString, 0); //Display string, no decimal point 119 | //myDisplay.DisplayString("-23b", 3); //Display string, decimal point in third position 120 | 121 | //Check if 10ms has elapsed 122 | if (millis() - timer >= 100) 123 | { 124 | timer = millis(); 125 | deciSecond++; 126 | } 127 | 128 | delay(5); 129 | } 130 | 131 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | SevSeg KEYWORD1 2 | NewNum KEYWORD2 3 | PrintOutput KEYWORD2 4 | COMMON_CATHODE LITERAL1 5 | COMMON_ANODE LITERAL1 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=SevSeg 2 | version=1.0.2 3 | author=SparkFun Electronics 4 | maintainer=SparkFun Electronics 5 | sentence=Seven Segment library for Arduino 6 | paragraph=Seven Segment library for Arduino 7 | category=Display 8 | url=https://github.com/sparkfun/SevSeg 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/SevSeg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This library allows an Arduino to easily display numbers and characters on a 4 digit 7-segment 3 | display without a separate 7-segment display controller. 4 | 5 | If you have feature suggestions or need support please use the github support page: https://github.com/sparkfun/SevSeg 6 | 7 | Original Library by Dean Reading (deanreading@hotmail.com: http://arduino.cc/playground/Main/SevenSegmentLibrary), 2012 8 | Improvements by Nathan Seidle, 2012 9 | 10 | Now works for any digital pin arrangement, common anode and common cathode displays. 11 | Added character support including letters A-F and many symbols. 12 | 13 | Hardware Setup: 4 digit 7 segment displays use 12 digital pins. You may need more pins if your display has colons or 14 | apostrophes. 15 | 16 | There are 4 digit pins and 8 segment pins. Digit pins are connected to the cathodes for common cathode displays, or anodes 17 | for common anode displays. 8 pins control the individual segments (seven segments plus the decimal point). 18 | 19 | Connect the four digit pins with four limiting resistors in series to any digital or analog pins. Connect the eight segment 20 | pins to any digital or analog pins (no limiting resistors needed). See the SevSeg example for more connection information. 21 | 22 | SparkFun has a large, 1" 7-segment display that has four digits. 23 | https://www.sparkfun.com/products/11408 24 | Looking at the display like this: 8.8.8.8. pin 1 is on the lower row, starting from the left. 25 | Pin 12 is the top row, upper left pin. 26 | 27 | Pinout: 28 | 1: Segment E 29 | 2: Segment D 30 | 3: Segment DP 31 | 4: Segment C 32 | 5: Segment G 33 | 6: Digit 4 34 | 7: Segment B 35 | 8: Digit 3 36 | 9: Digit 2 37 | 10: Segment F 38 | 11: Segment A 39 | 12: Digit 1 40 | 41 | 42 | Software: 43 | Call SevSeg.Begin in setup. 44 | The first argument (boolean) tells whether the display is common cathode (0) or common 45 | anode (1). 46 | The next four arguments (bytes) tell the library which arduino pins are connected to 47 | the digit pins of the seven segment display. Put them in order from left to right. 48 | The next eight arguments (bytes) tell the library which arduino pins are connected to 49 | the segment pins of the seven segment display. Put them in order a to g then the dp. 50 | 51 | In summary, Begin(type, digit pins 1-4, segment pins a-g, dp) 52 | 53 | The calling program must run the DisplayString() function repeatedly to get the number displayed. 54 | Any number between -999 and 9999 can be displayed. 55 | To move the decimal place one digit to the left, use '1' as the second 56 | argument. For example, if you wanted to display '3.141' you would call 57 | myDisplay.DisplayString("3141", 1); 58 | 59 | 60 | */ 61 | 62 | #include "SevSeg.h" 63 | 64 | SevSeg::SevSeg() 65 | { 66 | //Initial values 67 | DecAposColon = 0; //This variable tracks the decimal place, apostrophe, and colon (if the display has support) 68 | 69 | } 70 | void SevSeg::Begin(boolean mode_in, byte numOfDigits, 71 | byte dig1, byte dig2, byte dig3, byte dig4, 72 | byte digitCol, byte digitApos, 73 | byte segA, byte segB, byte segC, byte segD, byte segE, byte segF, byte segG, 74 | byte segDP, 75 | byte segCol, byte segApos) 76 | { 77 | //Bring all the variables in from the caller 78 | numberOfDigits = numOfDigits; 79 | digit1 = dig1; 80 | digit2 = dig2; 81 | digit3 = dig3; 82 | digit4 = dig4; 83 | digitApostrophe = digitApos; 84 | digitColon = digitCol; 85 | segmentA = segA; 86 | segmentB = segB; 87 | segmentC = segC; 88 | segmentD = segD; 89 | segmentE = segE; 90 | segmentF = segF; 91 | segmentG = segG; 92 | segmentDP = segDP; 93 | segmentApostrophe = segApos; 94 | segmentColon = segCol; 95 | 96 | //Assign input values to variables 97 | //mode is what the digit pins must be set at for it to be turned on. 0 for common cathode, 1 for common anode 98 | mode = mode_in; 99 | if(mode == COMMON_ANODE) 100 | { 101 | DigitOn = HIGH; 102 | DigitOff = LOW; 103 | SegOn = LOW; 104 | SegOff = HIGH; 105 | } 106 | else 107 | { 108 | DigitOn = LOW; 109 | DigitOff = HIGH; 110 | SegOn = HIGH; 111 | SegOff = LOW; 112 | } 113 | 114 | DigitPins[0] = digit1; 115 | DigitPins[1] = digit2; 116 | DigitPins[2] = digit3; 117 | DigitPins[3] = digit4; 118 | SegmentPins[0] = segmentA; 119 | SegmentPins[1] = segmentB; 120 | SegmentPins[2] = segmentC; 121 | SegmentPins[3] = segmentD; 122 | SegmentPins[4] = segmentE; 123 | SegmentPins[5] = segmentF; 124 | SegmentPins[6] = segmentG; 125 | SegmentPins[7] = segmentDP; 126 | 127 | //Turn everything Off before setting pin as output 128 | //Set all digit pins off. Low for common anode, high for common cathode 129 | for (byte digit = 0 ; digit < numberOfDigits ; digit++) 130 | { 131 | digitalWrite(DigitPins[digit], DigitOff); 132 | pinMode(DigitPins[digit], OUTPUT); 133 | } 134 | //Set all segment pins off. High for common anode, low for common cathode 135 | for (byte seg = 0 ; seg < 8 ; seg++) 136 | { 137 | digitalWrite(SegmentPins[seg], SegOff); 138 | pinMode(SegmentPins[seg], OUTPUT); 139 | } 140 | 141 | if (digitColon != 255) 142 | { 143 | digitalWrite(digitColon, DigitOff); 144 | pinMode(digitColon, OUTPUT); 145 | digitalWrite(segmentColon, SegOff); 146 | pinMode(segmentColon, OUTPUT); 147 | } 148 | if (digitApostrophe != 255) 149 | { 150 | digitalWrite(digitApostrophe, DigitOff); 151 | pinMode(digitApostrophe, OUTPUT); 152 | digitalWrite(segmentApostrophe, SegOff); 153 | pinMode(segmentApostrophe, OUTPUT); 154 | } 155 | } 156 | 157 | //Begin 158 | /*******************************************************************************************/ 159 | //Set pin modes and turns all displays off 160 | //This second begin is used when the display does not support a colon and apostrophe 161 | //The digitApostrophe, segmentApostrophe, and dig/segColon are set to 255 and the normal .Begin is called 162 | void SevSeg::Begin(boolean mode_in, byte numOfDigits, 163 | byte dig1, byte dig2, byte dig3, byte dig4, 164 | byte segA, byte segB, byte segC, byte segD, byte segE, byte segF, byte segG, 165 | byte segDP) 166 | { 167 | Begin(mode_in, numOfDigits, dig1, dig2, dig3, dig4, 255, 255, segA, segB, segC, 168 | segD, segE, segF, segG, segDP, 255, 255); 169 | } 170 | 171 | //Set the display brightness 172 | /*******************************************************************************************/ 173 | //Given a value between 0 and 100 (0% and 100%), set the brightness variable on the display 174 | //We need to error check and map the incoming value 175 | void SevSeg::SetBrightness(byte percentBright) 176 | { 177 | //Error check and scale brightnessLevel 178 | if(percentBright > 100) percentBright = 100; 179 | brightnessDelay = map(percentBright, 0, 100, 0, FRAMEPERIOD); //map brightnessDelay to 0 to the max which is framePeriod 180 | } 181 | 182 | 183 | //Refresh Display 184 | /*******************************************************************************************/ 185 | //Given a string such as "-A32", we display -A32 186 | //Each digit is displayed for ~2000us, and cycles through the 4 digits 187 | //After running through the 4 numbers, the display is turned off 188 | //Will turn the display on for a given amount of time - this helps control brightness 189 | void SevSeg::DisplayString(const char* toDisplay, byte DecAposColon) 190 | { 191 | //For the purpose of this code, digit = 1 is the left most digit, digit = 4 is the right most digit 192 | for(byte digit = 1 ; digit < (numberOfDigits+1) ; digit++) 193 | { 194 | switch(digit) 195 | { 196 | case 1: 197 | digitalWrite(digit1, DigitOn); 198 | break; 199 | case 2: 200 | digitalWrite(digit2, DigitOn); 201 | break; 202 | case 3: 203 | digitalWrite(digit3, DigitOn); 204 | break; 205 | case 4: 206 | digitalWrite(digit4, DigitOn); 207 | break; 208 | //This only currently works for 4 digits 209 | } 210 | 211 | //Here we access the array of segments 212 | //This could be cleaned up a bit but it works 213 | //displayCharacter(toDisplay[digit-1]); //Now display this digit 214 | // displayArray (defined in SevSeg.h) decides which segments are turned on for each number or symbol 215 | unsigned char characterToDisplay = toDisplay[digit-1]; 216 | if (characterToDisplay & 0x80) // bit 7 enables bit-per-segment control 217 | { // Each bit of characterToDisplay turns on a single segment (from A-to-G) 218 | if (characterToDisplay & 0x01) digitalWrite(segmentA, SegOn); 219 | if (characterToDisplay & 0x02) digitalWrite(segmentB, SegOn); 220 | if (characterToDisplay & 0x04) digitalWrite(segmentC, SegOn); 221 | if (characterToDisplay & 0x08) digitalWrite(segmentD, SegOn); 222 | if (characterToDisplay & 0x10) digitalWrite(segmentE, SegOn); 223 | if (characterToDisplay & 0x20) digitalWrite(segmentF, SegOn); 224 | if (characterToDisplay & 0x40) digitalWrite(segmentG, SegOn); 225 | } 226 | else 227 | { 228 | const uint8_t chr = pgm_read_byte(&characterArray[characterToDisplay]); 229 | if (chr & (1<<6)) digitalWrite(segmentA, SegOn); 230 | if (chr & (1<<5)) digitalWrite(segmentB, SegOn); 231 | if (chr & (1<<4)) digitalWrite(segmentC, SegOn); 232 | if (chr & (1<<3)) digitalWrite(segmentD, SegOn); 233 | if (chr & (1<<2)) digitalWrite(segmentE, SegOn); 234 | if (chr & (1<<1)) digitalWrite(segmentF, SegOn); 235 | if (chr & (1<<0)) digitalWrite(segmentG, SegOn); 236 | } 237 | //Service the decimal point, apostrophe and colon 238 | if ((DecAposColon & (1<<(digit-1))) && (digit < 5)) //Test DecAposColon to see if we need to turn on a decimal point 239 | digitalWrite(segmentDP, SegOn); 240 | 241 | delayMicroseconds(brightnessDelay + 1); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good) 242 | //The + 1 is a bit of a hack but it removes the possible zero display (0 causes display to become bright and flickery) 243 | //If you set this too long, the display will start to flicker. Set it to 25000 for some fun. 244 | 245 | //Turn off all segments 246 | digitalWrite(segmentA, SegOff); 247 | digitalWrite(segmentB, SegOff); 248 | digitalWrite(segmentC, SegOff); 249 | digitalWrite(segmentD, SegOff); 250 | digitalWrite(segmentE, SegOff); 251 | digitalWrite(segmentF, SegOff); 252 | digitalWrite(segmentG, SegOff); 253 | digitalWrite(segmentDP, SegOff); 254 | 255 | //Turn off this digit 256 | switch(digit) 257 | { 258 | case 1: 259 | digitalWrite(digit1, DigitOff); 260 | break; 261 | case 2: 262 | digitalWrite(digit2, DigitOff); 263 | break; 264 | case 3: 265 | digitalWrite(digit3, DigitOff); 266 | break; 267 | case 4: 268 | digitalWrite(digit4, DigitOff); 269 | break; 270 | //This only currently works for 4 digits 271 | } 272 | // The display is on for microSeconds(brightnessLevel + 1), now turn off for the remainder of the framePeriod 273 | delayMicroseconds(FRAMEPERIOD - brightnessDelay + 1); //the +1 is a hack so that we can never have a delayMicroseconds(0), causes display to flicker 274 | } 275 | 276 | //After we've gone through the digits, we control the colon and apostrophe (if the display supports it) 277 | 278 | //Turn on the colon and/or apostrophe 279 | if ((digitColon != 255) || (digitApostrophe != 255)) 280 | { 281 | if (DecAposColon & (1<<4)) //Test to see if we need to turn on the Colon 282 | { 283 | digitalWrite(digitColon, DigitOn); 284 | digitalWrite(segmentColon, SegOn); 285 | } 286 | if (DecAposColon & (1<<5)) //Test DecAposColon to see if we need to turn on Apostrophe 287 | { 288 | digitalWrite(digitApostrophe, DigitOn); 289 | digitalWrite(segmentApostrophe, SegOn); 290 | } 291 | delayMicroseconds(brightnessDelay + 1); //Display this digit for a fraction of a second (between 1us and 5000us, 500-2000 is pretty good) 292 | 293 | //Turn off the colon and/or apostrophe 294 | digitalWrite(digitColon, DigitOff); 295 | digitalWrite(segmentColon, SegOff); 296 | digitalWrite(digitApostrophe, DigitOff); 297 | digitalWrite(segmentApostrophe, SegOff); 298 | delayMicroseconds(FRAMEPERIOD - brightnessDelay + 1); //the +1 is a hack so that we can never have a delayMicroseconds(0), causes display to flicker 299 | } 300 | 301 | } 302 | -------------------------------------------------------------------------------- /src/SevSeg.h: -------------------------------------------------------------------------------- 1 | //Written by Dean Reading, 2012. deanreading@hotmail.com 2 | //See .cpp file for info 3 | 4 | #ifndef SevSeg_h 5 | #define SevSeg_h 6 | 7 | #if defined(ARDUINO) && ARDUINO >= 100 8 | #include "Arduino.h" 9 | #else 10 | #include "WProgram.h" 11 | #endif 12 | 13 | #include 14 | 15 | #define COMMON_CATHODE 0 16 | #define COMMON_ANODE 1 17 | 18 | #define BLANK 16 //Special character that turns off all segments (we chose 16 as it is the first spot that has this) 19 | 20 | // framePeriod controls the length of time between display refreshes 21 | // It's also closely linked to the brightness setting 22 | #define FRAMEPERIOD 2000 23 | //Total amount of time (in microseconds) for the display frame. 1,000us is roughly 1000Hz update rate 24 | //A framePeriod of: 25 | //5000 is flickery 26 | //3000 has good low brightness vs full brightness 27 | //2000 works well 28 | //500 seems like the low brightness is pretty bright, not great 29 | 30 | 31 | //This is the combined array that contains all the segment configurations for many different characters and symbols 32 | const uint8_t characterArray[] PROGMEM = { 33 | // ABCDEFG Segments 7-segment map: 34 | 0b1111110, // 0 "0" AAA 35 | 0b0110000, // 1 "1" F B 36 | 0b1101101, // 2 "2" F B 37 | 0b1111001, // 3 "3" GGG 38 | 0b0110011, // 4 "4" E C 39 | 0b1011011, // 5 "5" E C 40 | 0b1011111, // 6 "6" DDD 41 | 0b1110000, // 7 "7" 42 | 0b1111111, // 8 "8" 43 | 0b1111011, // 9 "9" 44 | 0b1110111, // 10 "A" 45 | 0b0011111, // 11 "b" 46 | 0b1001110, // 12 "C" 47 | 0b0111101, // 13 "d" 48 | 0b1001111, // 14 "E" 49 | 0b1000111, // 15 "F" 50 | 0b0000000, // 16 NO DISPLAY 51 | 0b0000000, // 17 NO DISPLAY 52 | 0b0000000, // 18 NO DISPLAY 53 | 0b0000000, // 19 NO DISPLAY 54 | 0b0000000, // 20 NO DISPLAY 55 | 0b0000000, // 21 NO DISPLAY 56 | 0b0000000, // 22 NO DISPLAY 57 | 0b0000000, // 23 NO DISPLAY 58 | 0b0000000, // 24 NO DISPLAY 59 | 0b0000000, // 25 NO DISPLAY 60 | 0b0000000, // 26 NO DISPLAY 61 | 0b0000000, // 27 NO DISPLAY 62 | 0b0000000, // 28 NO DISPLAY 63 | 0b0000000, // 29 NO DISPLAY 64 | 0b0000000, // 30 NO DISPLAY 65 | 0b0000000, // 31 NO DISPLAY 66 | 0b0000000, // 32 ' ' 67 | 0b0000000, // 33 '!' NO DISPLAY 68 | 0b0100010, // 34 '"' 69 | 0b0000000, // 35 '#' NO DISPLAY 70 | 0b0000000, // 36 '$' NO DISPLAY 71 | 0b0000000, // 37 '%' NO DISPLAY 72 | 0b0000000, // 38 '&' NO DISPLAY 73 | 0b0100000, // 39 ''' 74 | 0b1001110, // 40 '(' 75 | 0b1111000, // 41 ')' 76 | 0b0000000, // 42 '*' NO DISPLAY 77 | 0b0000000, // 43 '+' NO DISPLAY 78 | 0b0000100, // 44 ',' 79 | 0b0000001, // 45 '-' 80 | 0b0000000, // 46 '.' NO DISPLAY 81 | 0b0000000, // 47 '/' NO DISPLAY 82 | 0b1111110, // 48 '0' 83 | 0b0110000, // 49 '1' 84 | 0b1101101, // 50 '2' 85 | 0b1111001, // 51 '3' 86 | 0b0110011, // 52 '4' 87 | 0b1011011, // 53 '5' 88 | 0b1011111, // 54 '6' 89 | 0b1110000, // 55 '7' 90 | 0b1111111, // 56 '8' 91 | 0b1111011, // 57 '9' 92 | 0b0000000, // 58 ':' NO DISPLAY 93 | 0b0000000, // 59 ';' NO DISPLAY 94 | 0b0000000, // 60 '<' NO DISPLAY 95 | 0b0000000, // 61 '=' NO DISPLAY 96 | 0b0000000, // 62 '>' NO DISPLAY 97 | 0b0000000, // 63 '?' NO DISPLAY 98 | 0b0000000, // 64 '@' NO DISPLAY 99 | 0b1110111, // 65 'A' 100 | 0b0011111, // 66 'b' 101 | 0b1001110, // 67 'C' 102 | 0b0111101, // 68 'd' 103 | 0b1001111, // 69 'E' 104 | 0b1000111, // 70 'F' 105 | 0b1011110, // 71 'G' 106 | 0b0110111, // 72 'H' 107 | 0b0110000, // 73 'I' 108 | 0b0111000, // 74 'J' 109 | 0b0000000, // 75 'K' NO DISPLAY 110 | 0b0001110, // 76 'L' 111 | 0b0000000, // 77 'M' NO DISPLAY 112 | 0b0010101, // 78 'n' 113 | 0b1111110, // 79 'O' 114 | 0b1100111, // 80 'P' 115 | 0b1110011, // 81 'q' 116 | 0b0000101, // 82 'r' 117 | 0b1011011, // 83 'S' 118 | 0b0001111, // 84 't' 119 | 0b0111110, // 85 'U' 120 | 0b0000000, // 86 'V' NO DISPLAY 121 | 0b0000000, // 87 'W' NO DISPLAY 122 | 0b0000000, // 88 'X' NO DISPLAY 123 | 0b0111011, // 89 'y' 124 | 0b0000000, // 90 'Z' NO DISPLAY 125 | 0b1001110, // 91 '[' 126 | 0b0000000, // 92 '\' NO DISPLAY 127 | 0b1111000, // 93 ']' 128 | 0b0000000, // 94 '^' NO DISPLAY 129 | 0b0001000, // 95 '_' 130 | 0b0000010, // 96 '`' 131 | 0b1110111, // 97 'a' SAME AS CAP 132 | 0b0011111, // 98 'b' SAME AS CAP 133 | 0b0001101, // 99 'c' 134 | 0b0111101, // 100 'd' SAME AS CAP 135 | 0b1101111, // 101 'e' 136 | 0b1000111, // 102 'F' SAME AS CAP 137 | 0b1011110, // 103 'G' SAME AS CAP 138 | 0b0010111, // 104 'h' 139 | 0b0010000, // 105 'i' 140 | 0b0111000, // 106 'j' SAME AS CAP 141 | 0b0000000, // 107 'k' NO DISPLAY 142 | 0b0110000, // 108 'l' 143 | 0b0000000, // 109 'm' NO DISPLAY 144 | 0b0010101, // 110 'n' SAME AS CAP 145 | 0b0011101, // 111 'o' 146 | 0b1100111, // 112 'p' SAME AS CAP 147 | 0b1110011, // 113 'q' SAME AS CAP 148 | 0b0000101, // 114 'r' SAME AS CAP 149 | 0b1011011, // 115 'S' SAME AS CAP 150 | 0b0001111, // 116 't' SAME AS CAP 151 | 0b0011100, // 117 'u' 152 | 0b0000000, // 118 'b' NO DISPLAY 153 | 0b0000000, // 119 'w' NO DISPLAY 154 | 0b0000000, // 120 'x' NO DISPLAY 155 | 0b0000000, // 121 'y' NO DISPLAY 156 | 0b0000000, // 122 'z' NO DISPLAY 157 | 0b0000000, // 123 '0b' NO DISPLAY 158 | 0b0000000, // 124 '|' NO DISPLAY 159 | 0b0000000, // 125 ',' NO DISPLAY 160 | 0b0000000, // 126 '~' NO DISPLAY 161 | 0b0000000, // 127 'DEL' NO DISPLAY 162 | }; 163 | 164 | 165 | class SevSeg { 166 | 167 | public: 168 | SevSeg(); 169 | 170 | //Public Functions 171 | void DisplayString(const char*, byte); 172 | // void NewNumber(int number_in, byte DecPlace_in); 173 | void Begin(boolean mode_in, byte numOfDigits, byte digit1, byte digit2, byte digit3, byte digit4, byte segment1, byte segment2, byte segment3, byte segment4, byte segment5, byte segment6, byte segment7, byte segmentDP); 174 | void Begin(boolean mode_in, byte numOfDigits, byte digit1, byte digit2, byte digit3, byte digit4, byte digitColon, byte digitApostrophe, byte segment1, byte segment2, byte segment3, byte segment4, byte segment5, byte segment6, byte segment7, byte segmentDP, byte segmentColon, byte segmentApostrophe); 175 | void SetBrightness(byte percentBright); 176 | 177 | //Public Variables 178 | 179 | private: 180 | //Private Functions 181 | void displayCharacter(byte characterToDisplay); //Illuminates the correct segments 182 | void SplitNumber(int); 183 | 184 | //Private Variables 185 | boolean mode, DigitOn, DigitOff, SegOn, SegOff; 186 | 187 | byte digit1, digit2, digit3, digit4; 188 | byte digitApostrophe, digitColon, segmentApostrophe, segmentColon; 189 | byte segmentA, segmentB, segmentC, segmentD, segmentE, segmentF, segmentG, segmentDP; 190 | 191 | byte numberOfDigits; 192 | 193 | unsigned int brightnessDelay; 194 | 195 | byte DigitPins[4]; 196 | byte SegmentPins[8]; 197 | boolean lights[4][8]; 198 | byte nums[4]; 199 | 200 | byte DecAposColon; 201 | }; 202 | 203 | #endif 204 | 205 | --------------------------------------------------------------------------------