diff --git a/7segNums.cpp b/7segNums.cpp new file mode 100644 index 0000000..fbd417f --- /dev/null +++ b/7segNums.cpp @@ -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); + } +} diff --git a/7segNums.h b/7segNums.h new file mode 100644 index 0000000..3703db8 --- /dev/null +++ b/7segNums.h @@ -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