Hi Members,
1). I need code to write real time Serial output dynamically into ".csv" or ".txt" file on my computer. This need is for using that csv or txt file into some other simulating software in real time.
2). If problem one gets solved or even not, then I want to clear Serial Monitor after every output and start from the same line again. This is the requirement of that simulating software I talked about earlier, for saving memory. Please, how?
Please help me with additional codes to fit in with my code below. I'm new to programming and already tried many things from internet source, but didn't work . Using data acquisition software is barred. Here is my code, for reading the rotation angle of a bicycle handlebar.
float rotangle;
float voltage;
float temp;
void setup() {
Serial.begin(9600);
Serial.println("Volt , Side from Normal, Angle, Movement");
float Left(rotangle);
float Right(rotangle);
float straight(rotangle);
}
void loop() {
int sensorValue = analogRead(A0);
voltage = sensorValue * (5.0 / 1023.0);
if(voltage<2.5)
Left();
else if(voltage>2.5)
Right();
else Straight();
temp=voltage;
}
float Left()
{ rotangle = 180/2 - voltage * ((180/2)/2.5);
Serial.print(voltage);
Serial.print(",LEFT,");
Serial.print("-");
Serial.print(rotangle);
movementDir();
delay(1000);
}
float Right()
{ rotangle = (voltage - 2.5) * ((180/2)/2.5);
Serial.print(voltage);
Serial.print(",RGHT,");
Serial.print(rotangle);
movementDir();
delay(1000);
}
float Straight()
{ rotangle = 0;
Serial.print(voltage);
Serial.print(",STRT,");
Serial.println(rotangle);
movementDir();
delay(1000);
}
float movementDir()
{ if (voltage>temp)
Serial.println(",Moved in RHT Dir");
else if (voltage<temp)
Serial.println(",Moved in LFT Dir");
else
Serial.println(",Handlebar Constant");
}