cancel
Showing results for 
Search instead for 
Did you mean: 

Throttle position visualization

fing
Associate II

Hello,

I have written my 4 bit grayscale, 256x64 OLED driver using SPI, and I want to visualize my throttle position. The throttle value ranges between -100 and +100 where -100 means maximum deceleration and +100 the maximum acceleration. So far, I have successfully implemented the buffering technique in SPI, which is insanely fast and I can eliminate for loops. As the range increases from 0 to +100, a rectangle rises from the middle to upwards, and from 0 to -100 a rectangle increases from the middle to downwards. The previous version used for loops which were incredibly inefficient, so I started using buffers.

1 byte controls 2 pixels that have 16 brightness levels. 0xFF = 2 pixels at max brightness.

The problem is that if I decrease the size of the rectangle, it stays in the OLED's GDDRAM and they are not automatically written over with zeros.

0693W00000WL8TGQA1.png0693W00000WL8TLQA1.png0693W00000WL8TVQA1.pngI am using a bitmap array for the black and white rectangles. The size of the black and white rectangles is 6x56 pixels. In my case, one row is made up of 3 bytes, which means that every size has to be a multiple of 3. This is the value that I am passing into the writeData2 function.

So far I have made something to solve this but it doesn't really work properly. I split the incoming data into 3 cases, when the throttle is above zero, under zero and of course when it is zero. For the sake of simplicity I am showing the code only for the positive region.

The positive case uses 1 black and 1 white rectangle. I am controlling the start and end position of the rectangles and their size respectively.

At 0 throttle the black rectangle spans from 0 to the 30th row, and the white rectangle is just one line in 31.

At 100 throttle the black rectangle spans from 0 to 3 and the white rectangle from 4 to 31.

When the throttle value increases:

  • Black rectangle end row decreases (start row fixed at 0)
  • White rectangle start row decreases (end row fixed at 31)
  • Black rectangle size decreases (multiple of 3)
  • White rectangle size increases (multiple of 3)

Now my code is working when I increase the value, but it doesn't decrease.

float throttlepos;
void teglalap2(int8_t gaz) { //-100 and + 100 
 
 
 
	if (gaz > 0) {
		throttlepos = round(0.27f * gaz);
		/* for debugging
		 watch = gaz;
		 feketerowend = 27 - throttlepos + 3;
		 feketesize = 90 - (throttlepos * 3);
		 feherrowstart = 27 - throttlepos + 4;
		 fehersize = 3 + (throttlepos * 3);
		 */
 
 
		setColAddr(0, 2);
		setRowAddr(0, 27 - throttlepos + 3);
		writeData2(black, 90 - (throttlepos * 3));
 
 
		setColAddr(0, 2);
		setRowAddr(27 - throttlepos + 4, 31);
		writeData2(white, 3 + (throttlepos * 3));
 
 
 
	}
}

Perhaps my calculations are wrong but I have been watching my variables and they look good.

0 REPLIES 0