Thomas, it seems like you understand the concept of classes pretty well. (Unless that's an example you copied from a textbook without understanding.)
Totally copied the library from somewhere. I think it may have been from buckys tutorial, but it may have been posted on the form. Actually, I think it was on the arduino.cc how to make a library page.
I hope you don't mean that you want to store runtime variables in the library itself, for use in the future?
I think that may be what I'm thinking of doing. Otherwise how would I be able to call the code in a different void section? I don't want to have to declare the variables as globals to do this, I'd rather the library do that automatically. Or at least that was what I was thinking. Maybe that is a bad idea for some reason. If so please explain why.
Is this what you mean? If not, you'll need to explain what you want a bit more clearly.
this is more along the lines of what I was thinking
#include <rectangle_t.h>
void setup() {
// initialize digital pin 13 as an output.
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
StoreRectData();
FiveMinutesLaterInDifferentLoopReadDataStored();
}
void StoreRectData()
{
rectangle_t myRect(12,24);
}
void FiveMinutesLaterInDifferentLoopReadDataStored()
{
Serial.println(myRect.area());
}
So you want to call the 'tick' class's 'value()' function with a value from 1 to 9. I understand that bit.
correct. Tic tack toe has 9 places you can put an x. the 1 to 9 identifies where you are putting the next x. Then that information goes into the class and is stored there with the other information that was stored previously and figures out where to put it's 0 for its turn.
Can you give an example of exactly what the 'value()' function needs to return?
Sure. three lines of something like this 1 X | X | X /* the | represents the lines drawn in tic tax toe the X represents your moves, the 0 represents the moves decided by the class and if neither X or O is occupying the space then the space is available for the either the player or the class to use next turn*/
line 1 |X|0 //1|2 |3 // player responses with one of these numbers
line 2 || //4|5 |6
line 3 ||X //7|8|9
calls would be made like this
void loop(){
players turn(); // player chooses which space, info is stored in library to be retrieved later
player 2 turn();
}
void players turn(){
// chooseX(1); // data is stored in library
// if entered, print chart
}
void player 2 turn(){
// choose0(2) // data is stored in library
//if entered, print chart containg data stored from players turn() and player2 turn()