Go Down

Topic: AS BEGINNER (Read 968 times) previous topic - next topic


Nov 19, 2012, 12:18 pm Last Edit: Nov 19, 2012, 12:20 pm by Nick2012Future Reason: 1
I have some couple of minor problems, I just don't know how to solve them.
(Objectif 1: Use a RES variable in math equation )
On first image of Arduino, I can't figure out how to put ",2" character to get two decimals on Serial monitor.

(Objectif 2: Test measurement on D2 using boolean)  
On second image, I can't understand an error in my void setup  

Thanks a lot. Sorry for french comments.    


First, posting pictures of your code is nowhere near as good as posting your real code. We can't cut and paste mistakes from your pictures.

Also, once we go to reply mode, the pictures go away.

I can't figure out how to put ",2" character to get two decimals on Serial monitor.

It goes INSIDE the parentheses. It's an optional argument. It's also the default. Of course, it only applies to printing floats or doubles (which are really floats, too). Printing an int to two decimal places makes no sense.

On second image, I can't understand an error in my void setup

Your code is full of errors. Some time spent with the reference page would be much more beneficial than my pointing them all out.

The art of getting good answers lies in asking good questions.


There are several problems.

The ',2' arguments you're trying to pass to Serial.print need to be inside the brackets, as PaulS pointed out.

In your case the numbers you're printing are integers (whole numbers) so for example 5/2 is equal to 2.5 but when you use integer arithmetic the '.5' is lost and the answer is 2. If you're printing integers then the second argument isn't required anyway.

In your print statements you are printing values like this:
Code: [Select]

Serial.print(RES = RES/2);

That has two effects: it prints the value of  RES/2, and it also assigned that value back to RES so RES is no longer equal to five - this would affect the results of all the subsequent calculations. If you only want to print the value of RES/2 without changing the value of RES in the process, then you can do it like this:

Code: [Select]



I'm sorry to say this, but you really don't have much of a clue, do you?  I think there are more incorrect lines that there are correct ones.

You need to go back to absolute basics.  Before you do ANY programming, you need to understand the BASIC SYNTAX of the language.

You should read and thoroughly understand this PDF file: www.cs.mcgill.ca/~adenau/teaching/cs206/lecture10.pdf

It details the basic syntax of the C language, and once you know that, you will quickly see where all your errors are.


Sorry for french comments.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


Ok! I think I got it finally, I have just to mention float to initiate my variables and then I can select number of decimals.

Thanks a lot for tutorials!! 

Go Up