first version .cpp and .h

This commit is contained in:
Xaloc 2020-03-13 13:06:55 +01:00
parent d54d3de82d
commit 970e1ef792
2 changed files with 123 additions and 0 deletions

98
7segNums.cpp Normal file
View File

@ -0,0 +1,98 @@
#include "Arduino.h"
#include "SegDisp.h"
SegDisp::SegDisp(int pins[8])
{
for (int i = 0; i < 8; i++){
pinMode(pins[i], OUTPUT);
_pins[i]=pins[i];
}
}
void SegDisp::zero(int state)
{
int leds[6] = {0,1,2,4,5,6};
for (int i = 0; i < 6; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::one(int state)
{
int leds[2] = {2,6};
for (int i = 0; i < 2; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::two(int state)
{
int leds[5] = {0,1,3,5,6};
for (int i = 0; i < 5; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::three(int state)
{
int leds[5] = {1,2,3,5,6};
for (int i = 0; i < 5; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::four(int state)
{
int leds[4] = {2,3,4,6};
for (int i = 0; i < 4; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::five(int state)
{
int leds[5] = {1,2,3,4,5};
for (int i = 0; i < 5; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::six(int state)
{
int leds[6] = {0,1,2,3,4,5};
for (int i = 0; i < 6; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::seven(int state)
{
int leds[3] = {2,5,6};
for (int i = 0; i < 3; i++){
digitalWrite(_pins[led[i]], state);
}
}
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);
}
}
void SegDisp::nine(int state)
{
int leds[6] = {1,2,3,4,5,6};
for (int i = 0; i < 6; i++){
digitalWrite(_pins[led[i]], state);
}
}
void SegDisp::dot(int state)
{
int leds[1] = {7};
for (int i = 0; i < 1; i++){
digitalWrite(_pins[led[i]], state);
}
}

25
7segNums.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef 7segNums_h
#define 7segNums_h
#include "Ardunio.h"
class SegDisp
{
public:
SegDisp(int pins[8]);
void zero(int state);
void one(int state);
void two(int state);
void three(int state);
void four(int state);
void five(int state);
void six(int state);
void seven(int state);
void eight(int state);
void nine(int state);
private:
int _pins[8];
};
#endif