What is wrong with this code?

jcgalvezv

New Member
Today I receive my first PICAXE-08M and I was just testing what I have learned. This code should read an analog value and, if it is greater than zero, blink the led once. Every analog read should be sent to the serial port. If no reading is done then every second the "testing" test + w1 content is sent to the computer. But, when something greater than 0 is read, the text and value is sent, the led blinking enters a loop and no more reading are sent to the computer.

Code:
symbol ADCPORT = 2
symbol LEDPORT = 1

main:
      w1 = 0
	readadc10	ADCPORT, w1

	sertxd      ("testing", #w1, 13, 10)
	if w1 = 0 then nextone
	gosub		blinkled
nextone:
	pause		1000
	goto		main

blinkled:
	high		LEDPORT
	sleep		100
      low		LEDPORT
	return
 

hippy

Ex-Staff (retired)
"SLEEP 100" takes around 230 seconds ( 4 minutes ) to execute :)

You probably meant "PAUSE 100" for a 100ms, tenth of a second, flash.
 

jcgalvezv

New Member
You are absolutely right. Thank you. I didn't notice it because I was using a blinking led and not a regular one.
 

Texy

Senior Member
You do realise that the led will blink if there is even as little as 1/1023rd of the supply voltage on the ADC pin?
Also you do not need to set w1=0 at the beginning of the loop as it will be set by the readadc instruction.

HTH
Texy
 

jcgalvezv

New Member
You do realise that the led will blink if there is even as little as 1/1023rd of the supply voltage on the ADC pin?
Yes, I am just testing.
Also you do not need to set w1=0 at the beginning of the loop as it will be set by the readadc instruction.
Yes, it is not necessary. Since I was having a problem I thought it was needed. I didn't include it at the beginning and it is now removed.

I have been a C language programmer for a long time. In C language sleep is the instruction to pause the execution of the program in milliseconds.

Thank you for your replies.
 
Top