Hi All,
I created this small code to read a pot position and generate a pattern of LEDs attached to the Port.B pins.
It works fine "as is", but when i try to change my pot range to more than 16 patterns on the LEDs, it never seems to go beyond my 16 pot ranges assigned.
The Pot_Position value is read from a pot attached to the ADC input on Pin C.0
The Pot_Position value is then divided by 16 to create 16 evenly spaced "zones" around the entire pot travel, it seems to work perfectly.
When i try to increase my range of 16 to say 20 and include 20 data values in my lookup table, the code doesn't seem to display the LED patterns for 20 different positions of the pot rotation.
The data values of $00 to $0F were just for my initial tests to prove it works, but the final values will not be in that order.
I feel i'm overlooking something, but there's not much in the code to go wrong, arghh!
I created this small code to read a pot position and generate a pattern of LEDs attached to the Port.B pins.
It works fine "as is", but when i try to change my pot range to more than 16 patterns on the LEDs, it never seems to go beyond my 16 pot ranges assigned.
The Pot_Position value is read from a pot attached to the ADC input on Pin C.0
The Pot_Position value is then divided by 16 to create 16 evenly spaced "zones" around the entire pot travel, it seems to work perfectly.
When i try to increase my range of 16 to say 20 and include 20 data values in my lookup table, the code doesn't seem to display the LED patterns for 20 different positions of the pot rotation.
The data values of $00 to $0F were just for my initial tests to prove it works, but the final values will not be in that order.
I feel i'm overlooking something, but there's not much in the code to go wrong, arghh!
Code:
#picaxe 14m2
#no_data
symbol Pot_Position = b0 'Store a variable of the Pot_Position ADC input into an 8bit number.
symbol LED_Loader = pinsB 'assign LED_loader to the entire PortB pins (B.0 to B.5)
dirsb = %11111111 'set PortB to all OUTPUTS.
do
if Pot_Position=0 then 'if pot value is 0 (the "off" position)
LED_Loader=0 'then turn the LED_loader Leds OFF.
else 'otherwise load pot value onto loader LEDs.
Pot_Position=Pot_Position/16 'divide pot into ranges of "16" (256/16=16 zones/patterns to display) to evenly create zones in the pot where each value will change.
lookup Pot_Position,($00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0A,$0B,$0C,$0D,$0E,$0F),LED_Loader 'Load value onto Loader LEDs!
endif
readadc C.0,Pot_Position 'read pot value on pin C.0 (ADC) to set the "pattern" value for the LED_loader.
loop
Last edited: