How to reduce flickering in rendering #3297
Unanswered
JordanKlaers
asked this question in
Q&A - General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am drawing a circle with "fillCircle" based on the degree that I read from a sensor, representing an angle of a motor.
In my loop I am only reading the sensor and drawing a black circle to "erase" the old position, and a new circle based on the new angle.
I am using a buffer class that saves the lasts three values read, with a little logic to not render a new circle when the sensor isnt moving (sometimes it flickers up and down 1 "unit" so I skip repeated redraws untill it changes by 2 or more)
I also have an object "coordinates" that saves all the possible coordinates so I dont have to do cos/sin each loop to render the circle location.
What can I do to prevent this flickering im seeing?
I was thinking either somehow, combining the black cricle (for "erasing" the old location) and new white circle into one drawing command (I was thinking the flickering is because of the way I move the circles position.) Or is there some other appraoch?
Here is the code in the loop (im sorry im having trouble with the indentation):
`void loop() {
shaftAngle = normalizeRadians(as5600.getSensorAngle());
float shaftDegree = round(shaftAngle * (360.0f / (2 * M_PI)));
//reading a new degree
if (shaftDegree != buffer.getLast()) {
//if its not fluttering, we can add the new value
if (!isFluttering) {
//+/- 1 and not fluttering
isFluttering = buffer.add(shaftDegree);
//erase the old
coordinates = getFromCache(buffer.getSecondLast());
tft_donk.fillCircle(coordinates[2] - 5, coordinates[3] - 5, 10, GC9A01A_BLACK);
//draw the new
coordinates = getFromCache(buffer.getLast());
tft_donk.fillCircle(coordinates[2] - 5, coordinates[3] - 5, 10, GC9A01A_WHITE);
}
//if its fluttering, then we only add new value if tis +/- 2
else if (!isWithinThreshold(shaftDegree, buffer.getLast(), 2)) {
isFluttering = buffer.add(shaftDegree);
//erase the old
coordinates = getFromCache(buffer.getSecondLast());
tft_donk.fillCircle(coordinates[2] - 5, coordinates[3] - 5, 10, GC9A01A_BLACK);
//draw the new
coordinates = getFromCache(buffer.getLast());
tft_donk.fillCircle(coordinates[2] - 5, coordinates[3] - 5, 10, GC9A01A_WHITE);
}
}
}
Beta Was this translation helpful? Give feedback.
All reactions