Timer and LCD problems but not basic. Need a pro.

Hi guys, I feel really bad like a leech here but I'm in no position to help anyone 'yet'. When I am in that position I will. Your help is greatly appreciated!

I started this sketch before I knew anything really(still don't tbh). Finished about 50% before I even knew about arrays. I just used simple example type code and went on from there. It works but its very crappy how I coded it. Even I know that. I really don't want to redo this now. Its almost done and I learned from it. I want to learn to code properly after this. :slight_smile:

I'm having two problems I need some help with.. The first is a timer. In my original sketch I used millis() and another variable previousmillis as a seconds counter. Very simple. When millis() > previousmillis by 1000 it updates counter variable then resets previousmillis. This worked great although I need to use smaller increments of time like increments of .25 all the way up to 9.00.

The weird thing is the .25 isn't .25 seconds. It actually ends up being 4 seconds. There's another variable that is a setpoint that needs to ramp up at that rate(by .25 a degree by a second). I really hope that makes sense.

.25 = 4000 milliseconds
.50 = 2000 milliseconds
1 = 1000 milliseconds

If that doesn't make sense I'll wait until tomorrow to explain I'm sure it'll sound better.

The second problem is I'm using an lcd menu. Simple crap coded one but very effective. You guys helped with it it actually. I added the eeprom functions to save/load everything and its working. I'm finally adding the sketches together and I'm having a problem going from loop() to MENU states. Whats happening is I setup the IDLE menu in loop() function. When I load the REFLOW_STATE_IDLE state I tried to simply clear the lcd before hand but it keeps redrawing. I figured that I should go straight to REFLOW_STATE_IDLE THEN setup the lcd menu but then none of my buttons worked. How it is now, if I press the edit menu button it writes the menu over top the existing idle lcd setup. if I'm in a menu and press cancel I have it setup to go to idle but it works fine that way with a simple lcd.clear();
]
Any help would be greatly appreciated on either problem.

Its about 40k of code so I uploaded it to mediafire. Its still a work in progress with other problems but these are most important now. I also have other variables and another finite state machine that aren't used yet. Again, I know the code is whack but I'm like a first grader trying to do this. Its working so far and I really am planning on learning to code the right way. Just my first project.

EDIT:For timer problem open sketch and search for REFLOW_STATE_STEP_1_RAMP. For LCD problem search for void loop() and go from there. Thanks again I'm really stuck on these problems.....

Every time through loop() you do a lot of writing to the LCD:

  lcd.setCursor(1, 1);
  lcd.print("PTN:");
  lcd.print(currentProfile);
  lcd.setCursor(13, 1);
  lcd.print("STEP:");
  lcd.print(currentStep);
  lcd.setCursor(1, 2);
  lcd.print("TH");
  lcd.setCursor(5, 2);
  lcd.print("SV:");           
  lcd.setCursor(13, 2);
  lcd.print("PV:");
  lcd.setCursor(1, 3);
  lcd.print("BH");
  lcd.setCursor(5, 3);
  lcd.print("SV:");
  lcd.print(sv2);
  lcd.setCursor(13, 3);
  lcd.print("PV:");

Unless that part of the display is common to every state, you should probably draw it only in the states where it is needed.

noobdude:
The first is a timer. In my original sketch I used millis() and another variable previousmillis as a seconds counter. Very simple. When millis() > previousmillis by 1000 it updates counter variable then resets previousmillis. This worked great although I need to use smaller increments of time like increments of .25 all the way up to 9.00.

The weird thing is the .25 isn't .25 seconds. It actually ends up being 4 seconds. There's another variable that is a setpoint that needs to ramp up at that rate(by .25 a degree by a second). I really hope that makes sense.

.25 = 4000 milliseconds
.50 = 2000 milliseconds
1 = 1000 milliseconds

If that doesn't make sense I'll wait until tomorrow to explain I'm sure it'll sound better.

To save everyone wading through 40K+ of source code, I suggest that you extract your timing code into a separate small sketch that demonstrates the problem in the simplest way you can, and post that here.

Just an observation. I looked through the code but couldn't find these timing problems, but:

.25 seconds = 250 millis

1 second = 1000 millis

1000 / .25 = 4000
1000 * .25 = 250

That may be the source of one of your problems.

@John Yes, that's the problem exactly. I tried to make it go straight to IDLE state from loop then pasted that code to setup LCD but buttons wouldn't work after? Weird huh? I'm going to try again in a different smaller sketch and see how I can make it work.

@Peter Yes. Its a weird situation to me too. I'm not sure how to make a timer to convert .25 to 1 degree every 4 seconds VS 250ms. It works perfectly for 1 second increments of course but I need slower than that. I will write up a different sketch so its not so rough to go through and read etc. I didn't even use comments really...

@jimmy Good call! I'll / instead of * . I think that's the ticket actually!!!

Thanks for the replies guys. This is so close to being done. :slight_smile:

@jimmy60 You're a genuis! Totally worked first try. All I did was when I went

if currentMillis - previousMillis > 1000 / rampRateStep1//(.25 first try)
previousMillis = currentMillis;
counter = counter + 1
setpointRamp = startTemp + counter;//actually updates setpoint here.

WORKS PERFECT! Thanks again!

  • karma for all you guys.