Due to this thread, I wrote my own version of the bargraph code. However as it had already been done at least twice before I've also produced some variants to not make this thread just a waste of space with nothing new.
Improved versions of all three bargraph styles shown here are now available, but currently only for parallel LCDs/OLEDs.
The new improved versions use a convenient gosub for the bargraph and attributes of the bargraph such as length and position can be conveniently set via variables - this makes it easy to have multiple bargraphs on the display at once. On the originals it is hard to change some of these properties due to all the values (except for the value) being constants. If you want to use a serial LCD then you are stuck with the originals. The parallel LCD versions are much more 'responsive' than the serial LCD versions because of not having a slow serial interface, therefore even if I do eventually do serial LCD versions they will still be quite sluggish i.e. if the value of the bar is set using a potentiometer then turning the knob quickly from one end to the other will cause the bargraph to increment smoothly whilst it is being turned when using the parallel interface but when using the serial interface the bar will jump up in big steps.
Remember, AXE133 users can simply plug their programming cable into the AXE133 and reprogram the built-in PICAXE-18M2 to benefit immediately from the parallel LCD/OLED interface, and if for some reason you want to go back to using this as a serial display then program the 18M2 with the serial firmware available on the PICAXE website.
The already-done one
Click here for the NEW parallel LCD/OLED version
Outdated AXE033/AXE133 serial version:
True linear bar
The gap between each character space, which is exactly one pixel wide on OLEDs and around one pixel wide on LCDs means that the relationship between bar length and input value is not perfectly linear. This example treats this gap as just being inactive pixels so that the relationship is perfectly linear, but of course it is not possible to actually make the gaps light up.
Click here for the NEW parallel LCD/OLED version
Outdated AXE033/AXE133 serial version:
Something more unique
This version only uses alternate columns on the LCD/OLED so that the gap between characters goes unnoticed. There are also down/up indicators at the ends of the bargraph so the lcdsize constant must be set to the desired size of the bargraph bit not the length of the LCD for the original version. For the new parallel LCD/OLED version, the length set by using the barlength variable does include the arrows on the end.
Click here for the NEW parallel LCD/OLED version
Outdated AXE033/AXE133 serial example:
Comments appreciated.
Improved versions of all three bargraph styles shown here are now available, but currently only for parallel LCDs/OLEDs.
The new improved versions use a convenient gosub for the bargraph and attributes of the bargraph such as length and position can be conveniently set via variables - this makes it easy to have multiple bargraphs on the display at once. On the originals it is hard to change some of these properties due to all the values (except for the value) being constants. If you want to use a serial LCD then you are stuck with the originals. The parallel LCD versions are much more 'responsive' than the serial LCD versions because of not having a slow serial interface, therefore even if I do eventually do serial LCD versions they will still be quite sluggish i.e. if the value of the bar is set using a potentiometer then turning the knob quickly from one end to the other will cause the bargraph to increment smoothly whilst it is being turned when using the parallel interface but when using the serial interface the bar will jump up in big steps.
Remember, AXE133 users can simply plug their programming cable into the AXE133 and reprogram the built-in PICAXE-18M2 to benefit immediately from the parallel LCD/OLED interface, and if for some reason you want to go back to using this as a serial display then program the 18M2 with the serial firmware available on the PICAXE website.
The already-done one
Click here for the NEW parallel LCD/OLED version
Outdated AXE033/AXE133 serial version:
Code:
#picaxe 28x2
#no_data
symbol lcdpin = C.3
symbol adcpin = C.2
symbol readvar = b4
symbol length = b5
symbol loopcounter = b6
symbol charactercounter = b7
symbol lcdsize = 16
main:
pause 200
serout lcdpin, N2400_8, (254, 64, 32, 32, 32, 32, 32, 32, 32, 32)
serout lcdpin, N2400_8, (254, 72, 48, 48, 48, 48, 48, 48, 48, 48)
serout lcdpin, N2400_8, (254, 80, 56, 56, 56, 56, 56, 56, 56, 56)
serout lcdpin, N2400_8, (254, 88, 60, 60, 60, 60, 60, 60, 60, 60)
serout lcdpin, N2400_8, (254, 96, 62, 62, 62, 62, 62, 62, 62, 62)
serout lcdpin, N2400_8, (254, 104, 63, 63, 63, 63, 63, 63, 63, 63)
do
readadc adcpin,readvar
length = lcdsize * 5 - 1 * readvar / 255 + 1
serout lcdpin,N2400_8,(254,128,#length," ",254,192)
charactercounter = lcdsize
do
if length => 5 then
serout lcdpin,N2400_8,(13)
length = length - 5
dec charactercounter
else
exit
end if
loop
readvar = length + 8
serout lcdpin,N2400_8,(readvar)
for loopcounter = 0 to charactercounter
serout lcdpin,N2400_8,(32)
next
loop
The gap between each character space, which is exactly one pixel wide on OLEDs and around one pixel wide on LCDs means that the relationship between bar length and input value is not perfectly linear. This example treats this gap as just being inactive pixels so that the relationship is perfectly linear, but of course it is not possible to actually make the gaps light up.
Click here for the NEW parallel LCD/OLED version
Outdated AXE033/AXE133 serial version:
Code:
#picaxe 28x2
#no_data
symbol lcdpin = C.3
symbol adcpin = C.2
symbol readvar = b4
symbol length = b5
symbol loopcounter = b6
symbol charactercounter = b7
symbol lcdsize = 16
main:
pause 10
serout lcdpin, N2400_8, (254, 64, 32, 32, 32, 32, 32, 32, 32, 32)
serout lcdpin, N2400_8, (254, 72, 48, 48, 48, 48, 48, 48, 48, 48)
serout lcdpin, N2400_8, (254, 80, 56, 56, 56, 56, 56, 56, 56, 56)
serout lcdpin, N2400_8, (254, 88, 60, 60, 60, 60, 60, 60, 60, 60)
serout lcdpin, N2400_8, (254, 96, 62, 62, 62, 62, 62, 62, 62, 62)
serout lcdpin, N2400_8, (254, 104, 63, 63, 63, 63, 63, 63, 63, 63)
do
readadc adcpin,readvar
length = lcdsize * 6 - 1 * readvar / 255 + 1
serout lcdpin,N2400_8,(254,128,#length," ",254,192)
charactercounter = lcdsize
do
if length => 6 then
serout lcdpin,N2400_8,(13)
length = length - 6
elseif length = 5 then
serout lcdpin,N2400_8,(13)
length = length - 5
else
exit
end if
dec charactercounter
loop
readvar = length + 8
serout lcdpin,N2400_8,(readvar)
for loopcounter = 0 to charactercounter
serout lcdpin,N2400_8,(32)
next
loop
This version only uses alternate columns on the LCD/OLED so that the gap between characters goes unnoticed. There are also down/up indicators at the ends of the bargraph so the lcdsize constant must be set to the desired size of the bargraph bit not the length of the LCD for the original version. For the new parallel LCD/OLED version, the length set by using the barlength variable does include the arrows on the end.
Click here for the NEW parallel LCD/OLED version
Outdated AXE033/AXE133 serial example:
Code:
#picaxe 18m2
#no_data
symbol lcdpin = C.3
symbol adcpin = C.2
symbol readvar = b4
symbol length = b5
symbol loopcounter = b6
symbol charactercounter = b7
symbol endposition = b8
symbol lcdsize = 14
setfreq m8
pause 200
serout lcdpin, N2400_8, (254, 64, 32, 32, 32, 53, 32, 32, 32, 32)
serout lcdpin, N2400_8, (254, 72, 32, 48, 48, 53, 48, 48, 32, 32)
serout lcdpin, N2400_8, (254, 80, 32, 52, 52, 53, 52, 52, 32, 32)
serout lcdpin, N2400_8, (254, 88, 32, 53, 53, 53, 53, 53, 32, 32)
serout lcdpin, N2400_8, (254, 96, 34, 39, 47, 49, 47, 39, 34, 32)
serout lcdpin, N2400_8, (254, 104, 40, 60, 58, 49, 58, 60, 40, 32)
endposition = lcdsize + 193
main:
do
readadc adcpin,readvar
length = lcdsize * 3 - 1 * readvar / 255 + 1
serout lcdpin,N2400_8,(254,128,#length," ",254,endposition,13,254,192,12)
charactercounter = lcdsize
do
dec charactercounter
if length > 3 then
serout lcdpin,N2400_8,(11)
length = length - 3
else
exit
end if
loop
readvar = length + 8
serout lcdpin,N2400_8,(readvar)
looplabel:
if charactercounter > 0 then
serout lcdpin,N2400_8,(8)
dec charactercounter
else
goto main
end if
goto looplabel
loop
Last edited: