Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:33 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Think tank required

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 01:42pm 03 May 2013
Copy link to clipboard 
Print this post

I have spent some time trying to get the light bulb above my head to illuminate but without luck thought that I might bounce this one off the more intelligent programing minds on this forum.

I would like a simple routine that would increase (or decrease) a variable with a key pressed (key is identified using an analogue input) but have the ability to accelerate the rate of increase (or decrease) the longer the key is pressed. When the key is released the rate returns to slow.

 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 05:26pm 03 May 2013
Copy link to clipboard 
Print this post

Hi Graeme,

The following code may give you some ideas - I tested on a Duinomite Mega running 4.3A

Cheers,
Doug.


' Program to demonstrate use of analogue input pin
' to increase a variable while a switch is
' closed and return to normal rate on release
' Use pin 1 as analogue input with pullup resistor
' to hold high and normally open switch to ground.
' Pin will be high until switch operated.

Entry:
slow = 10 ' initial "slow" value for rate
rate = slow ' set rate to initial value
SetPin 1,1 ' setup pin to be used as analogue input

' Now for the interrupt handler to check if key pressed
SetTick 500,switch_check 'interrupt every 500mS

Main:
' main program area - I just print rate to demo
Print rate,;
Pause 50
GoTo main

'Interrupt service routine
switch_check:
If Pin(1) = 0 Then
rate = rate + 1
Else
rate = slow
EndIf
IReturn



... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 08:22pm 03 May 2013
Copy link to clipboard 
Print this post

Doug, it's a great start and I would never have come up with the idea. Graeme had two more requirements and I may be able to help with one which is to accelerate the rate of increase. I will add my efforts in capitals.

My suggestions are untested. I don't have an active machine. The MULIPLIER and BASE don't have to be integers but not zero.

' Program to demonstrate use of analogue input pin
' to increase a variable while a switch is
' closed and return to normal rate on release
' Use pin 1 as analogue input with pullup resistor
' to hold high and normally open switch to ground.
' Pin will be high until switch operated.

Entry:
slow = 10 ' initial "slow" value for rate
BASE=1 ' base acceleration
MULTIPLIER=2 ' set this greater than 1 to increase the acceleration
ACCELERATION=BASE
rate = slow ' set rate to initial value
SetPin 1,1 ' setup pin to be used as analogue input

' Now for the interrupt handler to check if key pressed
SetTick 500,switch_check 'interrupt every 500mS

Main:
' main program area - I just print rate to demo
Print rate,;
Pause 50
GoTo main

'Interrupt service routine
switch_check:
If Pin(1) = 0 Then
ACCELERATION=ACCELERATION * MULTIPLIER
rate = rate + 1 + ACCELERATION
Else
rate = slow
ACCELERATION=BASE
EndIf
IReturn

 
ajkw
Senior Member

Joined: 29/06/2011
Location: Australia
Posts: 290
Posted: 11:48pm 03 May 2013
Copy link to clipboard 
Print this post

Graeme,

I had this idea. It counts rather fast and definitely accelerates with time.

Anthony.


cls
pause 500
Do
locate 0,0 : print Timer
If Keydown > 0 then 'can also check for actual key or i/o pin
st = timer
do
inc = (Timer - st) / 100
a = a + inc
locate 20,20 : print a;" "
locate 20,40 : print inc;" "
loop until keydown = 0
endif

Loop

 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024