// put your setup code here, to run once:
#include <SoftwareSerial.h> // include the software serial libray
#define TRUE 1
#define FALSE 0
// You can define multiple sets of data as flight1, flight2 etc until you run out of memory..., just change "#define currentFlight" to match
// the flight# you want to use then recompile and re-upload
// note that the maximum single altitude value is approximatly 65000 (16 bits)
// This test data was downloaded from a Pnut altimeter - the flight to 900+ feet is an acutal flight, the flight to 8000+ feet is the test
// sequence from PerfectFlite when the altimeter was first received. You can replace these data sets with your own data by uing the download cable
// from perfectflite together with the Data Capture program here: http://www.perfectflite.com/Downloads/Download%20Program/Windows/PerfectFlite%20DataCap.exe
// you can download the flight you are interested from the Pnut. When you inspect the data you can select the range you want and copy to the clipboard
unsigned int flight1[] = {
0,2,1,1,2,2,3,2,1,2,4,5,9,14,20,25,34,45,54,62,67,70,74,81,87,96,105,113,122,129,140,149,159,167,177,187,197,208,
218,230,241,252,263,275,286,297,309,321,333,345,357,370,381,394,406,419,432,446,459,473,484,495,505,514,522,530,
540,547,554,564,574,583,589,597,604,612,619,625,633,640,649,654,659,665,669,675,682,689,693,699,705,710,717,723,
729,735,739,744,748,755,759,765,770,775,780,783,788,793,796,800,806,809,813,817,821,825,829,833,836,839,843,846,
849,852,855,860,863,866,868,871,873,876,877,879,883,885,888,890,892,894,896,898,900,901,904,905,907,908,910,910,
912,913,915,916,916,917,920,921,921,922,923,923,923,924,924,926,926,926,927,928,929,927,928,929,929,930,930,930,
930,929,927,928,929,929,929,929,929,928,930,932,929,926,925,922,921,918,917,916,916,915,914,915,917,917,917,915,
912,911,910,907,902,904,904,901,900,897,895,895,895,892,894,892,888,889,888,885,884,886,879,881,878
};
unsigned int flight2[] = {
1,0,0,1,1,0,0,0,0,0,0,1,35,77,118,159,201,241,280,320,361,402,441,482,522,562,603,645,687,727,768,809,850,893,
935,978,1018,1060,1102,1143,1185,1226,1268,1310,1350,1391,1432,1472,1515,1556,1598,1637,1679,1719,1760,1800,
1841,1881,1921,1960,2001,2041,2081,2121,2160,2200,2239,2278,2317,2356,2395,2434,2473,2512,2550,2589,2627,2665,
2702,2740,2777,2814,2853,2891,2928,2964,3001,3037,3074,3110,3147,3184,3218,3254,3290,3324,3362,3396,3431,3465,
3501,3537,3571,3606,3640,3674,3709,3744,3778,3811,3846,3880,3913,3947,3981,4015,4047,4082,4115,4148,4181,4216,
4248,4280,4314,4345,4380,4411,4442,4474,4507,4539,4572,4604,4635,4667,4697,4730,4761,4791,4823,4852,4884,4913,
4944,4974,5004,4034,5064,5095,5125,5154,5183,5212,5242,5272,5301,5330,5358,5388,5416,5444,5474,5500,5530,5557,
5587,5613,5641,5669,5696,5725,5752,5779,5806,5832,5859,5886,5912,5939,5886,5912,5939,5965,5991,6016,6042,6069,
6094,6121,6145,6170,6196,6221,6245,6270,6296,6320,6345,6368,6392,6416,6439,6464,6487,6511,6534,6557,6580,6603,
6625,6649,6671,6693,6716,6737,6760,6780,6802,6824,6845,6867,6886,6907,6928,6949,6970,6990,7010,7029,7049,7068,
7090,7107,7126,7145,7165,7184,7202,7222,7240,7259,7276,7294,7312,7328,7346,7364,7380,7398,7415,7432,7448,7464,
7480,7495,7513,7528,7542,7558,7573,7589,7604,7618,7633,7647,7662,7677,7690,7703,7717,7731,7745,7758,7772,7784,
7795,7808,7821,7832,7845,7856,7880,7890,7902,7913,7923,7935,7945,7955,7966,7976,7986,7995,8004,8014,8023,8032,
8041,8050,8059,8067,8075,8083,8091,8099,8107,8113,8121,8129,8135,8142,8149,8155,8160,8166,8173,8180,8185,8191,
8196,8202,8207,8213,8217,8221,8227,8231,8236,8240,8245,8249,8252,8260,8264,8268,8270,8274,8276,8280,8283,8286,
8288,8291,8293,8295,8298,8300,8303,8304,8307,8308,8310,8312,8315,8314,8316,8318,8319,8321,8321,8323,8323,8325,
8326,8327,8328,8329,8330,8330,8332,8332,8332,8332,8333,8334,8336,8334,8336,8334,8336,8334,8336,8338,8338,8338,
8337,8339,8339,8339,8339,8339,8340,8340,8341,8342,8342,8342,8343,8343,8343,8344,8344,8343,8343,8344,8343,8344,
8344,8345,8346,8347,8346,8348,8346,8347,8347,8348,8348,8347,8349,8349,8347,8348,8348,8347,8348,8349,8350,8350,
8349,8350,8349,8350,8349,8349,8350,8350,8349,8351,8350,8351,8350,8350,8351,8351,8351,8250,8250,8250,8351,8350,
8351,8351,8352,8351,8351,8351,8351,8352,8350,8350,8352,8350,8350,8352,8351,8352,8352,8351,8312,8265,8212,8171,
8126,8080,9032,7986,7940,7896,7850,7806,7762,7717,7675
};
#define FlightData flight1 // set to flight1 or flight2 or.... - whatever data set you wish to use
// you can define debug TRUE or FALSE. If true the program will output the altitude to the serial monitor as well as the serial port
#define debug TRUE // output to the serial monitor in addition to the serial port if TRUE
String ASCIIAltitude;
int noElements;
SoftwareSerial PnutSerial(10, 11); // Software Serial port: RX uses pin 10, TX uses pin 11
/*unsigned int flight1[] = {
0,2,1,1,2,2,3,2,1,2,4,5,9,14,20,25,34,45,54,62,67,70,74,81,87,96,105,113,122,129,140,149,159,167,177,187,197,208,
218,230,241,252,263,275,286,297,309,321,333,345,357,370,381,394,406,419,432,446,459,473,484,495,505,514,522,530,
540,547,554,564,574,583,589,597,604,612,619,625,633,640,649,654,659,665,669,675,682,689,693,699,705,710,717,723,
729,735,739,744,748,755,759,765,770,775,780,783,788,793,796,800,806,809,813,817,821,825,829,833,836,839,843,846,
849,852,855,860,863,866,868,871,873,876,877,879,883,885,888,890,892,894,896,898,900,901,904,905,907,908,910,910,
912,913,915,916,916,917,920,921,921,922,923,923,923,924,924,926,926,926,927,928,929,927,928,929,929,930,930,930,
930,929,927,928,929,929,929,929,929,928,930,932,929,926,925,922,921,918,917,916,916,915,914,915,917,917,917,915,
912,911,910,907,902,904,904,901,900,897,895,895,895,892,894,892,888,889,888,885,884,886,879,881,878
};
unsigned int flight2[] = {
1,0,0,1,1,0,0,0,0,0,0,1,35,77,118,159,201,241,280,320,361,402,441,482,522,562,603,645,687,727,768,809,850,893,
935,978,1018,1060,1102,1143,1185,1226,1268,1310,1350,1391,1432,1472,1515,1556,1598,1637,1679,1719,1760,1800,
1841,1881,1921,1960,2001,2041,2081,2121,2160,2200,2239,2278,2317,2356,2395,2434,2473,2512,2550,2589,2627,2665,
2702,2740,2777,2814,2853,2891,2928,2964,3001,3037,3074,3110,3147,3184,3218,3254,3290,3324,3362,3396,3431,3465,
3501,3537,3571,3606,3640,3674,3709,3744,3778,3811,3846,3880,3913,3947,3981,4015,4047,4082,4115,4148,4181,4216,
4248,4280,4314,4345,4380,4411,4442,4474,4507,4539,4572,4604,4635,4667,4697,4730,4761,4791,4823,4852,4884,4913,
4944,4974,5004,4034,5064,5095,5125,5154,5183,5212,5242,5272,5301,5330,5358,5388,5416,5444,5474,5500,5530,5557,
5587,5613,5641,5669,5696,5725,5752,5779,5806,5832,5859,5886,5912,5939,5886,5912,5939,5965,5991,6016,6042,6069,
6094,6121,6145,6170,6196,6221,6245,6270,6296,6320,6345,6368,6392,6416,6439,6464,6487,6511,6534,6557,6580,6603,
6625,6649,6671,6693,6716,6737,6760,6780,6802,6824,6845,6867,6886,6907,6928,6949,6970,6990,7010,7029,7049,7068,
7090,7107,7126,7145,7165,7184,7202,7222,7240,7259,7276,7294,7312,7328,7346,7364,7380,7398,7415,7432,7448,7464,
7480,7495,7513,7528,7542,7558,7573,7589,7604,7618,7633,7647,7662,7677,7690,7703,7717,7731,7745,7758,7772,7784,
7795,7808,7821,7832,7845,7856,7880,7890,7902,7913,7923,7935,7945,7955,7966,7976,7986,7995,8004,8014,8023,8032,
8041,8050,8059,8067,8075,8083,8091,8099,8107,8113,8121,8129,8135,8142,8149,8155,8160,8166,8173,8180,8185,8191,
8196,8202,8207,8213,8217,8221,8227,8231,8236,8240,8245,8249,8252,8260,8264,8268,8270,8274,8276,8280,8283,8286,
8288,8291,8293,8295,8298,8300,8303,8304,8307,8308,8310,8312,8315,8314,8316,8318,8319,8321,8321,8323,8323,8325,
8326,8327,8328,8329,8330,8330,8332,8332,8332,8332,8333,8334,8336,8334,8336,8334,8336,8334,8336,8338,8338,8338,
8337,8339,8339,8339,8339,8339,8340,8340,8341,8342,8342,8342,8343,8343,8343,8344,8344,8343,8343,8344,8343,8344,
8344,8345,8346,8347,8346,8348,8346,8347,8347,8348,8348,8347,8349,8349,8347,8348,8348,8347,8348,8349,8350,8350,
8349,8350,8349,8350,8349,8349,8350,8350,8349,8351,8350,8351,8350,8350,8351,8351,8351,8250,8250,8250,8351,8350,
8351,8351,8352,8351,8351,8351,8351,8352,8350,8350,8352,8350,8350,8352,8351,8352,8352,8351,8312,8265,8212,8171,
8126,8080,9032,7986,7940,7896,7850,7806,7762,7717,7675
};*/
void setup() {
if (debug){
PnutSerial.begin(9600); // This is our software serial port from the Pnut altimeter - set to 9600 BAUD
Serial.begin (9600); // This is the hardware serial port used by the serial monitor - also set to 9600 BAUD
}
ASCIIAltitude.reserve(6); // allow for up to five digits in each altitude value plus end delimiter
noElements = (sizeof(FlightData)/sizeof(int)); // calculate how many altitude values are in our array (max index is one less than this)
pinMode (LED_BUILTIN, OUTPUT); // USe built in LED to flag next flight
digitalWrite(LED_BUILTIN,HIGH); // first trip through - tell user we are about to start
delay (1000); // leave LED on for 1 second
digitalWrite (LED_BUILTIN,LOW); // Turn LED OFF
}
void loop() {
// put your main program code here, to run repeatedly:
// ... (rest of your loop code) ...
for (int index = 0; index <= noElements-1; index++) {
ASCIIAltitude = String (FlightData[index]);
if (debug)
Serial.println (ASCIIAltitude); // show our current altitude on the serial monitor
PnutSerial.println (ASCIIAltitude); // if not send the altitude
delay (47); // Pnut sends data out every 50 ms - but in the program it takes about 1ms to send out each character so us e 47 ms
}
digitalWrite (LED_BUILTIN,HIGH);
delay (1000);
digitalWrite (LED_BUILTIN,LOW);
delay (5000); // repeat the flight again after a pause of 5 seconds
}