Skip to content

Commit

Permalink
MERGE: make it an arduino library;
Browse files Browse the repository at this point in the history
  • Loading branch information
KLszTsu committed Aug 17, 2017
2 parents 6f741bf + 6eb2418 commit 260e3b2
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 43 deletions.
70 changes: 70 additions & 0 deletions examples/counter/counter.ino
@@ -0,0 +1,70 @@
/* Library 4Digit7Seg12Pin by KLsz Studio
* For more info please visit "https://github.com/KuangLei/4Digit7Seg12Pin/"
* This Library is protected under GPLv3, CopyLeft KLsz Studio
*/

#include <fDigitsSegtPin.h>

// Connect the 4 Digit 7 Segment Display to Arduino like this
/* Arduino Pin 33 32 31 30 29 28
* | | | | | |
* Resistor | R R | | R
* | | | | | |
* +------------------+
* Display | 8. 8. 8. 8. |
* +------------------+
* | | | | | |
* Resistor R R R R R |
* | | | | | |
* Arduino Pin 22 23 24 25 26 27
*/
/* FUNCTION: fDigitsSegtPin(Pin1, Pin2, Pin3, Pin4, Pin5, Pin6, Pin7, Pin8, Pin9, Pin10, Pin11, Pin12):
* Usage: Create a Display and set the pins,
Put it before the setup() function;
* Arguments: Pin1~Pin12: (int) 4 Digit 7 segment display's pins from 1 to 12;
*/
fDigitsSegtPin Display(22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33);

void setup() {
// Init and config the display here
/* FUNCTION: begin():
* Usage: Init the Pins,
* Put it in the setup() function;
* PARAMETER: doPrint_lastDot:
* Usage: Print the dot in the last digit when the number is over 1000;
* Options: (int) 0, 1;
* Default: 0;
* Example: When printing 1024,
* if this parameter is set to 0, it will print "1 0 2 4 ",
* if this parameter is set to 1, it will print "1 0 2 4.";
* PARAMETER: doPrint_firstZero:
* Usage: Print the first zero when the number is less than 10;
* Option: (int) 0, 1;
* Default: 0;
* Example: Whenl printing 3.14,
* if this parameter is set to 0, it will print " 3.1 4 ",
* if this parameter is set to 1, it will print "0 3.1 4 ";
* Notice: Because the size of a float or double or anything is only 4 in Arduino,
* it can only keep two decimal places;
*/
Display.begin();
Display.doPrint_lastDot = 1;
Display.doPrint_firstZero = 1;
}

void loop() {
// Print the value here
/* FUNCTION: print(Value)"
* Usage: Print value;
* Arguments: Value: (float) The value to print;
* Notice: 1. If the value is larger than 10000 or is negative,
* It will print an error like this:
* [Error](4Digit7Seg12Pin): Input value larger than 10000.
* We will soon add a parameter to disable this;
* 2. This kind of display cannot display a value for long;
* If you call this function not frequently enough, it will start blinking;
* If you want a continous one, consider those display with a chip on it like 595;
*/
for(float i = 0.01; i < 10000; i += 0.01) Display.print(i);
}

6 changes: 6 additions & 0 deletions keywords.txt
@@ -0,0 +1,6 @@
fDigitsSegtPin KEYWORD1
begin KEYWORD2
print KEYWORD2
doPrint_lastDot KEYWORD2
doPrint_firstZero KEYWORD2

10 changes: 10 additions & 0 deletions library.properties
@@ -0,0 +1,10 @@
name=4Digit7Seg12Pin
version=0.1.0
author=KLsz <KLsz@outlook.com>
maintainer=KLsz <KLsz@outlook.com>
sentence=Power the basic 4 digits 7 segments display
paragraph=Power the 4 digits 7 segments display with 12 pins. If you want to use it in a project, consider those display with a chip on it like 595.
category=Other Input / Output
url=https://github.com/KuangLei/4Digit7Seg12Pin/
architectures=*

