Show Posts
Pages: 1 ... 7 8 [9] 10 11 ... 41
121  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 06, 2014, 04:07:07 am
Dear all,
The problem i am facing as below.
1:IN main on serial monitor is not all printing
2). In lcd_call(), When entered into any case Instead of staying particular case, going back to case 1.i have attached image also for understanding


Code:
void loop()
{
Serial.println("In main");
lcd_call();
}

void lcd_call()
{
int menuOption=0;
  int button;
  do
  {
     
  switch(menuOption)
  {
  case 0:Serial.println("set+date:");Display_Date_Time(); timedBeep(shortBeep,1);break;
  case 1:Serial.println("DISPLAY:");lcdClear();lcd.print("DISPLAY MENU"); timedBeep(shortBeep,1);   break;
  case 2:Serial.println("SET MENU:");lcdClear();lcd.print("SET MENU"); timedBeep(shortBeep,1);   break;
  }
    button=read_LCD_buttons();
     if(button==btnRIGHT)
  {
    menuOption=menuOption+1;
    if(menuOption>2)
    {
      menuOption=0;
    }
  }else
  {
   menuOption;
  }   
 
 
  }while(menuOption<menuOptions);

 
}

122  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 06, 2014, 01:40:45 am
My New function are defined step by step:

Variable declaration:
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int adc_key_in = 0;
#define btnRIGHT  0 // Okay
#define btnUP     1 // inc
#define btnDOWN   2 // dec
#define btnLEFT   3 // Select
#define btnSELECT 4 // Menu
#define btnNONE   5
int Display_count=0;
int Update_Display=0;
float latitude=13.0;
float longitude=80.0;
float Wind_Kmph=13.0;
float Wind_Speed=38.0;
float DESIRE=45.0;
float ACTUAL=43.0;
static int local_day;
static int local_month;
static int local_year;
int local_s;
static int local_h;
static int local_m;
int lastDay = 0;
int lastMonth = 0;
int lastYear = 0;
int lastHour = 0;
int lastMinute = 0;
int lastSecond=0;
typedef enum {
  DATE_TIME,
  COORDINATE,
  WINDSPEED,
  POSITIONTRACK,
  DISPAY_PARAMETER,
  SET_PARAMETER,
  DISPLAY_TYPE_MAX
}
DISPLAY_SCREEN_TYPE;
DISPLAY_SCREEN_TYPE display_screen_type=DATE_TIME;
function called from Loop()
Code:
void setup()
{
}

void loop()
{

  Display_LCD();
  Chk_key();
}

check display code:
Code:

void Display_LCD()
{

  Display_count=Display_count+1;
  Serial.print("Display_count");
  Serial.println(Display_count);
  int newdata;
  int olddata;
  if(newdata!=olddata)
    olddata=newdata;
  else
    newdata;

  if(Update_Display==1)
  {
    switch(display_screen_type)
    {
      lcdClear();
    case DATE_TIME:     
      digitalClockDisplay();
      break;
    case COORDINATE:     
      Display_coordinate();
      break;
    case WINDSPEED:     
      Display_Wind();
      break;
    case POSITIONTRACK: 
      Display_angle();
      break;
    case DISPAY_PARAMETER:
      Display_fun();
      break;//display_screen_type=SET_PARAMETER;Update_Display=1;break;
    case SET_PARAMETER:
      Set_Fun();
      break;//display_screen_type=DATE_TIME;Update_Display=1;break;
    case DISPLAY_TYPE_MAX:
      break;
    default:
      digitalClockDisplay();
    }
    Update_Display=0;
    if(display_screen_type>DISPLAY_TYPE_MAX)
    {
      display_screen_type=DATE_TIME;
    }
  }
  else

      if(Display_count>5)
    {
      Update_Display=1;
      Display_count=0;
    }

}



check button  code:
Code:

void Chk_key()
{
  int button=read_LCD_buttons();

  switch(button)
  {
  case 0:// RIGHT/MENU BUTTON BEING SELECTED
    Action_RIGHT();
    break;
  case 1:// UP KEY/INCREMENT PRESSED   
    Action_UP(); 
    break;
  case 2: // DOWN / DECREMENT KEY  PRESSED
    Action_DOWN();
    break;
  case 3://LEFT / ESCAPE KEY PRESSED
    Action_LEFT();
    break;
  case 4://SELECT KEY PRESSED
    Action_SELECT();
    break;   
  }
}
action for RIGHT of key defined here:

