temperature is displayed on the LED display.

Make a temperature monitor. The minimum components should be:

•Arduino
•Two-digit LED numeric display
•Two buttons
•Temperature sensor TMP36
The behaviour of the system should be:

•In the default state, the temperature is displayed on the LED display.
•When button 1 is pressed, the system records ten temperatures at one-second intervals, with some form of indication to show that it is gathering data. When data collection ends, the system should return to the default state, and give some form of indication that it has done so. The temperatures recorded should be stored for later use.
•When button 2 is pressed, either:
?If there are stored temperatures in memory, the system displays them.
?If there are no stored temperatures in memory, the system indicates this.

hi my friends this is my assignment for uni. I am now really confused about how to record ten temps and display on LED for ten times. and how to back to default state. thanks can anyone help me figure out for me? THANKS VERY MUCH~~~

... and how to back to default state ...

You haven't told us what you have accomplished so far.

Have you been able to implement the default state?

Don

zs63:
hi my friends this is my assignment for uni. I am now really confused about how to record ten temps and display on LED for ten times. and how to back to default state. thanks can anyone help me figure out for me? THANKS VERY MUCH~~~

So, uni is basically about teaching you how to break down problems into manageable sizes, and how to do research to solve the problems.

In terms of breaking down your assignment, you need to separate your current problem into 3 problems. 1. record and store 10 temperatures. 2. Display 1 of these stored temperatures on the LED. 3. Reset back to the default state.

I would start with trying to conquer problem 1, keeping the need to do 2 and 3 in the back of your mind. Have you thought about how you're going to solve problem 1? What have you come up with so far?

this is my code for the first step

If it is code then why didn't you use the 'insert code' button?

Your comments are hard to read, perhaps you should press harder on the keys.

Don

OK, well you've got a start there.

To make it easier for us to read, please go back and modify your post and put the code inside [ code] [ /code] tags.

The two things I think you have to do next is:

  1. work out how to store 10 temperatures. Look up arrays of floats in C++.
  2. See if you can get a number displayed on your LEDs. Change the signature of your void displayNumb() to void displayNumb(float temperature). This will also mean your tempH and tempL move inside the function. Then call the function from your loop with a test number. This will also help you later. Using parameters on functions allows you to isolate bits of code from each other, as well as allowing you to re-use code since the function then doesn't depend on global variables which can be changed somewhere else in the program. Generally speaking, using parameters to pass in the necessary data to a function is a very good way to program.

The same way you call getVoltage. Look up C++ parameter passing on the web.

In the middle of your code, you have these two lines:

 int tempH= (temperature/10);
 int tempL=(temperature-tempH*10);

I don't understand how those lines can be reached. They're not in any function.

Immediately prior to those two lines, temperature is declared as an integer although it was previously declared as an float. Is this intentional?

zs63:
sorry i not understand how to call the function in loop with a text number? can you explain to me? Thanks very much~~

I said "test number", not "text number".

arloG:
In the middle of your code, you have these two lines:

 int tempH= (temperature/10);

int tempL=(temperature-tempH*10);




I don't understand how those lines can be reached. They're not in any function. 

Immediately prior to those two lines, temperature is declared as an integer although it was previously declared as an float. Is this intentional?

These problems will go away once he passes the temperature as a parameter.

You’re getting there.

What is this for loop for?

