Hi, everyone
Do you know how flag command and flag.duration commands works in Arduino?
I have seen so a code on a project and i didn't understand it. thanks in advance...
struct {
/* mode
0- Bekle
1- Deney modu
2- GPS test modu
3- Gyro test modu
*/
uint8_t mode;
uint32_t duration;//Deney süresi ms (varsayılan 10s)
} flags;
flags is a struct holding 2 data items. The mode data item is accessed by referring to it as flags.mode and the duration as flags.duration
In setup(), flags.mode is set to 0 and flags.duration to 10000. The rest of the code posted uses the struct data in the same way as normal variables. The struct variables could just as well be mode and duration in the code that you posted but it is not complete so the struct may be useful elsewhere in the sketch
When you have a list of values used to keep track of a mode or state it is good to use an 'enumeration' (enum) to assign values to names. Using the names makes it much clearer what is happening AND shows that the comments in the switch statement are clearly wrong:
enum modes {BEKLE_MODE, DENEY_MODE, GPS_TEST_MODE, GYRO_TEST_MODE};
struct
{
enum modes mode;
uint32_t duration; //Deney süresi ms (varsayılan 10s)
} flags;
unsigned long lastMillis = 0;
bool isGPSRead = false;
boolean buton = false;
void setup()
{
flags.mode = BEKLE_MODE;
flags.duration = 10000L;
Serial.begin(115200);
Serial.setTimeout(100);
!!!!!!!!!!! Where is the end of setup()????
void loop()
{
if (flags.mode != BEKLE_MODE)
{
String cmd = Serial.readString();
if (cmd != "")
{
if (!cmd.compareTo("M0")) // Bekleme Modu
{
Serial.println(F("\nBekleme Modu"));
flags.mode = BEKLE_MODE;
}
else if (!cmd.compareTo("M1")) // Deney Modu
{
Serial.println(F("\nDeney Modu"));
dosya = SD.open("gps7.txt", FILE_WRITE);
lastMillis = millis();
flags.mode = DENEY_MODE;
}
}
switch (flags.mode)
{
case DENEY_MODE: //Bekleme Modu
break;
case BEKLE_MODE: // Deney Modu
logSD_GPS();
logSD_Ivme();
if (millis() - lastMillis > flags.duration) // ayarlanan set süresi bitince deney bitiyor
{
Serial.println(F("Deney Tamamlandı\nBekleme Modu"));
flags.mode = BEKLE_MODE;
dosya.close();
}
UKHeliBob:
flags is a struct holding 2 data items. The mode data item is accessed by referring to it as flags.mode and the duration as flags.duration
In setup(), flags.mode is set to 0 and flags.duration to 10000. The rest of the code posted uses the struct data in the same way as normal variables. The struct variables could just as well be mode and duration in the code that you posted but it is not complete so the struct may be useful elsewhere in the sketch
UKHeliBob:
so, how can i change duration of the system?, because, when i change the values of "flags.duration", system gives error.