Code:

void Action_RIGHT()
{
  int button=read_LCD_buttons();

  switch(display_screen_type)
  {
  case DATE_TIME:
    Chk_key();
    if(button==btnRIGHT)
    {
      Update_Display=1;
      display_screen_type=DISPAY_PARAMETER;
    }
    else
    {
      Update_Display=1;
      display_screen_type=DATE_TIME;
    }
  case DISPAY_PARAMETER:
    if(button==btnRIGHT)
    {
      Update_Display=1;
      display_screen_type=SET_PARAMETER;
    }
    else
    {
      Update_Display=1; 
      display_screen_type=DISPAY_PARAMETER;
    }
  }
}
Problem i am facing here in this part.Initially controller it should show date/time. Once right key pressed change to Display parameter and again pressed to setparameter. Depend on status of key pressed i know in which state display screen is and then choose key to navigate. Currently working with Right key action.   
123  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 06, 2014, 01:30:31 am
Compiler not giving any error
124  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 06, 2014, 12:30:54 am
I modified code little bit .As you all said .i am checking previous state and current state. Let me know uis syntax is correct or not


Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int adc_key_in = 0;
#define btnRIGHT  0 // Okay
#define btnUP     1 // inc
#define btnDOWN   2 // dec
#define btnLEFT   3 // Select
#define btnSELECT 4 // Menu
#define btnNONE   5
int Display_count=0;
int Update_Display=0;
float latitude=13.0;
float longitude=80.0;
float Wind_Kmph=13.0;
float Wind_Speed=38.0;
float DESIRE=45.0;
float ACTUAL=43.0;
static int local_day;
static int local_month;
static int local_year;
int local_s;
static int local_h;
static int local_m;
int lastDay = 0;
int lastMonth = 0;
int lastYear = 0;
int lastHour = 0;
int lastMinute = 0;
int lastSecond=0;

typedef enum {
  DATE_TIME,
  COORDINATE,
  WINDSPEED,
  POSITIONTRACK,
  DISPAY_PARAMETER,
  SET_PARAMETER,
  DISPLAY_TYPE_MAX
}
DISPLAY_SCREEN_TYPE;
DISPLAY_SCREEN_TYPE display_screen_type=DATE_TIME;



void setup()
{
}

void loop()
{

  Display_LCD();
  Chk_key();
}

void lcdClear(){
  lcd.clear();
  lcd.begin(16,2);
  lcd.setCursor(0,0);
}

void Display_fun()
{
  lcdClear();
  lcd.print("DISPAY PARA:");
}

void Set_Fun()
{
  lcdClear();
  lcd.print("SET PARAMETER:");
}
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, 131, 307, 481, 722
  // we add approx 50 to those values and check to see if we are close
  // No button pressed should be 1023
  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 Chk_key()
{
  int button=read_LCD_buttons();

  switch(button)
  {
  case 0:// RIGHT/MENU BUTTON BEING SELECTED
    Action_RIGHT();
    break;
  case 1:// UP KEY/INCREMENT PRESSED   
    Action_UP(); 
    break;
  case 2: // DOWN / DECREMENT KEY  PRESSED
    Action_DOWN();
    break;
  case 3://LEFT / ESCAPE KEY PRESSED
    Action_LEFT();
    break;
  case 4://SELECT KEY PRESSED
    Action_SELECT();
    break;   
  }
}







void Action_RIGHT()
{
  int button=read_LCD_buttons();

  switch(display_screen_type)
  {
  case DATE_TIME:
    Chk_key();
    if(button==btnRIGHT)
    {
      Update_Display=1;
      display_screen_type=DISPAY_PARAMETER;
    }
    else
    {
      Update_Display=1;
      display_screen_type=DATE_TIME;
    }
  case DISPAY_PARAMETER:
    if(button==btnRIGHT)
    {
      Update_Display=1;
      display_screen_type=SET_PARAMETER;
    }
    else
    {
      Update_Display=1; 
      display_screen_type=DISPAY_PARAMETER;
    }
  }
}

