I'm trying to make a fully working chronometer with the addition of using a self made library.
I made a fully working code before starting to split my functions into a library, after having finished that I tried to compile my code again after a quick restart of the Arduino IDE.
the error log states the following:
C:\Users\bjorn\OneDrive\APHogeschool\2EA\Microcontrollers\Lab4_Opg4\Lab4_Opg4.ino:1:25: fatal error: Chronometer.h: No such file or directory
#include "Chronometer.h"
^
compilation terminated.
exit status 1
Fout bij het compileren voor board Arduino Nano
main .ino code:
#include "Chronometer.h"
Chronometer chronometer(100);
const int light[] = {3, 4, 5, 6, 7, 8, 9};
const int digit[] = {10, 11, 12, 13};
int value[] = {0, 0, 0, 0};
bool change[] = {true, false, false, false};
int hold[] = {0, 0, 0, 0};
const int table[][7] = {
{1, 1, 1, 1, 1, 1, 0},
{0, 1, 1, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 1},
{1, 1, 1, 1, 0, 0, 1},
{0, 1, 1, 0, 0, 1, 1},
{1, 0, 1, 1, 0, 1, 1},
{1, 0, 1, 1, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1}
};
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < 7; i++) {
pinMode(light[i], OUTPUT);
}
for (int i = 0; i < 7; i++) {
pinMode(digit[i], OUTPUT);
digitalWrite(digit[i], HIGH);
}
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
for (int d = 0; d < 4; d++) {
digitalWrite(digit[d], LOW);
chronometer.Convert(light, value, d, change);
digitalWrite(digit[d], HIGH);
}
int d = 0;
hold[d]++;
while (d < 4) {
chronometer.Change(value, d, change);
d++;
}
}
.h code
#ifndef Morse_h
#define Morse_h
#include "Arduino.h"
class Chronometer {
public:
Chronometer(int timestamp);
void Convert(int light[], int value[], int d, bool change[]);
void Change(int value[], int d, bool change[]);
private:
int _timestamp;
};
#endif
.cpp code
#include "Arduino.h"
#include "Chronometer.h"
Chronometer::Chronometer(int timestamp) {
_timestamp = timestamp;
}
void Chronometer::Convert(int light[], int value[], int d, bool change[]) {
for (int j = 0; j < 7; j++) {
digitalWrite(light[j], table[value[d]][j]);
}
delay(3);
}
void Chronometer::Change(int value[], int d, bool change[]) {
if (hold[d] == timestamp) {
value[d]++;
if (d != 0)
hold[d] = 0;
if (value[0] == 10) {
value[0] = 0;
hold[1] = timestamp;
}
if (value[1] == 6) {
value[1] = 0;
hold[2] = timestamp;
}
if (value[2] == 10) {
value[2] = 0;
hold[3] = timestamp;
}
if (value[3] == 6) {
value[3] = 0;
hold[4] = timestamp;
}
hold[d] = 0;
}
}
thanks.
