Beginner needs help

Microfreak

New Member
Hy Folks.
I´m Steffen from Austria and I like to learn to handle the picaxe 18x for a project. I want to realize an old projekt with Hardware Relais with the Picaxe. I searched here in the forum an try to find any information in the basic command but I think I need a little help during my startup.

How can I realize my problems:

I have one switch on input 0 and one Output. When I press the switch at the Input the Output should go into high level and when I press the switch again the Output should go back into low. I realized this but i have one Problem. When I press the button the Output must go to high even if I hold the button. The Programm has to run and work other steps or commands. Then, when I release the button the program must go on and work the other commands. When I press the Button again the Output has to go to low level until I releas the Button again and go th high when I press the Button and so on. The min problem is that the Programm must run in the background.

Its an electronical impuls relay I like to build whith the option to run the rest of the Program without any break.

I hope you understand what I mean. I hope sombody has an idea.

Regards, Steffen

Sorry about my bad english :p
 

BeanieBots

Moderator
For other commands to run while still checking the status of an input, you need to use interrupts. Not the easiest programming method to use but have a look at the "setint" command. If it's not clear what to do, ask again.
 

inglewoodpete

Senior Member
Solution without interrupts

Steffen, It is not essential to use interrupts in your programme. For a beginner, interrupts can be quite a challenge! What you requested could be performed in a programme like the one I have outlined below. The important thing to remember when writing code for this solution is to ensure that the code does not get 'stuck' in a loop in the subroutine. I have used code like this to avoid using interrupts.

-Peter

Code:
Symbol	PushButton = Pin0
Symbol	LED = 2

	Low LED			'Initialise the LED output to Low (Off) state
Main:	Do Until PushButton = 1
		GoSub DoStuff	'Do the normal work
	Loop
	'Pin 1 has is now High (Active)
	Toggle LED		'Invert the state of the output (Hi to Lo or Lo to Hi)
	Do Until PushButton = 0
		GoSub DoStuff	'Do the normal work while the pushbutton remains pressed
	Loop
	'Pin 1 has is now Low (Off)
	Goto Main

DoStuff:	'Subroutine that does the normal background processing tasks
		'The code here would typically check inputs, variables, perform calculations and set
		'  outputs as required by the process.
		'You must ensure that processing does not get 'trapped' in a loop or delay (eg pause)
		'  statement within this subroutine.

	Return
 
Top