Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pause and resume function in arduino lcd

Status
Not open for further replies.

gayathrim

Junior Member level 3
Joined
May 13, 2019
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
253
hi, i have a keypad and 16x4 connected to an arduino. the start button in the keypad triggers a relay and show a count in the lcd. also, there is a pause/resume key as well. when the pause key is pressed once, the arduino pin powering the relay is made low. the count is paused in the lcd. while the key is pressed again, the relay pin is made high and the count resumes in the lcd. This works fine for 5-6 times until the lcd goes blank after a while. can someone suggest any solution? Thanks in advance.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
23,032
Helped
4,716
Reputation
9,448
Reaction score
5,089
Trophy points
1,393
Activity points
152,591
Hi,

can someone suggest any solution?
How could this be possible without seeing your complete code?

Klaus
 

gayathrim

Junior Member level 3
Joined
May 13, 2019
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
253
Hi,


How could this be possible without seeing your complete code?

Klaus


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 11, d5 = 10, d6 = 9, d7 = 8;    //lcd arduino interface
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
 
#define enable 2
#define load 3
#define clock 4                                                 //lcd arduino interface
#define data 5
 
void setup()
 
{ 
 
lcd.clear();
l2:
lcd.begin(16, 4);
pinMode(enable,OUTPUT);
pinMode(load,OUTPUT);                                            //define arduino pins
pinMode(clock,OUTPUT);
pinMode(data,INPUT);
 
digitalWrite(load,HIGH);
digitalWrite(enable,HIGH);
 
pinMode(13,INPUT);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(16,OUTPUT);
 
Serial.begin(9600);
 
lcd.print("SPECTRUM ANTENNA");
lcd.setCursor(0, 2);                                           //print name and set
lcd.print("SET:");
delay(200);
int k=0;
 
 
int dec_flag=0,dec_flag2=0,flag3=0;
 
float read_c=0,temp_val=0;
 
int digit_array[4]={0},pos_count=0,pos_count1=0,dec_count=0,pause_count=0,clockwise_counter=0,anticlockwise_counter=0,decimal_array[2],dec_pos2=0,dec_pos=0,pos_count2=0,dec_count2=0;
 
float angle_val=0.0,temp=0.0,new_angle_val=0.0;
 
byte incoming;
 
float duration=0.0,lowpulse=0.0;
 
l1:
lcd.setCursor(5+pos_count+pos_count1,2);
digitalWrite(load,LOW);
delayMicroseconds(5);
digitalWrite(load,HIGH);
delayMicroseconds(5);
 
 
 
digitalWrite(clock,HIGH);
digitalWrite(enable,LOW);
 
incoming=shiftIn(data,clock,MSBFIRST);                       //read the incoming 5 bits from keypad
 
digitalWrite(enable,HIGH);
 
if(incoming==31)                                             //if the incoming bits 11111, do nothing
 
    {1;}
 
else if(incoming>=0&&incoming<=9)                            //if the incoming number is digit between 0 and 9
 
{
   if(dec_flag==0)                                        //check if decimal point is used yet
      {
       digit_array[pos_count]=incoming;
       pos_count++;                                          //store the number into an array
       lcd.print(incoming);                                  //print the digits on lcd
       delay(200);
      }
 
   else if(dec_flag==1)                                   //check if decimal point is used and store the decimal values into new array
      {
        decimal_array[dec_pos]=incoming;
        dec_pos++;
        lcd.print(incoming);                                  //print digits after decimal point on lcd
        delay(200);
      }
 
}
 
else if(incoming==19)
{
    lcd.print(".");                                            //key to print decimal point
    delay(200);
    dec_flag=1;
    pos_count1++;                      
}
 
else if(incoming==16)                                       //enter key
 
{
lcd.setCursor(0, 3);
lcd.print("READ:");
delay(200);
  
  if(pos_count>3)
 
    {
      lcd.clear();
      lcd.setCursor(0,1);                                //if the number has more than 3 digits, print invalid and go to label 2(enter new digit)
      lcd.print("*INVALID ENTRY*");
      delay(3250);
      goto l2;
    }
  else if(pos_count==1)
    {
      angle_val=digit_array[0];                          //angle is one digit
    }
  else if(pos_count==2)
    {
      angle_val=digit_array[0]*10+digit_array[1];                                   //2 digit angle 
    }
 
  else if(pos_count==3)
    {                                                                            //third digit
      angle_val=digit_array[0]*100+digit_array[1]*10+digit_array[2];
    }
 
/*******************************************/
 
  if(dec_flag==1)
 
  {
   if(dec_pos>2)
 
    {
      lcd.clear();
      lcd.setCursor(0,1);                                //if the decimal number has more than 3 digits, print invalid
      lcd.print("*INVALID ENTRY*");
      delay(3250);
      goto l2;
    }
 
   else if(dec_pos==1)
    {
      float temp_val=decimal_array[0];                  //add the decimal and whole numbers to get final angle value
      temp_val=temp_val/10;
      angle_val=angle_val+temp_val;
    }
 
   else if(dec_pos==2)
 
    {
      temp_val=decimal_array[0]*10+decimal_array[1];  
      temp_val=temp_val/100;
      angle_val=angle_val+temp_val;
    }
    else if(dec_pos==0)
 
    {
      angle_val=angle_val+temp_val;
    }
  }
 
 if (angle_val>360)
  {
    lcd.clear();
    lcd.setCursor(0,1);                                       //if the number is greater than 360, print invalid
    lcd.print("*INVALID ENTRY*");
    delay(3250);
    goto l2;
  }
}
 
else if(incoming==12)
  {
    angle_val=angle_val+0.1;                                 // key for 0.1 increment
    lcd.setCursor(5,2);
    lcd.print(angle_val);
    delay(200);
  }
 
else if(incoming==11)
  {
    lcd.clear();
    goto l2;                                                   //reset key
  }
  else if(incoming==13)
{
     lcd.setCursor(0,1);
     lcd.print("                ");
     if(clockwise_counter==1)
     digitalWrite(15,LOW);
     clockwise_counter=0;
     goto l1;
}
else if(incoming==18)
  {
    lcd.setCursor(5,2);
    lcd.print("        ");  
    lcd.setCursor(5,2);                                      //erase the current value and reset the position
    delay(200);
    pos_count=0;
    dec_count=0;
    goto l1;
  }
 if(clockwise_counter==1)
 goto l3; 
else if(incoming==10)                                         //key for clockwise rotation
{
  temp=angle_val;                                               //store current digit value in temp
  clockwise_counter=1;
  digitalWrite(15,HIGH);                                  //set clockwise pin high
  l3:
    duration=pulseIn(13,HIGH);                                //read the interrupt high pulses 
      if(duration<30000)
      {
        read_c=read_c+0.1;
        lcd.setCursor(5,3);
         lcd.print(read_c);
      }
 
 else 
       {
         lcd.setCursor(5,3);
         lcd.print(read_c);
         delayMicroseconds(100);   
         x2:  if(read_c>=angle_val)                                              //compare read and set
            {
               digitalWrite(15,LOW);   //set clockwise pin low
               lcd.clear();
               lcd.setCursor(0,2);                                    
               lcd.print("*ROTATION");
               lcd.setCursor(6,3);
               lcd.print("COMPLETED*");
               delay(800);
               goto l2;
            }
      }
     
      
       if(read_c>=angle_val)                                              //compare read and set
            {
               digitalWrite(15,LOW);   //set clockwise pin low
               lcd.clear();
               lcd.setCursor(0,2);                                    
               lcd.print("*ROTATION");
               lcd.setCursor(6,3);
               lcd.print("COMPLETED*");
               delay(800);
               goto l2;
            }
      
      goto l1;
}
 
 
goto l1;
 
 
 
 
}
void loop()
 
{}

 
Last edited by a moderator:

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
23,032
Helped
4,716
Reputation
9,448
Reaction score
5,089
Trophy points
1,393
Activity points
152,591
Hi,

come on...
I searched for "pause" and I searched for "resume" in your code...
No meaningful occurences.

Don´t generate riddles. Give us a hint where the "pause and resume" code is.

Klaus
 

kripacharya

Banned
Joined
Dec 28, 2012
Messages
1,204
Helped
182
Reputation
360
Reaction score
175
Trophy points
1,343
Location
New Delhi
Activity points
0
Without going through your (quite messy) code, I suspect your lcd goes blank because your cursor position is outside the display boundaries.
 

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,479
Helped
1,183
Reputation
2,385
Reaction score
1,181
Trophy points
1,403
Location
Brazil
Activity points
54,957
A code with excessive use of goto's statements is intrinsically unstructured, difficult to debug, and prone to work unnexpectdly. By the way, you are not doing anything on the loop() section which is empty, all of your code is at setup() section which by definition should be executed just once; review Arduino fundamentals.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top