I wrote a library and finally got it to compile, but now nothing happens. No LEDs light up. I’ve already tested the code outside of a library (in a sketch) and I know it works fine. I think I have a misunderstanding of how to run libraries. Here is my .h file:
#ifndef numberLED_h
#define numberLED_h
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
class numberLED {
private:
public:
numberLED();
void writeNum(int val);
void writeChar(int val);
void dice();
int num;
int numSegments [] [7];
int upperCharSegments [] [7];
int lowerCharSegments [] [7];
int val;
};
#endif
Here are the (relevant) parts of my .cpp file:
#include "numberLED.h"
numberLED::numberLED() { //make it so the user can define what pins they want to use.
for(int i = 0; i < 8; i++) {
pinMode(i, OUTPUT);
}
randomSeed(analogRead(0));
}
int num = 0;
int numSegments [] [7] = { //0-9
{1, 1, 0, 1, 1, 1, 1},
{0, 1, 0, 0, 1, 0, 0},
{0, 1, 1, 1, 0, 1, 1},
{0, 1, 1, 0, 1, 1, 1},
{1, 1, 1, 0, 1, 0, 0},
{1, 0, 1, 0, 1, 1, 1},
{1, 0, 1, 1, 1, 1, 1},
{0, 1, 0, 0, 1, 0, 1},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 0, 1, 0, 1}
};
void numberLED::writeNum(int val) {
for( int i = 0; i < 7; i++) {
digitalWrite(i,numSegments[val][i]==1 ? HIGH : LOW);
}
}
And here is my sketch. It simply counts upwards:
// Displays numbers and letters on a seven-segment LED
#include <numberLED.h>
numberLED led;
void setup()
{
}
void loop()
{
led.writeNum(led.num);
led.num++;
if (led.num >= (sizeof led.numSegments)/(sizeof led.numSegments[0]))
led.num = 0;
delay(1000);
}
I know all of the files are in the right place as everything compiles fine. Is there something else I’m missing? Feel free to also critique my library. Thank you!