Sample : Arduino Serial

boolean headersend = false;

double counter = 0.0;

 

int led = 13;

 

void setup()

{

 Serial.begin(57600);

 

 Serial.println("LogView Studio - OpenFormat Zero Demo (Serial Port for Data sending)");

 Serial.println("2013 by Dominik Schmidt\n");

 pinMode(led, OUTPUT);  

}

 

void loop()

{

 String tempst;

 double temp;

 if (Serial.available() > 0)

 {

   char c = Serial.read();

   switch (c)      

   {

   case 83: // "S" -> Start

     Serial.println("Start detected");

     // Send Header information

     tempst = "$N$;Data Logging\r\n";

     Serial.print(tempst);

     tempst = "$C$;Value 1;Value 2\r\n";

     Serial.print(tempst);

     headersend = true;

     break;

   case 69: // "E" -> End

     Serial.println("End detected");

     digitalWrite(led, LOW);

     headersend = false;

     break;

   }

 }

 

 if (headersend)

 {

   digitalWrite(led, !digitalRead(led));

   counter += 0.01;

   if (counter > 6.28) {counter = 0.0;}

 

   Serial.print("$");

   temp = sin(counter);

   Serial.print(temp);

   Serial.print(";");

   temp = sin(cos(counter) * tan(counter / 2));

   Serial.print(temp);

   Serial.print("\r\n");

 

   delay(250);

 }

}


Send feedback on this topic
Copyright (C) 2013-2014 Dominik Schmidt / Holger Hemmecke. All rights reserved.