First of all i re-wrote the software for tasks 18 & 19, as you will see in the next post
i then rewrote the functions in a test LIB sketch, & when it compiled & ran ok, i deleted the setup() & loop() parts & saved it in a separate folder which i have called Arduino Libraries.
These should NOT BE CONFUSED with the C-libraries, for which you must write the line, at the head of your code:
#include Clib1.h
(which normally has those pointy brackets enclosing the .h file - but which means something entirely different in this blog's HTML so i can't put them in).
In the Arduino task sketch, click on 'Sketch' as shown on the right.
Click on 'Add File...'
You get the dialog box as shown on the left.
You have to know where your required file is, & open it..
Click on the 'Open' tab.
You now have TWO sketches open, & they can be combined to operate as one.
And when you save the original sketch, the LIBrary sketch is saved with it, so that every time you subsequently open the main sketch you get the LIB sketch opening with it.
i should add a line to the LIB sketch, describing the required parameters.
in theory (hehe - famous last words!) i should be able:
to write anything that has the right parameters for the right job;
to plug in a different motor provided the parameters fit;
change the motor type used with only minor code alterations.
this has been a bit of a holdup, & i think is worth the extra effort i've made for it.
ps: the same probably applies to Processing sketches i'd imagine..
Here's some example code - Keypress input via the Serial Monitor:
/*
* Project: LIB04_KeypressInput
* Author: Jane-Maree Howard
* Date: Saturday 08/10/2011
* Platform: Arduino 22
* Purpose: To make a library function for inputting a key-press via Serial comm link
* Operation: Description: inputs a key-press & returns an Integer
- Procedure(): int KeypressInput(); no parameters
*/
int KeypressInput()
{
/* inputs a keypress via the Serial comms link
& returns a non-zero Integer only if there is an input
CALLED IN MAIN SKETCH */
int iKey = 0;
// send data only when you receive data
if (Serial.available() > 0)
iKey = Serial.read();
return iKey;
}//KeypressInput().
//END
Used in the following posts (click to return to them if necessary):
Project 02 - Motor Project;
Task 13;
Task 14;
i hope this'll speed things up a bit, when it comes to writing more complicated software..
ReplyDelete