Hardware Reference
In-Depth Information
struct position {
int xx;
int yy;
};
This struct would declare a position to have an X and Y value. In strict C, you would have to declare the struct
or enum with typedef , but in C++ this is not required. This struct could be added to our Hello Library header file, as
indicated in Listing 12-6.
Listing 12-6. Position struct in header file HelloLibrary.h updated
/*
*
* HelloLibrary Header file
*
*/
#ifndef HelloLibrary_h
#define HelloLibrary_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define LED_PIN 13
struct position {
int xx;
int yy;
};
void printHelloLibrary();
void startBlink(int duration);
#endif
Then the Position struct could be used in the main sketch, as shown in Listing 12-7.
Listing 12-7. Code using the Position struct
#include "HelloLibrary.h"
void setup()
{
Serial.begin(9600);
position Position;
Position.xx = 20;
Position.yy = 30;
Serial.print("Position X: ");
Serial.print(Position.xx);
Serial.print(" Y: ");
Serial.println(Position.yy);
}
 
Search WWH ::




Custom Search