void Action_UP()
{
  lcdClear();
  lcd.print("UP");


}

void Action_DOWN()
{
  lcdClear();
  lcd.print("DOWN");
}


void  Action_LEFT()
{
  lcdClear();
  lcd.print("LEFT");
}

void Action_SELECT()
{
  lcdClear();
  lcd.print("SELECT");
}




void Display_LCD()
{

  Display_count=Display_count+1;
  Serial.print("Display_count");
  Serial.println(Display_count);
  int newdata;
  int olddata;
  if(newdata!=olddata)
    olddata=newdata;
  else
    newdata;

  if(Update_Display==1)
  {
    switch(display_screen_type)
    {
      lcdClear();
    case DATE_TIME:     
      digitalClockDisplay();
      break;
    case COORDINATE:     
      Display_coordinate();
      break;
    case WINDSPEED:     
      Display_Wind();
      break;
    case POSITIONTRACK: 
      Display_angle();
      break;
    case DISPAY_PARAMETER:
      Display_fun();
      break;//display_screen_type=SET_PARAMETER;Update_Display=1;break;
    case SET_PARAMETER:
      Set_Fun();
      break;//display_screen_type=DATE_TIME;Update_Display=1;break;
    case DISPLAY_TYPE_MAX:
      break;
    default:
      digitalClockDisplay();
    }
    Update_Display=0;
    if(display_screen_type>DISPLAY_TYPE_MAX)
    {
      display_screen_type=DATE_TIME;
    }
  }
  else

      if(Display_count>5)
    {
      Update_Display=1;
      Display_count=0;
    }

}


void Display_coordinate()
{
  //  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Latitude:");
  lcd.print(latitude);
  lcd.setCursor(0,1); 
  lcd.print("Longitude:");
  lcd.print(longitude);

}



void  Display_Wind()
{
  //Wind_calc();
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("WS kmph:");
  lcd.print(Wind_Kmph);
  lcd.setCursor(0,1); 
  lcd.print("WS m/s:");
  lcd.print(Wind_Speed);

}

void   Display_angle()
{
  //calcPos();
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("DESIRED: ");
  lcd.print(DESIRE,DEC);
  lcd.setCursor(0,1);
  lcd.print("ACTUAL: ");
  lcd.print(ACTUAL,DEC);
}


void digitalClockDisplay()
{
  //calcTime();
  // Serial.print(local_s);
  lcd.begin(16,2);
  lcdClear();
  lcd.setCursor(0,0);
  lcd.print("Date:");
  lcd.print(local_day);
  lcd.print("/");
  lcd.print(local_month);
  lcd.print("/");
  lcd.print(local_year);
  lcd.print("    ");
  lcd.setCursor(0,1);
  lcd.print("Time:");
  lcd.print(local_h);
  lcd.print(":");
  lcd.print(local_m);
  lcd.print(":");
  lcd.print(local_s);
  lcd.print("   ");

  lastDay = local_day;
  lastMonth = local_month;
  lastYear =local_year;
  lastHour = local_h;
  lastMinute = local_m;
  lastSecond=local_s;

  Serial.print("Local Date:");
  Serial.print(local_day);
  Serial.print("/");
  Serial.print(local_month);
  Serial.print("/");
  Serial.println(local_year);
  Serial.print("local_time is:");
  Serial.print(local_h);
  Serial.print("-");
  Serial.print(local_m);
  Serial.print("-");
  Serial.println(local_s);

}


125  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 04, 2014, 05:09:49 am
Flickering problem being solved . The problem i am facing now when i call LCD call in Menuoption 2: section While chnanging set parameter directly back to main program.
126  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 03, 2014, 11:21:30 pm
I am thinking the problem in code in this statement

Code:
'
void loop()
{
int button;
 while(( button = read_LCD_buttons()) != btnNONE)
    {
      calcTime();
      lcdClear();
      //digitalClockDisplay();
      lcd_call();
    }

}

127  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 03, 2014, 12:59:36 am
Post all your code. Or perhaps you should post your snippets at http://snippets-r-us.com/

code has been already pasted . CHeck starting of link
Main code:
http://paste.ubuntu.com/7025788/

lcd.h
  http://paste.ubuntu.com/7025947/
LCD.c

http://paste.ubuntu.com/7025949/

