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.

[SOLVED] Add or subtract variable value (x0.1, x1, x10) according how long button pressed

Status
Not open for further replies.

Ranbeer Singh

Full Member level 5
Joined
Jul 30, 2015
Messages
259
Helped
22
Reputation
44
Reaction score
22
Trophy points
1,298
Location
Faridabad India
Activity points
3,266
Hello,

I am implementing a function for add or subtract variable value according to button pressed time.

When i press button for a short time it should increase or decrease 0.1 from variable. When i press button for 4-5 second, it should increase or decrease 1 from variable. When i press button more then 8 second, it should increase or decrease every time 10 from variable.

Code:
float x = 0.01
while(a < 200)
{
	if(DownKey) 
	{
		k -= x;
		a = 0;
	}	
	if(UpKey) 
	{
		k += x;
		a = 0;
	}	
	if(k > 99.99) k = 99.99;
	if(k < 0) k = 0;
	delay_10ms();
	a++;
}

My concern is, how can i set X in 0.1, 1, 10 format according to button pressed time?
 
Last edited:

Code:
if (Downkey || Upkey)
{
  keypressed++;
  switch (keypressed)
  {
     10: 
        x = 0.1;
        break;
     20: 
        x = 1
        break;
     // etc.
  }
}
else
{
  keypressed = 0;
  x = 0.01;
}
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top