Coding continues...
First part - to get setpoint values - is almost completed. But there's one big drawback. I would like to put all code concerning input of setpoint values in the setup part of the sketch. Tried different ways without success. Here are the premises:
I have 7 files on mSD, with different burning data.
One example file: RawGlaz.txt: 0,20,240,300,280,790,300,790,315,20,0,0
Would like to choose one of these files, to get the right time/temp relations for the actual burning.
By Serial.read I can choose file 1-7 and thus read the correct data in this file.
But I dont realize how to get "if (Serial.available())" working as expected in "void setup". I realise that one should find a method to delay and wait for an input, but I cant figure out how.
Right now this procedure is placed in the "void loop"-part of the sketch, and it works ok. But I would seriously avoid to open/close mSD-files everytime the process moves through the loop. Any clues?
Heres the code. Dont care for all prints, right now they're only checkpoint for me.
#include <SD.h>
//Declarations
char* BurnCurve[]={
"GLABEND.TXT", "RAWGLAZ.TXT", "DRYING_.TXT", "STOWARE.TXT", "STOGLAZ.TXT", "CLAGLAZ.TXT", "BISCUIT.TXT"};
int i, temp, time, tempArray[5], timeArray[5];
int incomingByte;
void setup()
//Open serial comm. & set comm. channels
{
Serial.begin(9600);
while (!Serial)
{
}
pinMode(10,OUTPUT);
if(!SD.begin(8))
{
Serial.println("initialization failed!");
return;
}
// Instructions to choose right Burn curve
for (i=0; i<7; i++)
{
Serial.print(BurnCurve[i]);
Serial.print(" - Choose ");
Serial.print(i + 1);
Serial.println(" for this curve");
}
}
void loop()
{
// Input number of Burn curve
if (Serial.available())
{
// read the incoming byte:
incomingByte = Serial.read();
incomingByte = incomingByte - 49;
Serial.println("");
Serial.print("Burn Curve is: ");
Serial.println(BurnCurve[incomingByte]);
File SPFile = SD.open(BurnCurve[incomingByte]);
Serial.println("");
if (SPFile)
{
for (int i=0; i<6; i++)
{
time = SPFile.parseInt();
temp = SPFile.parseInt();
tempArray[i] = temp;
timeArray[i] = time;
Serial.println("");
Serial.print(timeArray[i]);
Serial.print(" ");
Serial.println(tempArray[i]);
}
}
else
{
// if the file didn't open, print an error:
Serial.println("error opening RawGlaz.txt");
}
// close file:
SPFile.close();
Serial.println("done.");
}
}
/*
{
Calculate SetPoint values from temp/time Arrays
}
{
Catch data from the thermocouples and transform to degrees centrigrade
}
{
PDI calculations
}
{
Output to thyristor stack
}
EOF
*/
Here's the output when choosing file GlaBend.txt through sending "1" as input:
GLABEND.TXT - Choose 1 for this curve
RAWGLAZ.TXT - Choose 2 for this curve
DRYING_.TXT - Choose 3 for this curve
STOWARE.TXT - Choose 4 for this curve
STOGLAZ.TXT - Choose 5 for this curve
CLAGLAZ.TXT - Choose 6 for this curve
BISCUIT.TXT - Choose 7 for this curve
Burn Curve is: GLABEND.TXT
0 20
200 625
210 625
450 400
600 200
615 20
done.