I created the Segments.h file and put the following code in it
#ifndef MY_7segments_H
#define MY_7segments_H
#include <Arduino.h>
class Segments {
private:
// bits representing segments A through G (and decimal point) for numerals 0-9
const int numeral[10] = {
//ABCDEFG /dp
B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110, // 9
};
int nbrDigits;
int segmentPins;
int digitPins;
public:
Segments(int nbrDigits, int segmentPins, int digitPins);
void init();
void showNumber(int number);
void showDigit(int number, int digit);
};
#endif
Also created file Segments.cpp, and put the following code:
#include "7segments.h"
Segments::Segments(int nbrDigits, int segmentPins, int digitPins) {
this->nbrDigits = nbrDigits;
this->segmentPins = segmentPins;
this->digitPins = digitPins;
init();
}
Then I try to call my class from the main program, but I get a compilation error.
Could you please tell me how to correctly pass an array to a class?
const int segmentPins[] = { A9, A8, A7, A6, A5, A4, A3, A2 };
const int nbrDigits= 2; // the number of digits in the LED display
//dig 0 1 2 3
const int digitPins[nbrDigits] = { A0, A1 };
Segments myseg(nbrDigits, segmentPins, digitPins);
@kazan116
Please, post your complete sketch including setup() and loop() functions to allow novice readers to understand the foundation/applicaton of C++ Language from your example. Also, indicate if you are using Arduino MEGA and the type of 7-segment display device (CC or CA).