Hi everyone,
Hope someone can help here. I have built an anemometer and I'm using the code shown below, a butchered version of a few peoples code that has been here before.
The issue is that I am wanting the encoder to show 0 - 359 degrees rather than the Data Variable max which shows up to 255. Is there any way to do this?
I have tried the code with word variables however it didn't work on the LCD display, the encoder had no effect.
I'm at a bit of a loss here, I have tried searching through the forum and found this: http://www.picaxeforum.co.uk/showthread.php?23182-how-to-count-and-display-above-255-help-needed however I don't really understand what is happening. I have tried to do what it says but (a) it didn't work and (b) I would like to know what is happening even if it did work.
Any help is much appreciated
View attachment Finale.bas
Hope someone can help here. I have built an anemometer and I'm using the code shown below, a butchered version of a few peoples code that has been here before.
The issue is that I am wanting the encoder to show 0 - 359 degrees rather than the Data Variable max which shows up to 255. Is there any way to do this?
I have tried the code with word variables however it didn't work on the LCD display, the encoder had no effect.
I'm at a bit of a loss here, I have tried searching through the forum and found this: http://www.picaxeforum.co.uk/showthread.php?23182-how-to-count-and-display-above-255-help-needed however I don't really understand what is happening. I have tried to do what it says but (a) it didn't work and (b) I would like to know what is happening even if it did work.
Any help is much appreciated
Code:
initiate: serout C.6,N2400,(254,1) ;clear display
pause 500 ;allows time for LCD to reset
serout C.6,N2400,(254,128) ;first row of the first line
serout C.6,N2400,("Mikes Anemometer") ;print message
pause 5000 ;pause 5 seconds
serout C.6,N2400,(254,1) ;clear display
pause 500 ;allows LCD to reset
symbol getBits = b0 'b0 = bit7 : bit6 : bit5 : bit4 : bit3 : bit2 : bit1 : bit0
symbol dir = b1
symbol counter = b3
setint %00000001,%00000001 'interrupt on pinC.0 high only
main:
do
bintoascii b4, b5,b6,b7 ;changes b4 output to 3 ascii characters
bintoascii b8, b9,b10,b11 ;changes b8 output to 3 ascii characters
serout C.6,N2400,(254,128,"Angle=",b5,b6,b7) ;Top line is Angle=XXX
serout C.6,N2400,(254,192,"Windspeed=",b9,b10,b11) ;Bottom line is Windspeed=XXX
count C.2, 1000, b8 ;Counts B8 pulses to give RPS
loop ;loop back to main
interrupt:
bit1 = pinC.1: bit0 = pinC.0 'save rotary encoder pins status
getBits = getBits & %000000011 'isolate rotary encoder pins
if getBits <> 0 then 'if both pins are low, the direction is undetermined: discard
dir = bit1 * 2 'direction: if bit1=low then dir=0; if bit1=high then dir=2
counter = counter - 1 + dir 'change counter variable accordingly
b4 = b3*15 ;Because 15 degrees incriments, multiplied accordingly
do while getBits <> 0 'wait for the encoder to go to the next "detent" position
getBits = pinsC & %000000011 ;isolate rotary ecoder pins
loop ;loops program
endif ;terminate multiple lines
setint %00000001,%00000001 'restore interrupt on pinC.0 high
return
Last edited: