NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Support Forum » A few interesting things I noticed when reading thru the USB NerdKits Guide
May 10, 2010 by Steve35897 |
First there is a contradiction about hooking up the LCD back light. Step 4a on page 28 contradicts what is in Appendix D: The LCD backlight. So will the backlight work with the battery or not? Also the code for the temperature sensor on page 54 seems to be wrong. The last line of the for loop on page that says "temp_avg = temp_avg + this_temp/100; " I don't believe this method of running average will work. Maybe if you substitute i where the 100 is may work. Just my observations. I haven't started on the kit yet just spent some time reading through the guide |
---|---|
May 10, 2010 by Ralphxyz |
Hi Steve, The LCD will work off the battery, but as noted the battery life will be drastically reduced! The tempsensor code works as published. Ralph |
May 10, 2010 by hevans (NerdKits Staff) |
Hi Steve35897, Just to try to clear up your question about the averaging code. What we have there isn't really a running average, it is just a way to arrive at the average over 100 samples. Notice that we are in a loop that will grab 100 samples. If you wanted to average over those 100 samples, you could add them all up and then divide by 100, or you could divide each of them by 100 and then add up the results. That is what this code is doing. After taking 100 samples, the code will arrive at the average. Does that make sense? Humberto |
May 10, 2010 by Steve35897 |
It makes sense in theory but if you do it on paper it doesn't work. Trying to do it manually for 100 samples would take a long time. So I used some nice easy numbers and just did it for 5 samples instead of 100 which should work if the formula works. I also used an easy temp of 100 which seemed like a nice number to work with. So the first one the average is 0. 1st sample is 0+100/5=20, 2nd sample is 20+100/5=24, 3rd sample is 24+100/5=24.8, 4th sample is 24.8+100/5=24.96, 5th sample is 24.96+100/5=24.99. Do you see a trend? So my conclusion is that the formula doesn't work. If the code works then it isn't using that line of code. |
May 10, 2010 by hevans (NerdKits Staff) |
Hi Steve, I see where you are getting confused. C follows the same order of operations that you are used to from algebra class. Multiplications and divisions will happen before addition and subtraction. Using your example the code would do the following:
If you wanted to alter the order of operations you would have to put parenthesis around the addition (20+100)/5 would equal 24. Hope that clears it up! Humberto |
May 10, 2010 by Steve35897 |
Yes I see now. Thanks for clearing that up for me |
Please log in to post a reply.
Did you know that using an alternating excitation voltage can reduce the noise in many sensor measurements? Learn more...
|