├── .gitignore ├── Simple7SegmentLed.png ├── keywords.txt ├── 7SegmentLed_Pinlayout.png ├── README.txt ├── Soda.h ├── README.md ├── LICENSE ├── examples ├── SodaDemo │ └── SodaDemo.ino └── SodaSerial │ └── SodaSerial.ino └── Soda.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build-tmp/ 3 | *.sublime-workspace 4 | *.sublime-project 5 | -------------------------------------------------------------------------------- /Simple7SegmentLed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raster/Soda/master/Simple7SegmentLed.png -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | Soda KEYWORD1 2 | pins KEYWORD2 3 | write KEYWORD2 4 | setDecimalState KEYWORD2 -------------------------------------------------------------------------------- /7SegmentLed_Pinlayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/raster/Soda/master/7SegmentLed_Pinlayout.png -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This library was made by Quin, the head engineer at Qtechknow. I made this specifically for using with 7-segment displays. Share, distribute, and edit for your specific uses. This is an open-source library. 2 | 3 | Functions: 4 | 5 | Soda soda; 6 | Initiates the library. 7 | 8 | soda.pins(int a, int b, int c, int d, int e, int f, int g, int dp); 9 | Declares and sets up the pins. 10 | 11 | soda.write(int number); 12 | Lights up int number on the 7-Segment display. 13 | 14 | soda.setDecimalPoint(int digit, boolean decimalState); 15 | Sets the decimal point of int digit to boolean decimalState. -------------------------------------------------------------------------------- /Soda.h: -------------------------------------------------------------------------------- 1 | #ifndef Soda_h 2 | #define Soda_h 3 | 4 | #if ARDUINO >= 100 // Arduino 1.0 and 0023 compatible! 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | class Soda 11 | { 12 | public: 13 | void pins(int a, int b, int c, int d, int e, int f, int g, int dp, boolean common); 14 | void write(int number); 15 | void setDecimalPoint(int digit, boolean decimalState); 16 | 17 | private: 18 | int _a, _b, _c, _d, _e, _f, _g, _dp, _common; 19 | int _number; 20 | int _digit; 21 | boolean _decimalState; 22 | int segmentPins [8]; 23 | 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Soda 2 | ==== 3 | 4 | A Arduino library for 7 segment LED 5 | 6 | This library was made by [Quin](https://github.com/Qtechknow/Arduino-Libraries), the head engineer at Qtechknow. He made this specifically for using with 7-segment displays. Share, distribute, and edit for your specific uses. This is an open-source library. 7 | 8 | Some edits done by @fabiantheblind 9 | I had to pull it into a new repo for better usage. Also I made some major changes to the usage of the pinlayout. See [Quin's original work here.](https://github.com/Qtechknow/Arduino-Libraries) 10 | 11 | Functions: 12 | 13 | Soda soda; 14 | Initiates the library. 15 | 16 | soda.pins(int a, int b, int c, int d, int e, int f, int g, int dp); 17 | Declares and sets up the pins. 18 | 19 | soda.write(int number); 20 | Lights up int number on the 7-Segment display. 21 | 22 | soda.setDecimalPoint(int digit, boolean decimalState); 23 | Sets the decimal point of int digit to boolean decimalState. 24 | 25 | 26 | Hook the decimal display up like this: 27 | ![](Simple7SegmentLed.png) 28 | ![](7SegmentLed_Pinlayout.png) 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 fabiantheblind 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /examples/SodaDemo/SodaDemo.ino: -------------------------------------------------------------------------------- 1 | /* Soda Demo 2 | 3 | Uses the soda library from Qtechknow. Counts to 9 and then goes back to 0 on 4 | a seven segment display. 5 | 6 | created 14 Apr 12 7 | Made by Quin (Qtechknow) 8 | 9 | Some edits by @fabiantheblind 10 | see: http://www.tinkersoup.de/lcd-oled-e-paper/7-segment-anzeige-led-blue/a-1122/ 11 | see: https://www.sparkfun.com/products/9191 12 | see: http://www.instructables.com/id/Seven-Segment-Display-Tutorial/step3/Testing-The-Display/ 13 | see: http://forum.arduino.cc/index.php/topic,22413.0.html 14 | see Datasheet (Anode pin marking is wrong): https://www.sparkfun.com/datasheets/Components/LED/YSD-160AB3C-8.pdf 15 | 16 | 17 | Libraries: https://github.com/Qtechknow/Arduino-Libraries/tree/master/Soda 18 | my fork: https://github.com/fabiantheblind/Seven-Segment-LED-Arduino-Libraries 19 | 20 | 21 | on the 7 segement LED 22 | Anode Pins are 3 and 8 23 | connect them to 5V 24 | connect the rest of the pins to a resistor and the according pins. 25 | 26 | 7/A 27 | _ 28 | 9/F |_| 6/B 29 | 1/E |_| 4/C . <-- 5/DB (The point) 30 | 31 | 2/D 32 | 33 | And the center bar is the 10/G 34 | 35 | */ 36 | 37 | #include "Soda.h" 38 | 39 | Soda Soda; // initialize the library 40 | 41 | // 8 works right 42 | // 9 works wrong 43 | // |_ 44 | // |_|. 45 | // 46 | 47 | 48 | void setup() { 49 | // Segments A, B, C, D, E, F, G, DP pin numbers 50 | Soda.pins(1, 2, 4, 6, 7, 9, 10, 5, HIGH); // set high for common anode, and 51 | // low for common cathode display 52 | } 53 | 54 | void loop() { 55 | 56 | for(int i=0; i< 9; i++) { 57 | Soda.write(i); // count to 9 58 | delay(1000); // delay for 1 second 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/SodaSerial/SodaSerial.ino: -------------------------------------------------------------------------------- 1 | /* SodaSerial 2 | 3 | When you type in a number between 0 and 9 on the serial monitor, the 7-segment 4 | display, driven by the Soda library, will light up correspondingly. 5 | 6 | created 07 May 2012 7 | made by Qtechknow (Quin) 8 | */ 9 | 10 | #include "Soda.h" 11 | 12 | Soda Soda; // initialize the library 13 | 14 | void setup() { 15 | // Segments A, B, C, D, E, F, G, DP pin numbers 16 | Soda.pins(0, 1, 2, 3, 4, 5, 6, 7, HIGH); // set high for common anode, and 17 | // low for common cathode display 18 | Serial.begin(9600); // start serial communication 19 | } 20 | 21 | void loop() { 22 | if(Serial.available() > 0) { // is there anything on the serial monitor? 23 | char ch = Serial.read(); 24 | 25 | switch (ch) { // start the switch case statement 26 | 27 | case '0': // if we receive a 0, print a 0 28 | Soda.write(0); 29 | break; 30 | 31 | case '1': // if we receive a 1, print a 1 and so on 32 | Soda.write(1); 33 | break; 34 | 35 | case '2': 36 | Soda.write(2); 37 | break; 38 | 39 | case '3': 40 | Soda.write(3); 41 | break; 42 | 43 | case '4': 44 | Soda.write(4); 45 | break; 46 | 47 | case '5': 48 | Soda.write(5); 49 | break; 50 | 51 | case '6': 52 | Soda.write(6); 53 | break; 54 | 55 | case '7': 56 | Soda.write(7); 57 | break; 58 | 59 | case '8': 60 | Soda.write(8); 61 | break; 62 | 63 | case '9': 64 | Soda.write(9); 65 | break; 66 | 67 | default: // default is to clear the display 68 | Soda.clear(); 69 | } 70 | } 71 | delay(1000); // don't go too fast 72 | } 73 | -------------------------------------------------------------------------------- /Soda.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "Soda.h" 3 | 4 | void Soda::pins(int a, int b, int c, int d, int e, int f, int g, int dp, boolean common) { 5 | 6 | _a=a; 7 | _b=b; 8 | _c=c; 9 | _d=d; 10 | _e=e; 11 | _f=f; 12 | _g=g; 13 | _dp=dp; 14 | _common=common; 15 | 16 | segmentPins[0] = _dp; 17 | segmentPins[1] = _g; 18 | segmentPins[2] = _f; 19 | segmentPins[3] = _e; 20 | segmentPins[4] = _d; 21 | segmentPins[5] = _c; 22 | segmentPins[6] = _b; 23 | segmentPins[7] = _a; 24 | 25 | for(int i=0; i < 8; i++) { 26 | 27 | pinMode(segmentPins[i], OUTPUT); 28 | } 29 | } 30 | 31 | void Soda::write(int number) { 32 | 33 | const byte numeral[10] = { 34 | B11111100, // 0 35 | B00110000, // 1 36 | B11011010, // 2 37 | B01111010, // 3 38 | B00110110, // 4 39 | B01101110, // 5 40 | B11101110, // 6 41 | B10001100, // 7 42 | B11111110, // 8 43 | B01111110, // 9 44 | }; 45 | 46 | boolean isBitSet; 47 | 48 | for(int segment=1; segment < 8; segment++) { 49 | if(number < 0 || number > 9) { 50 | isBitSet = 0; 51 | } 52 | else{ 53 | isBitSet = bitRead(numeral[number], segment); 54 | } 55 | isBitSet = ! isBitSet; 56 | digitalWrite(segmentPins[segment], isBitSet); 57 | } 58 | } 59 | 60 | void Soda::setDecimalPoint(int digit, boolean decimalState) { 61 | 62 | _digit=digit; 63 | _decimalState=decimalState; 64 | 65 | if(_digit == 1) { 66 | 67 | if (_decimalState == HIGH && _common == HIGH) { 68 | digitalWrite(_dp, LOW); 69 | } 70 | if (_decimalState == HIGH && _common == LOW) { 71 | digitalWrite(_dp, HIGH); 72 | } 73 | if (_decimalState == LOW && _common == HIGH) { 74 | digitalWrite(_dp, HIGH); 75 | } 76 | if (_decimalState == LOW && _common == LOW) { 77 | digitalWrite(_dp, LOW); 78 | } 79 | } 80 | } --------------------------------------------------------------------------------