49 changes: 6 additions & 43 deletions fDigitsSegtPin.h → src/fDigitsSegtPin.cpp 100755 → 100644
@@ -1,47 +1,10 @@
class fDigitsSegtPin {
public:
//Storage the pins
fDigitsSegtPin(u8 vPf1, u8 vPf2, u8 vPf3, u8 vPf4, u8 vPf5, u8 vPf6, u8 vPf7, u8 vPf8, u8 vPf9, u8 vPf10, u8 vPf11, u8 vPf12);
/* Library 4Digit7Seg12Pin by KLsz Studio
* For more info please visit "https://github.com/KuangLei/4Digit7Seg12Pin/"
* This Library is protected under GPLv3, CopyLeft KLsz Studio
*/

//Init the pins
void begin();

//Print digit
void print(float vff);

//Settings
u8 doPrint_lastDot = 0;
u8 doPrint_firstZero = 0;
private:
//Pins
u8 vPcD1; u8 vPcD2; u8 vPcD3; u8 vPcD4;
u8 vPcA; u8 vPcB; u8 vPcC; u8 vPcD; u8 vPcE; u8 vPcF; u8 vPcG; u8 vPcH;

//Display table
u8 villDigitTable[10][7] = {
// a b c d e f g
{1, 1, 1, 1, 1, 1, 0}, //0
{0, 1, 1, 0, 0, 0, 0}, //1
{1, 1, 0, 1, 1, 0, 1}, //2
{1, 1, 1, 1, 0, 0, 1}, //3
{0, 1, 1, 0, 0, 1, 1}, //4
{1, 0, 1, 1, 0, 1, 1}, //5
{1, 0, 1, 1, 1, 1, 1}, //6
{1, 1, 1, 0, 0, 0, 0}, //7
{1, 1, 1, 1, 1, 1, 1}, //8
{1, 1, 1, 1, 0, 1, 1}, //9
};

//Clean the afterglow
void fvAfterGlow();
//Set the digit to write
void fvSet(u8 vifDigit);
//Write number to the digit
void fvWrite(u8 vifNumber, u8 vifDot);

//Print the digit with the number
void fvPrint(u8 vifDigit, u8 vifNumber, u8 vifDot);
};
#include "Arduino.h"
#include "fDigitsSegtPin.h"

//Storage the pins
fDigitsSegtPin::fDigitsSegtPin(u8 vPf1, u8 vPf2, u8 vPf3, u8 vPf4, u8 vPf5, u8 vPf6, u8 vPf7, u8 vPf8, u8 vPf9, u8 vPf10, u8 vPf11, u8 vPf12) {
Expand Down
57 changes: 57 additions & 0 deletions src/fDigitsSegtPin.h
@@ -0,0 +1,57 @@
/* Library 4Digit7Seg12Pin by KLsz Studio
* For more info please visit "https://github.com/KuangLei/4Digit7Seg12Pin/"
* This Library is protected under GPLv3, CopyLeft KLsz Studio
*/

#ifndef fDigitsSegtPin_h
#define fDigitsSegtPin_h

#include "Arduino.h"

class fDigitsSegtPin {
public:
//Storage the pins
fDigitsSegtPin(u8 vPf1, u8 vPf2, u8 vPf3, u8 vPf4, u8 vPf5, u8 vPf6, u8 vPf7, u8 vPf8, u8 vPf9, u8 vPf10, u8 vPf11, u8 vPf12);

//Init the pins
void begin();

//Print digit
void print(float vff);

//Settings
u8 doPrint_lastDot = 0;
u8 doPrint_firstZero = 0;
private:
//Pins
u8 vPcD1; u8 vPcD2; u8 vPcD3; u8 vPcD4;
u8 vPcA; u8 vPcB; u8 vPcC; u8 vPcD; u8 vPcE; u8 vPcF; u8 vPcG; u8 vPcH;

//Display table
u8 villDigitTable[10][7] = {
// a b c d e f g
{1, 1, 1, 1, 1, 1, 0}, //0
{0, 1, 1, 0, 0, 0, 0}, //1
{1, 1, 0, 1, 1, 0, 1}, //2
{1, 1, 1, 1, 0, 0, 1}, //3
{0, 1, 1, 0, 0, 1, 1}, //4
{1, 0, 1, 1, 0, 1, 1}, //5
{1, 0, 1, 1, 1, 1, 1}, //6
{1, 1, 1, 0, 0, 0, 0}, //7
{1, 1, 1, 1, 1, 1, 1}, //8
{1, 1, 1, 1, 0, 1, 1}, //9
};

//Clean the afterglow
void fvAfterGlow();
//Set the digit to write
void fvSet(u8 vifDigit);
//Write number to the digit
void fvWrite(u8 vifNumber, u8 vifDot);

//Print the digit with the number
void fvPrint(u8 vifDigit, u8 vifNumber, u8 vifDot);
};

#endif

0 comments on commit 260e3b2

Please sign in to comment.