increment in binary

malti

New Member
Can anyone tell me please what should I put instead of the question marks, please

Program the Picaxe to increment in binary EACH TIME the button is pressed. (Keeps count of the number of button presses)

symbol F=B0
B1=0-1

loop:
if pin0=1 and F=0 then countit
if pin0=0 then reset
goto loop

countit:
B1 = B1+1
High B1
F=????
goto loop

reset:
?????
 

westaust55

Moderator
malti,

if you are logged in you will see an edit box at the bottom right of your posts.

You can use that to go back into your post and correct any errors rather than create a new post to say what is wrong.



with respect to your program code, what are you try ing to achieve?

What is the purpose of using
b1=0-1 (uses 4 bytes of program space)
that is the same as
b1 = 255 (uses 3 bytes of program space)


also, you cannot use the word reset as a label since RESET is a BASIC command.

If you describe what your program is trying to do maybe someone can hep you better.
 
Last edited:

hippy

Ex-Staff (retired)
If you want to increment your 'F' variable, use "F=F+1", to decrement it use "F=F-1".

To initialise to zero use "F=0", to set to -1 use "F=-1" ( that will actually set the variable to 255 for a byte variable, 65535 for a word variable, but the next increment will take it to zero in both cases ).
 

PhilipS

New Member
My guess is that F is for detecting when the switch is released again - but best wait to hear from the OP :)
 

Gavinn

Member
Hi Malti,

I'm also unsure what you are trying to do but let me see if I can get it right. There is also a command INC which increments a variable and DEC which will decrements a variable.

To the code;

Code:
symbol Button_pressed=B0

MAIN:			'Loop here until B0 goes high
if pin0=1 then 		'If B0 goes HIGH (button pressed) then goto countit routine
INC Button_pressed	'Only ever increments when B0 goes HIGH
goto countit		'Goto the increment code
else
	'Add anything you want to happen when B0 is LOW here
endif
goto MAIN	'Loop backto Main		

COUNTIT:	'Code to increment the putton presses and 
pause 100		
INC B1	'Increment B1 every 100ms or so
Let PINS = B1	'Set the output to equal the value of B1


if pin0=1 then COUNTIT	'Wait for the button to be depressed
B1=0		'When B0 goes LOW reset B1 back to 0
Let PINS = 0
pause 50	'Pause 50ms to allow for switch debounce
goto MAIN

What this code does is increment the output (B1) while PIN0 is HIGH and resets it to 0 when PIN0 goes LOW. Everytime PIN0 goes HIGH (i.e. everytime the button is pressed) the variable 'Button_pressed' increases to indicate home many times it has been pressed.

Some optimisation could be done of the code but it should give you an idea of how to do it.
 

malti

New Member
yes that is the task. It is not a school assignment but purely reading it and learn further on picaxe
 

eclectic

Moderator
yes that is the task. It is not a school assignment but purely reading it and learn further on picaxe
@malti.

I've only had a quick look at the site.
The course appears to be using a 28X / 28X1.
For a very simple starter, try this in the simulator.
Code:
#picaxe 28X1

main:
for b0 = 0 to 255
outpins =b0
pause 500
next
goto main
Secondly, for some great educational Picaxe-puzzles,
see post #4 here

http://www.picaxeforum.co.uk/showthread.php?t=8469&highlight=Rick+college

e
 

BeanieBots

Moderator
malti, the 'excercise' is to demonstrate the use of a flag.
The practicle example problem based around using a push-button is just for demonstration purpose. In reality, if you had the "make a counter count up only for each push" problem, it would not really require the use of a seperate flag. You would simply poll the input pin to get the desired effect.

So, which bit are you not clear on.
How to make a variable count for each push, or how to use a flag?
 
Top