glob.h

http://paste.ubuntu.com/7025951/
128  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 02, 2014, 11:14:25 pm
Can some one suggest me the algorithm/flowchart of the program for above problem
129  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 01, 2014, 05:19:17 am
SOlved menu section

Code:
void lcd_call()
{
  int button = 0;
  int menuOption=1;
  lcdClear();
  lcd.print("MENU DISPLAY:");
   button = read_LCD_buttons();
  while (menuOption <= menuOptions)
  {
  // button = read_LCD_buttons();
if (button == btnRIGHT)
    {
      timedBeep(shortBeep,1);   
      menuOption=menuOption+1;
      Serial.print("menuOption:");
      Serial.println(menuOption);
    }
    else
    {
      menuOption;
      Serial.print("menuOption:");
      Serial.println(menuOption);
    }

Display function
Code:
switch(menuOption)
case 1:
      lcdClear();
      lcd.print("DISPLAY PARAMETER");
      timedBeep(beep,1);
      delay(300);
 while((button = read_LCD_buttons()) != btnRIGHT)

      {

        int DS_Counter;
        Serial.println(button);
        DS_Counter=Display_selection();
        Serial.print("DS_Counter:");
        Serial.println(DS_Counter);
        switch(DS_Counter)
        {
        case 1:  
          lcd.setCursor(0,0);
          digitalClockDisplay();
          timedBeep(shortBeep,1);  
          break;
        case 2:
          lcd.setCursor(0,0);
          Display_angle();
          timedBeep(shortBeep,1);
          break;
        case 3:
          lcd.setCursor(0,0);
          Display_coordinate();
          timedBeep(shortBeep,1);
          break;
        case 4:
          lcd.setCursor(0,0);
          Display_Wind();
          timedBeep(shortBeep,1);
          break;
        case 5:
          DS_Counter=1;
          break;  
        }
        //button = read_LCD_buttons();
            
      }
Display_selection() defined here
Code:


int Display_selection()
{
  int button = read_LCD_buttons();

  if(button==btnUP)
    Display_counter++;
  if(button==btnDOWN)
    Display_counter--;


  if(Display_counter>=5 ||Display_counter<=0)
  {
    Display_counter=1;
  }
  return(Display_counter);

}

Code:
void digitalClockDisplay()
{
  calcTime();
 // Serial.print(local_s);
  //lcd.begin(16,2);

  
  lcd.setCursor(0,0);
  lcd.print("Date:");
  lcd.print(local_day);
  lcd.print("/");
  lcd.print(local_month);
  lcd.print("/");
 lcd.print(local_year);
 lcd.print("    ");
  lcd.setCursor(0,1);
  lcd.print("Time:");
  lcd.print(local_h);
  lcd.print(":");
  lcd.print(local_m);
  lcd.print(":");
 lcd.print(local_s);
 lcd.print("   ");
 
 lastDay = local_day;
    lastMonth = local_month;
    lastYear =local_year;
    lastHour = local_h;
    lastMinute = local_m;
    lastSecond=local_s;
    olddata=1;
//  button = read_LCD_buttons();

 
 
 
Serial.print("Local Date:");
  Serial.print(local_day);
  Serial.print("/");
  Serial.print(local_month);
  Serial.print("/");
  Serial.println(local_year);
  
//Serial.print("         ");

  Serial.print("local_time is:");
  Serial.print(local_h);
  Serial.print("-");
  Serial.print(local_m);
  Serial.print("-");
  Serial.println(local_s);
  
}






130  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 01, 2014, 05:02:06 am
Quote
Thanks it Clear Idea why it got Flicker.
The printing takes time and maybe that affects the flicker rate but that is all.
[/quote]

The reason i found flicker:
1)lcd.print being called so fast that execution time of loop
2)The printing takes time and maybe that affects the flicker rate but that is all.
3) Initialize of the LCD screen whenever they being called.That means Initialize done once @ time
131  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 01, 2014, 04:56:44 am
As you said i changed it to below. still flickering is there.
Code:
void loop()
{
  int button;
  while(( button = read_LCD_buttons()) != btnNONE)
  {
  lcd_call();
  }
    digitalClockDisplay();
}



As you said i changed to below code. It working fine Now.
Code:
void loop()
{
  int button;
 while(( button = read_LCD_buttons()) != btnNONE)
  {
  calcTime();
  lcdClear();
  //digitalClockDisplay();
  lcd_call();
 }
digitalClockDisplay();
delay(500);
}
As you said  IF case  used, its very difficult to track of various false condition.IS there any other case i can solve above issue
yes i accept i written my code badly.

i can't understand this statement:
Quote
You have the structure of the switch statement wrong, the first statement  switch(menuOption) must be followed by a case, you have some sort of 'if' structure before the first case.

In my case :
Code:
while (menu_counter< menu option)
   if (button ==RIGHT)
      {
       change menu;
      }
else
{
   digital clock display();
}



However this function is so badly written it is beyond a simple fix.
You have the structure of the switch statement wrong, the first statement  switch(menuOption) must be followed by a case, you have some sort of 'if' structure before the first case.
You must do the same with this function as with the first and only proceed to clear and write to the LCD when something has changed, in this case that something will be the state of your buttons, So just like I showed you how to do it in the digitalClockDisplay function, you test to see if any of the buttons have changed from last time and if they have not then return from the function immediately.

[/quote]
132  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 01, 2014, 04:41:03 am
Quote
Yes and I and others have told you that reason and you fail to understand it and ask for an example. I give you an example and you still ask for the reason. This has already been given to you.

These two functions are used to print Serial monitor.digital clock is to print it on Lcd_Screen ,Here  i am trying to understand . How Serial.print statement affect my LCD.print Statement here. because if i chosen same ports for both . assuming i use one port @ time and somehow using two pins simultaneously.
Code:
Print_Date();
Print_Time();
delay(500);

133  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 01, 2014, 04:22:03 am
Quote
i need reason if i change particular thing it will solve my problem
Yes and I and others have told you that reason and you fail to understand it and ask for an example. I give you an example and you still ask for the reason. This has already been given to you.
Let me try again in bigger font:-

Only display something to the LCD when something has changed.

AS YOU TOLD I REMOVED THE  FUNCTION , AND KEPT IN Serial.print IN DIGITAL CLOCK. BUT THE FLICKER PROBLEM NOT SOLVED

Code:
Print_Date();
     Print_Time();
     delay(500);
134  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 01, 2014, 04:10:58 am
Quote
but question how it solve my problem.
I have told you, and so have others.

So it is not worth helping you if this is all you are going to say.

A sensible response would have been:-
Thanks I have tried that and "insert here what you saw" happened, now I want to print the data and the time to the serial monitor, how do I do that?



Sorry for that. i need reason if i change particular thing it will solve my problem. Which could help me understand better.
135  Using Arduino / Programming Questions / Re: Call a function from main once @ time on: March 01, 2014, 04:08:22 am
The problem facing explained here

Code:
MY LOOP FUNCTION:
void loop()
{
  int button;

 while(( button = read_LCD_buttons()) != btnNONE)
  {
  calcTime();
  lcdClear();
  //digitalClockDisplay();
  lcd_call();
 }
IF NONE OF KEY BEING PRESSED IT KEEP ON DISPLAYING DIGITAL CLOCK.


digitalClockDisplay();
delay(500);

Code:
void   lcd_call()
{
[b]choose Right key to change menu[/b]  This part working FIne

pressed once: Display function();
pressed twice : Set_function();
pressed thrice: EXIT and BACK to Display_time

In Display Function()
WORKING FINE:
UP: increment Display menu
Down: Decrement Display Menu
LEFT:EXIT
RIGHT : change menu
 
Problem: Once enter particular display window after some time directly exit to Date and time ,
Reason: because NONE of key being pressed
IS it possible to stay here in particular Display window until Display Exit Key pressed i.e LEFT


SET_FUNCTION()
UP:INCREMENT VALUE / increment menu set
DOWN : DECREMENT VALUE/ decrement menu set
RIGHT: OK
LEFT :EXIT

PROBLEM :
1) i could not able to change Set parameter  Menu, but i can change in Display
2)While Setting parameter , Set_parameter() exit to Digital_clock function. Is there any way to stay in Set_parameter()  unless all parameter being set or exit key pressed.


}



Pages: 1 ... 7 8 [9] 10 11 ... 41