standarize pins, update readme
This commit is contained in:
parent
790917fcd4
commit
92a0591b48
62
README.md
62
README.md
|
@ -1,3 +1,63 @@
|
|||
# 7seg_numbers_arduino
|
||||
|
||||
This is a library for Arduino to display numbers on a 7 segment display.
|
||||
This is a library for Arduino to display numbers on a 7 segment display. The library creates a display object, this object is initialized by passing an array of the pin numbers where each segment is connected. It is assumed that the pins array will have the following order: {pinA, pinB, pinC, pinD, pinE, pinF, pinG, pinDP}.
|
||||
|
||||
Once the object is created, to print a number use the function with the number's name. Here is an example that use the library to print all the numbers from 0 to 9 and then the DP.
|
||||
|
||||
```c++
|
||||
#include <segNums.h>
|
||||
|
||||
int pins[8] = {2,3,4,5,6,7,8,9};
|
||||
|
||||
SegDisp disp(pins);
|
||||
|
||||
void setup(){
|
||||
}
|
||||
|
||||
void loop(){
|
||||
disp.zero(1);
|
||||
delay(500);
|
||||
disp.zero(0);
|
||||
delay(500);
|
||||
disp.one(1);
|
||||
delay(500);
|
||||
disp.one(0);
|
||||
delay(500);
|
||||
disp.two(1);
|
||||
delay(500);
|
||||
disp.two(0);
|
||||
delay(500);
|
||||
disp.three(1);
|
||||
delay(500);
|
||||
disp.three(0);
|
||||
delay(500);
|
||||
disp.four(1);
|
||||
delay(500);
|
||||
disp.four(0);
|
||||
delay(500);
|
||||
disp.five(1);
|
||||
delay(500);
|
||||
disp.five(0);
|
||||
delay(500);
|
||||
disp.six(1);
|
||||
delay(500);
|
||||
disp.six(0);
|
||||
delay(500);
|
||||
disp.seven(1);
|
||||
delay(500);
|
||||
disp.seven(0);
|
||||
delay(500);
|
||||
disp.eight(1);
|
||||
delay(500);
|
||||
disp.eight(0);
|
||||
delay(500);
|
||||
disp.nine(1);
|
||||
delay(500);
|
||||
disp.nine(0);
|
||||
delay(500);
|
||||
disp.dot(1);
|
||||
delay(500);
|
||||
disp.dot(0);
|
||||
delay(500);
|
||||
}
|
||||
```
|
||||
|
|
40
segNums.cpp
40
segNums.cpp
|
@ -11,65 +11,65 @@ SegDisp::SegDisp(int pins[8])
|
|||
|
||||
void SegDisp::zero(int state)
|
||||
{
|
||||
int leds[6] = {0,1,2,4,5,6};
|
||||
int leds[6] = {0,1,2,3,4,5};
|
||||
for (int i = 0; i < 6; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::one(int state)
|
||||
{
|
||||
int leds[2] = {2,6};
|
||||
int leds[2] = {1,2};
|
||||
for (int i = 0; i < 2; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::two(int state)
|
||||
{
|
||||
int leds[5] = {0,1,3,5,6};
|
||||
int leds[5] = {0,1,3,4,6};
|
||||
for (int i = 0; i < 5; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::three(int state)
|
||||
{
|
||||
int leds[5] = {1,2,3,5,6};
|
||||
int leds[5] = {0,1,2,3,6};
|
||||
for (int i = 0; i < 5; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::four(int state)
|
||||
{
|
||||
int leds[4] = {2,3,4,6};
|
||||
int leds[4] = {1,2,5,6};
|
||||
for (int i = 0; i < 4; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::five(int state)
|
||||
{
|
||||
int leds[5] = {1,2,3,4,5};
|
||||
int leds[5] = {0,2,3,5,6};
|
||||
for (int i = 0; i < 5; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::six(int state)
|
||||
{
|
||||
int leds[6] = {0,1,2,3,4,5};
|
||||
int leds[6] = {0,2,3,4,5,6};
|
||||
for (int i = 0; i < 6; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::seven(int state)
|
||||
{
|
||||
int leds[3] = {2,5,6};
|
||||
int leds[3] = {0,1,2};
|
||||
for (int i = 0; i < 3; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,15 +77,15 @@ void SegDisp::eight(int state)
|
|||
{
|
||||
int leds[7] = {0,1,2,3,4,5,6};
|
||||
for (int i = 0; i < 7; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
void SegDisp::nine(int state)
|
||||
{
|
||||
int leds[6] = {1,2,3,4,5,6};
|
||||
int leds[6] = {0,1,2,3,5,6};
|
||||
for (int i = 0; i < 6; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,6 @@ void SegDisp::dot(int state)
|
|||
{
|
||||
int leds[1] = {7};
|
||||
for (int i = 0; i < 1; i++){
|
||||
digitalWrite(_pins[led[i]], state);
|
||||
digitalWrite(_pins[leds[i]], state);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user