void loop() {
If(Serial.available() > 0){
long bufferCount;
long ;
char myData[MAXCHARS+1];
bufferCount = ReadLine(myData);
this is what I have so far.
Write and print out an Arduino C program which includes four functions: void setup(), void loop(), int ReadLine(char str[]), and the programmer-defined function int kelvinTemperature(celcius). Function loop() should have the user enter a value for the current temperature in degrees celsius, call the function kelvinTemperature to calculate the temperature in degrees Kelvin, and display the calculated value.
int kelvinTemperature(celcius)
Temp=Temp + 273.15;
void setup()
{
Serial.begin(9600);
Serial.println ("number in degrees celsius");
}
void loop() {
If(Serial.available() > 0){
long bufferCount;
long ;Temp
char myData[MAXCHARS+1];
bufferCount = ReadLine(myData);
temp= atoi(myData);
Serial.print("Temp in kelvin");
this is what i have im putting in what is in the book and trying to convert it to do what the project asks for me to do. i know i have most of it out of place. and i know i have to define temp but am unsure how to go about doing it. this all really baffles me.
LutherPumphandle:
this is what i have im putting in
There are so many things wrong with that code that there is no point trying to fix it. Toss what you have typed in the trash and start over. If you are copying it from a respectable book then you are copying it all wrong.
There are lots of example programs with the Arduin IDE. Study several of them until you are familiar with the basic concepts of creating a program.
With Arduino, we have the function Serial.parseFloat(), which returns a float type number, which is easily printed with Serial.println(). So read a centigrade number with parseFloat, add 273.15, print out the Kelvin result with println.
ParseFloat() takes the place of your "readline" function. The Arduino Serial functions are very useful for this kind of utilitarian programming. Use parseFloat to get a floating point number from the Serial input. You can write your own filtration to be sure it's a number, within range, etc.
Here is the simplest example using these two functions in concert, to do a simple arithmatic operation:
void setup() {
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0) {
float temperature = Serial.parseFloat();
if (Serial.read() == '\n') {
temperature = temperature + 273.15;
Serial.println(temperature);
}
}
}
Upload this code to an Arduino Uno. Then open the Serial Monitor from the Arduino software, and enter a decimal number that is greater than -273,15.
Giving the answer to an obvious homework problem/test question does a disservice to the students that actually try; the ones who respect themselves and take their education seriously. In fact those students may get a lower grade than the loser begging for answers because they don't get the benefit of an experts knowledge. Also, because the serious student may struggle for a longer period of time figuring out problems, they have less time for other classes so they have to work harder.
IMO the losers should be allowed to fail. I sure would give a -1 for giving the idiot the answer and another for hurting the student that tries.
Write and print out an Arduino C program which includes four functions: void setup(), void loop(), int ReadLine(char str[]), and the programmer-defined function int kelvinTemperature(celcius). Function loop() should have the user enter a value for the current temperature in degrees celsius, call the function kelvinTemperature to calculate the temperature in degrees Kelvin, and display the calculated value.
Start with the framework
int readLine(char *str)
{
// check robin's http://forum.arduino.cc/index.php?topic=396450.0 to get ideas
}
int kelvinTemperature(int celsius)
{
}
void setup()
{
}
void loop()
{
// call readLine and check if a complete line is read
// if a complete line is read, convert text to number (read up on atoi and atof), call kelvinTemperature and display the result
}
Don't worry, not all is lost. This can't be the end of their class (or it'd be too simple to be a serious subject), and as OP doesn't seem to understand the least of what he's doing here, and didn't learn, he'll just get behind so much that very soon he'll just fail even harder.
I always start an explanation by just telling a student how to do something. For a lot of students, starting from a working example is the easiest way to learn. I don't think talking in circles around the problem is a very good way to lead a student (especially a struggling student) to the answer. In my experience that often turns students off.
My example showed how to use the Arduino platform to do a simple program. The assignment however was about writing a function, kelvinTemperature(celcius), which my program did not do.
Given my example as a starting point, Luther (or any other student in the class) would needed to write a short function to accomplish the conversion, rather than do the arithmetic inline. I believe using a user written function is the point of this assignment.
So no, turning in such a simplistic answer, which did not accomplish the basic requirements of the assignment would not have earned the student an A.