I have since made a simple sketch modified from a youtube video I watched.
I altered the sketch name and the library name and directories, I altered the reference names in the files so they match but were different from the original files.
the new sketch worked.
I then renamed the sketch and added the lines to use a LCD 1602 shield, modified the sketch to output to the shield this worked. I first wrote a few lines in the sketch that printed on the screen then a function that printed a different line to the shield. all of this worked.
#include <MyLibrary.h>
#include <LiquidCrystal.h>
MyLib mlib(true);
void printToScreen(long num); // I want to move this o a .h file
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
lcd.begin(16, 2); // LCD SHIELD WITH 16X02 SCREEN
randomSeed(analogRead(A0));
lcd.clear();
lcd.setCursor(0,1);
lcd.print("display started");
delay(3000);
}
void loop() {
// put your main code here, to run repeatedly:
long rndNo = mlib.getRandomNumber();
// print number on lcd screen
printToScreen(rndNo);
delay(2000);
}
// I want to move below to a .cpp file
void printToScreen(long num){ // print number on lcd screen
lcd.setCursor(0,0);
lcd.print(num);
lcd.print(" ");
}
the library files to go with this sketch are below
//MyLibrary.h
#ifndef ml
#define ml
#if (ARDUINO >=100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class MyLib {
public:
// Constructor
MyLib(bool displayMsg=false);
// Methods
void begin(int baudRate=9600);
// select the pins used on the LCD panel
// void begin (int a=8,int b= 9,int c= 4,int d= 5,int e= 6,int f= 7);
// void begin(int a=16,int b= 2); // LCD SHIELD WITH 16X02 SCREEN
long getRandomNumber();
// void printToScreen(long num);
private:
bool _msg;
float getPi();
};
#endif
//MyLibrary.cpp
#include "MyLibrary.h"
MyLib::MyLib(bool displayMsg) {
// Anything you need when instantiating your object goes here
_msg = displayMsg;
}
// this is our 'begin' function
void MyLib::begin(int baudRate) {
}
// Pretend this is one or more complex and involved functions you have written
long MyLib::getRandomNumber() {
unsigned long specialNumber = random(5, 1000);
specialNumber *= getPi();
specialNumber -= 5;
return specialNumber;
}
// Private method for this class
float MyLib::getPi() {
return 3.1415926;
}
all of this code works together, the problems come when I try to move the function printToScreen to the library.
kendrick