Newbie project question

curry87

Senior Member
Hi im trying to make this so that user inputs a number of pulses which will show on a led.However i want an option for the last num of pulses entered to be saved in memory so that if two buttons are press at the same time it will show this.

Im using a picaxe 18 m btw.

Please give some ideas and examples on how to use write and read ?

thanks


Code:
symbol times = b0'pulses
symbol c = b3 'counter

main:

let times = 0

do

'counts how many flashes you want 
if pin3 = 1 then inc times : pause 100

		
'if two buttons are pressed at same time causing high  
else if pin5 = 1 and pin6 = 1 then pause 100
read times,b6
' *how to do *show last number of pulse inputed from before a reset



'break loop show number of flashes
 else if pin4 = 1 and times > 0  then 
 pause 100
exit	


else if pin1 = 0 then  
pause 200
goto main


endif

loop

write b6,times

for c = 1 to times
high 2
pause 700
low 2
pause 700

next c

pause 300
goto main
 

manuka

Senior Member
Welcome! There are lots of ways to do this, but how many pulses are likely to be EEPROM stored? Too many may become tricky to count! Consider a simple tens/units code, or even a SERTXD to an attached PC?
 

westaust55

Moderator
Welcome to the PICAXE forum

If I might offer you some advice in advance of others providing programming code.

1. try to format you code to make it easier to read. I have done this below for you with your existing code

2. Provide a plain english description on what you are trying to do/achieve

3. with respect to your code, you are using the variable (alias) "times" as a counter, which I believe is what you want, but later you use the same variable as a point to a location in EEPROM to retrieve a value with the READ instruction.

4. If you only wish to hold/save one value at any time then:
(a) do you want it saved if the PICAXE is powered down
(b) only saved whiel the program continues

If (a) then yes save in EEPROM ,
but if (b) then consider using a RAM location as EEPROM has a limited number of times (around 100,000 from memory – Oh no possible pun alert!) it can be written before it may fail.

Is this a school project or for home use?

= = = = =

Code:
symbol times = b0'pulses
symbol c = b3 'counter

main:

	let times = 0

	do

		'counts how many flashes you want 
		if pin3 = 1 then
			inc times
			pause 100

		else if pin5 = 1 and pin6 = 1 then
		'if two buttons are pressed at same time causing high  
			pause 100
			read times,b6  ; read value from EEPROM location times and put into b6
			' *how to do *show last number of pulse inputted from before a reset



			'break loop show number of flashes
 		else if pin4 = 1 and times > 0  then 
 			pause 100
			exit	; break from the DO loop


		else if pin1 = 0 then  
			pause 200
			goto main


		endif

	loop

		write b6,times

	for c = 1 to times
		high 2
		pause 700
		low 2
		pause 700

	next c

	pause 300
	goto main
 
Top