WhiteSpace
Well-known member
I have to confess to feeling pleased with myself - after a very large number of failures, with bars shooting all over the display and filling the screen in entirely random and infuriating fashion., and after a long process of trial and error rather than any real understanding of why it wasn't working, I have finally succeeded in creating a bar graph display for the little OLED display. It's intended for a two-motor control unit. I'm not sure yet whether I will control the motors using two pots to give analogue control - turn the knobs from full left (reverse) through centre (stop) to full right (forward) - or digitally with tactile switches like on a TV remote volume or channel control, which has only just occurred to me and might give tighter control. In case it's any use, I initially tried with bars of two bytes'/pixels' height, but they were just too narrow, so I settled on 3.
I'm sure others can improve on the coding - it took many attempts to work out how to keep each motor neatly within a pair of columns, rather than staggering all over the place. I've attached the code.
It looks like the photo attached. There's space to add characters or icons in the middle.
The key is this bit:
The control for each motor counts from 0 to 55 because I'm intending to transmit them from the control board to the vehicle via irout. The control for each motor will initially be counted from 0 to 255 as readadc, then divided by 5 (to give 0 to 51). The left motor will transmit an irout code from 0 to 51 and right motor will add 51 to give 52 to 103, so that the two motors will be transmitted in different ranges. That seemed to be the easiest way of getting two lots of motor controls within the 256 options available for irout. I'll update as this progresses.
I'm sure others can improve on the coding - it took many attempts to work out how to keep each motor neatly within a pair of columns, rather than staggering all over the place. I've attached the code.
It looks like the photo attached. There's space to add characters or icons in the middle.
The key is this bit:
Rich (BB code):
DisplayLeftMotor:
if b3 >= 21 and b3 <= 51 then; if motor is stopped or going forward, the bars are at or above the index line, so they start at row 1
row = 1
col = 0
Gosub SetPosition
elseif b3 >= 0 and b3 < 21 then ; if motor is reversing, the bars are below the line, so they start at the line (row 3) and go downwards
row = 3
col = 0
gosub SetPosition
endif
for b10 = 1 to 2; two columns to give a nice wide bar
hi2cout (0x40,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr) ; this does the top row
inc row; then move down a row.
gosub SetPosition
inc ptr; move to the next byte
hi2cout (0x40,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr)
inc row; then move down a row.
gosub SetPosition
inc ptr
hi2cout (0x40,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr)
inc row; then move down a row.
gosub SetPosition
inc ptr
hi2cout (0x40,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr,@ptr)
gosub SetPosition
ptr = ptr - 3; then go back to the first byte to display the top byte in the next column
col = col + 12 ; then move to the next character space, 12 columns further on
row = row - 3 ; go back to the top row, ready to write the right hand side of the bars
gosub SetPosition
next b10
return
Attachments
-
8.5 KB Views: 16
Last edited: