Pages: [1]   Go Down
Author Topic: millis()/1000 counting away like crazy.  (Read 467 times)
0 Members and 1 Guest are viewing this topic.
Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all.

Using MEGA 2560 with LCD Keypad Shield.
Playing around with the sample code provided at http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)

Code:
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
 
/*******************************************************
 
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010

********************************************************/
 
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
 
// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5


// Set up a bunch of arrays for future usage in matrix
String profileName[5];
String stepOneName[5];
int stepOneTemp[5];
int stepOneTime[5];
String stepTwoName[5];
int stepTwoTemp[5];
int stepTwoTime[5];
String stepThreeName[5];
int stepThreeTemp[5];
int stepThreeTime[5];
String stepFourName[5];
int stepFourTemp[5];
int stepFourTime[5];

String effectProfileName[2];
String effectHigh[2];

int selectedProfile = 0;
int tempLossInSystem = 0;

// read the buttons
int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;   
 return btnNONE;  // when all others fail, return this...
}
 
void setup()
{

//HELP NEEDED HERE - START
// setupDefaultSteps();  // Populate with some default values
//HELP NEEDED HERE - STOP

 delay(1000);
 lcd.begin(16, 2);              // start the library
 lcd.setCursor(0,0);
 lcd.print("Push the buttons"); // print a simple message
}
 
void loop()
{
 lcd.setCursor(9,1);            // move cursor to second line "1" and 9 spaces over
 lcd.print(millis()/1000);      // display seconds elapsed since power-up
 
 
 lcd.setCursor(0,1);            // move to the begining of the second line
 lcd_key = read_LCD_buttons();  // read the buttons
 
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnRIGHT:
     {
     lcd.print("RIGHT ");
     break;
     }
   case btnLEFT:
     {
     lcd.print("LEFT   ");
     break;
     }
   case btnUP:
     {
     lcd.print("UP    ");
     break;
     }
   case btnDOWN:
     {
     lcd.print("DOWN  ");
     break;
     }
   case btnSELECT:
     {
     lcd.print("SELECT");
     break;
     }
     case btnNONE:
     {
     lcd.print("NONE  ");
     break;
     }
 }
 
}



void setupDefaultSteps()
{
profileName[0] = "1 step Light";
stepOneName[0] = "Strike temp.";
stepOneTemp[0] = 71;
stepOneTime[0] = 2;
stepTwoName[0] = "Sacc. rest";
stepTwoTemp[0] = 64;
stepTwoTime[0] = 75;
stepThreeName[0] = "Mash out";
stepThreeTemp[0] = 76;
stepThreeTime[0] = 10;
stepFourName[0] = "";
stepFourTemp[0] = 0;
stepFourTime[0] = 0;
 
profileName[1] = "1 step Medium";
stepOneName[1] = "Strike temp.";
stepOneTemp[1] = 73;
stepOneTime[1] = 2;
stepTwoName[1] = "Sacc. rest";
stepTwoTemp[1] = 67;
stepTwoTime[1] = 60;
stepThreeName[1] = "Mash out";
stepThreeTemp[1] = 76;
stepThreeTime[1] = 10;
stepFourName[1] = "";
stepFourTemp[1] = 0;
stepFourTime[1] = 0;

profileName[2] = "1 step Full";
stepOneName[2] = "Strike temp.";
stepOneTemp[2] = 75;
stepOneTime[2] = 2;
stepTwoName[2] = "Sacc. rest";
stepTwoTemp[2] = 69;
stepTwoTime[2] = 45;
stepThreeName[2] = "Mash out";
stepThreeTemp[2] = 76;
stepThreeTime[2] = 10;
stepFourName[2] = "";
stepFourTemp[2] = 0;
stepFourTime[2] = 0;

profileName[3] = "2 steps Light";
stepOneName[3] = "Strike temp.";
stepOneTemp[3] = 54;
stepOneTime[3] = 2;
stepTwoName[3] = "Protein rest";
stepTwoTemp[3] = 50;
stepTwoTime[3] = 30;
stepThreeName[3] = "Sacc. rest";
stepThreeTemp[3] = 64;
stepThreeTime[3] = 75;
stepFourName[3] = "Mash out";
stepFourTemp[3] = 76;
stepFourTime[3] = 10;

profileName[4] = "2 steps Medium";
stepOneName[4] = "Strike temp.";
stepOneTemp[4] = 54;
stepOneTime[4] = 2;
stepTwoName[4] = "Protein rest";
stepTwoTemp[4] = 50;
stepTwoTime[4] = 30;
stepThreeName[4] = "Sacc. rest";
stepThreeTemp[4] = 67;
stepThreeTime[4] = 45;
stepFourName[4] = "Mash out";
stepFourTemp[4] = 76;
stepFourTime[4] = 10;

profileName[5] = "2 steps Full";
stepOneName[5] = "Strike temp.";
stepOneTemp[5] = 54;
stepOneTime[5] = 2;
stepTwoName[5] = "Protein rest";
stepTwoTemp[5] = 50;
stepTwoTime[5] = 30;
stepThreeName[5] = "Sacc. rest";
stepThreeTemp[5] = 67;
stepThreeTime[5] = 45;
stepFourName[5] = "Mash out";
stepFourTemp[5] = 76;
stepFourTime[5] = 10;
}


When I have the following section commented out the "lcd.print(millis()/1000);" prints every second since start as it suppose to

Code:
//HELP NEEDED HERE - START
// setupDefaultSteps();  // Populate with some default values
//HELP NEEDED HERE - STOP

But when I change like below to populate arrays in the function "setupDefaultSteps"  "lcd.print(millis()/1000);" prints like crazy.

Code:
//HELP NEEDED HERE - START
setupDefaultSteps();  // Populate with some default values
//HELP NEEDED HERE - STOP

Anyone know what I am doing wrong or why it behaves this way?

Br,
Magnus
Logged

UK
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In setupDefaultSteps(), how many profiles are you setting up?

When defining the arrays, how many slices are you allocating?

Answer those two questions and you may be part way to fixing your problem.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But when I change like below to populate arrays in the function "setupDefaultSteps"  "lcd.print(millis()/1000);" prints like crazy.

What does print like crazy mean? What is it printing? Are you saying it's changing quickly?
Logged

Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes. Counts rapidly.

But advice that majenko gave fixes it (as below).



Code:
// Set up a bunch of arrays for future usage in matrix
String profileName[6];
String stepOneName[6];
int stepOneTemp[6];
int stepOneTime[6];
String stepTwoName[6];
int stepTwoTemp[6];
int stepTwoTime[6];
String stepThreeName[6];
int stepThreeTemp[6];
int stepThreeTime[6];
String stepFourName[6];
int stepFourTemp[6];
int stepFourTime[6];
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using the String class for strings that do not change is a waste of precious memory. Get out of that habit NOW!
Logged

Pages: [1]   Go Up
Jump to: