Thanks for the answers. The library is successfully working. The only thing is, I would like to drive two digits now. Here are the most recent files.
The .h file
#ifndef Soda_h
#define Soda_h
#include "Arduino.h"
class Soda
{
public:
uint8_t pins(int a, int b, int c, int d, int e, int f, int g, int dp, boolean common);
void write(int number);
private:
int _a, _b, _c, _d, _e, _f, _g, _dp, _number;
byte numeral[10];
int segmentPins[8];
boolean _common;
};
#endif
The current .cpp file.
#include "Arduino.h"
#include "Soda.h"
uint8_t Soda::pins(int a, int b, int c, int d, int e, int f, int g, int dp, boolean common) {
_a=a;
_b=b;
_c=c;
_d=d;
_e=e;
_f=f;
_g=g;
_dp=dp;
_common=common;
segmentPins[0] = _dp;
segmentPins[1] = _g;
segmentPins[2] = _f;
segmentPins[3] = _e;
segmentPins[4] = _d;
segmentPins[5] = _c;
segmentPins[6] = _b;
segmentPins[7] = _a;
for(int i=0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT);
}
}
void Soda::write(int number) {
boolean isBitSet;
numeral[0] = B11111100; // 0
numeral[1] = B01100000; // 1
numeral[2] = B11011010; // 2
numeral[3] = B11110010; // 3
numeral[4] = B01100110; // 4
numeral[5] = B10110110; // 5
numeral[6] = B10111110; // 6
numeral[7] = B11100000; // 7
numeral[8] = B11111110; // 8
numeral[9] = B11100110; // 9
if (_common == HIGH) {
for(int segment=1; segment < 8; segment++) {
if(number < 0 || number > 9) {
isBitSet = 0;
}else{
isBitSet = bitRead(numeral[number], segment);
}
isBitSet = ! isBitSet;
digitalWrite(segmentPins[segment], isBitSet);
}
}
if (_common == LOW) {
for(int segment=1; segment < 8; segment++) {
if(number < 0 || number > 9) {
isBitSet = 0;
}else{
isBitSet = bitRead(numeral[number], segment);
}
digitalWrite(segmentPins[segment], isBitSet);
}
}
}
And the program I'm trying to run.
/* Soda Demo
Uses the soda library from Qtechknow. Counts to 9 and then goes back to 0 on
a seven segment display.
created 14 Apr 12
Made by Quin (Qtechknow)
*/
#include "Soda.h"
Soda Soda; // initialize the first display
Soda Soda2; // initialize the second display
void setup() {
// Segments A, B, C, D, E, F, G, DP pin numbers
Soda.pins(2, 3, 4, 5, 6, 7, 8, 9, HIGH); // set high for common anode, and
Soda2.pins(10, 11, 12, 13, A0, A1, A2, A3, HIGH); // low for common cathode display
}
void loop() {
for(int i=0; i< 10; i++) {
Soda.write(i); // count to 9
Soda2.write(i);
delay(1000); // delay for 1 second
}
}
These are the error messages.
SodaDemo:12: error: 'Soda' does not name a type
SodaDemo.cpp: In function 'void setup()':
SodaDemo:17: error: 'Soda2' was not declared in this scope
SodaDemo.cpp: In function 'void loop()':
SodaDemo:24: error: 'Soda2' was not declared in this scope
Any Help?
Thanks,
Qtechknow