void displayNumb(float temperature) {
for(int i=0;i<1000;i++)
{

Unless there’s a reason for it, take it out.

In this code:

void loop()
{
    float temperature = getVoltage(temperaturePin);
    temperature = (temperature - .5) * 100; 
    for (int i=0;i<10;i++)
    {
        displayNumb(temperature);
        delay(1000);
     }
}

You have the beginning of collecting 10 temperatures. You need to move the sampling of the temperature inside the for loop so that every second you get a new temperature. You also need to take that value, and instead of displaying it immediately by calling displayNumb(temperature), you need to store it in an array so that later on, you can call displayNumb(temp), where temp is one of the temperatures you stored earlier in an array. You need to look up and understand arrays. It is a fundamental concept used throughout programming.

It’s good that you have at least now tested calling displayNumb(temp) so you know you are getting something displayed.

You can’t write the code to return to the default state until you have written the code to change state, which you haven’t done yet. That is, until you’ve written the code to store the temperature values.

zs63:

void loop()

{
 
int temp[10];
 
    for(int i=0;i<10;i++)
    {
      float temperature = getVoltage(temperaturePin);
    temperature = (temperature - .5) * 100;
    temp[i]=temperature*1;
    displayNumb(temp[i]);
    Serial.print(temp[i]);Serial.println(“degree”);
    delay(1000);
     }
     delay(10000);
}





is this code correct for store 10 temps? thanks!

That looks pretty good, yes.

Now, the way the arduino works, every time you finish all the code in the loop, you exit the loop then the loop gets called again, so you re-enter the loop. So, you have to do 3 things next.

  1. The int temp[10]; has to be declared as a global variable. If you don’t do that, every time you exit the loop you will lose the values you stored.
  2. You need to only store 10 new values when button 1 is pressed, instead of every time you come into the loop. Then you can remove the delay(10000);
  3. When button 2 is pressed, you need to cycle through displaying the 10 stored temperatures.

You need to get into the habit of keeping your code clean to make it easier for both you and other people to read.

Your current code should look like this:

Note, no extra lines, columns correctly indented so we can easily see code blocks, one instruction per line.

Also, you should comment your code so you can remember what each line does, but also so people after you can tell what you were thinking.

void loop()
{ 
   int temp[10];
   int recall[10];

   if (digitalRead(buttonPin1)==LOW)
   { 
      for(int i=0;i<10;i++)
      {
         float temperature = getVoltage(temperaturePin);
         temperature = (temperature - .5) * 100; 
         temp[i]=temperature*1;
         displayNumb(temp[i]);
         Serial.print(temp[i]);
         Serial.println("degree");
         delay(1000);
      }
   }
   else if (digitalRead(buttonPin2)== LOW)
   {
      for(int i=0;i<10;i++)
      { 
         recall[i]=int(temp[i]);
         displayNumb( recall[i]);
         Serial.print(temp[i]);
         Serial.println("degree");
         delay(1000);
      }
   }
}

Now, to answer your questions:

  1. Why do you need the recall array? What is it doing for you?
  2. What would it mean to return to the default state? What is different between when you started up, and some time later? How would you return the things that have changed back to their state at the beginning?

You need to post your whole sketch again now to see where we are at. But, clean it up first like I did above with the indenting so we can read it easily.

  1. The information you need is already stored. You just need to access it.
  2. I can't tell what the problem is without seeing the complete (clean) sketch.

You need to go back through the thread and do the things I suggested, as well as think about what the lines of code are doing. All the information you need is in this thread. You just need to think about it and I'm sure you'll work it out.

The point of this exercise is not just to do the assignment. The point of the assignment is to learn, and to make sure you understand what you are doing so that you can solve problems like this yourself in the future. You need to think about every line in your code, and understand why it's there, or whether it shouldn't be there. You also need to format your code consistently so it is readable.

Hi,I'm sorry but who is arduinodlb talking too, my listing of post on this thread has got ZS63 missing except for the first post?
The post numbers are consecutive, this is number 13, but I cannot see any of zs63, except the first one.
Tom...... :slight_smile:

It looks like sz63 went back and deleted all his posts (except the first one, which you possibly can't delete). Seems an odd thing to do.

Seems an odd thing to do.

Well he got what he needed, his assignment is finished. Why let anyone else benefit from the experience?

Now all you (Ardunolib) have to do is delete all of your posts and it is TomGeorge who will look like the idiot.

Don

Hi, if it was a uni project, probably trying to remove all evidence of help. And from what I can make out good help given with great tolerance.
I don't know what they teach in uni these days but it doesn't look like the necessary information to complete a project.

You were encouraged to ask questions while doing your project and detail how you got your answers, it showed how much you had learn't.

I kinda think this may be a case of I want to be big in electronics but god I don't need to do all this hard work, but when I do I'll pick someone else's brain and call it my own, smart me.
I find I am coming across more and more tertiary students who have no clue of what is needed for them to acquire the piece of paper they hanker for. I had a final year Electronics Engineer in my workshop for "Work Experience". It seems now here in Australia an undergraduate has to do "work experience" to complete their course. (not sure how much but 6weeks worth sound right)
He was in last year of 3 year course, in the fortnight he was with us, he said he had done more soldering in that fortnight than he had ever done before.
When I was at uni, we had guys screaming for extra lab time, when the lab was vacant, to do personal projects. In most cases, depending on project this was actively encouraged, and all of us new which end of a soldering iron was hot.

I'l get of my soapbox now....lol
arduinodlb were you thanked?

Tom..... :slight_smile:
(yes that felt good...)

Indeed you cannot delete the first topic post, and this has been a topic of discussion by "scorched earth" enthusiasts.

One would think that any lecturer or tutor setting an assignment involving Arduino, would automatically scan the discussions here. One would certainly hope so.

TomGeorge:
Hi, if it was a uni project, probably trying to remove all evidence of help. And from what I can make out good help given with great tolerance.
I don't know what they teach in uni these days but it doesn't look like the necessary information to complete a project.

There definitely seemed to be some basic understanding missing. I don't know if that was the lecturer's fault, the student's fault, or both.

Paul__B:
Indeed you cannot delete the first topic post, and this has been a topic of discussion by "scorched earth" enthusiasts.

One would thank that any lecturer or tutor setting an assignment involving Arduino, would automatically scan the discussions here. One would certainly hope so.

Ahh. Good to know. Thanks Paul. Yes, I certainly hope so too. I was very careful to be helping him, rather than doing the work for him, which is really the point of his University study anyway: for him to learn. I don't think any lecturer should have a problem with the help he was getting even if they did scan here. And actually, that's reminiscent of the real world anyway. Nothing wrong with getting help from the internet when you're a professional.

That being said, he seemed to be not taking the time to understand what he should have been learning along the way. It certainly wasn't complete before he bailed, and I don' think he had yet acquired the skills to complete it himself. Maybe he worked out a way to copy it from a friend.