I just recently received my first arduino Uno from UPS. The reason i bought the arduino was because it was based off the C++ development language which i am quite familiar with. Following the instructions given on the link below i attempted to create a simple Library.
http://arduino.cc/en/Hacking/LibraryTutorialI wrote all the code for both the .h and the .cpp file as well as the .pde to run the code created by the library. The code was designed to make the built in LED blink after a specified amount of run times were completed (designed to remove the necessity of a word variable).
This was really simple and just a test to see how the library's would work in the ardunio language. This is when i discovered the issue that i could not save the .h and .cpp files with that extension. I would type in powerBlink.h and the message would print out saying file name issues so it changed the name as powerBlink_h.pde which was a serious annoyance because i can't save the files as needed now.
Some notes...
1.I have devC++ on my computer so all .h and .cpp files are defaulted to open in there.
2.I tried copy and pasting the .h file into a notepad file and saving it's type as .h and then open it from arduino i get the error "Processing can only it's own sketches and files ending in .pde"
3.Probably obvious from the above comment i'm running a windows but i have linux partitioned if need be.
4.I originally had a error trying to compile my .h file something to do with my instance variables so i commented them all out but then the developing enviorment came to the conclusion since it was a .pde file i needed a loop and a setup which since it was designed as a .h i don't have.
Code in order .h, .cpp, .pde
/*should hopefully blink the LED in just one library command
also the pulseWidth will be decided on the length of runs on
the run time clock.
*/
#ifndef powerBlink_h
#define powerBlink_h
#include "WProgram.h"
class powerBlink{
public:
powerBlink ();
powerBlink (unsigned int _pulseWidth);
void blinkRunTime();
private:
const int ledPin = 13
int ledState = LOW;
unsigned int time = 0;
unsigned int pulseWidth = 0;
};
#endif
//please blink
#include "WPorgram.h"
#include "powerBlink.h"
powerBlink::powerBlink(){
pulseWidth = 3000;
}
powerBlink::powerBlink(unsigned int _pulseWidth){
pulseWidth = _pulseWidth;
}
void powerBlink::blinkRunTime(){
if(time == pulseWidth){
time = 0;
if(ledState==LOW)
ledState = HIGH;
else
ledState = LOW;
}else{
time++;
}
digitalWrite(ledPin,ledState);
}
#include <powerBlink.h>
powerBlink blinker();
void setup(){
//no setup just run time computations
}
void loop(){
blinker.blinkRunTime();
}
Thanks for any help you can give.