add random fill function

This commit is contained in:
interfisch 2023-02-08 21:29:10 +01:00
parent 3bb37dc83f
commit 880a558951
3 changed files with 54 additions and 8 deletions

View File

@ -32,6 +32,7 @@ private:
unsigned long updateInterval;
public:
@ -44,9 +45,12 @@ public:
uint8_t getH(); //returns Rows
void setBuffer_solid(bool set);
void setBuffer_random(uint8_t randomness);
void loop_testDots();
void loop_drawClearTest();
unsigned long updateDuration; //for statistics and debugging. time it took for one update (max)
};
#endif

View File

@ -14,7 +14,7 @@ void Image::init()
flag_updating=false;
update_counter=0;
updateInterval=50;
updateInterval=30;
}
uint8_t Image::getW() {
@ -39,16 +39,35 @@ void Image::setBuffer_solid(bool set)
}
void Image::setBuffer_random(uint8_t randomness)
{
for (uint8_t x=0;x<getW();x++) {
uint16_t randomnumber=0;
for (uint8_t y=0;y<getH();y++) {
if (random(256)<randomness) { //the higher the parameter the more white
randomnumber+=pow(2, y);
}
}
backBuffer[x]=randomnumber;
//backBuffer[x]=(uint16_t)random(0x10000);
}
flag_updating=true; //make update run
}
bool Image::updateByColumn(bool direction, bool clearFirst, bool optimizeClear, bool optimizeSet)
{
if (millis()-lastUpdateMillis<updateInterval){ //too early
return 0; //not finished
}
if (!flag_updating) {
return 1; //finished
}
if (millis()-lastUpdateMillis<updateInterval){ //too early
return 0; //not finished
}
lastUpdateMillis=millis();
uint8_t x=update_counter/2;
@ -73,6 +92,10 @@ bool Image::updateByColumn(bool direction, bool clearFirst, bool optimizeClear,
update_counter++; //next column
unsigned long _duration=millis()-lastUpdateMillis; //how long it took to shift data and flip dots in this update
updateDuration=max(updateDuration,_duration); //store maximum value
if (update_counter/2>=getW()) { //reached last column
flag_updating=false;
update_counter=0;

View File

@ -27,16 +27,34 @@ void loop() {
static unsigned long last_change=0;
static bool color=0;
if (loopmillis-last_change >= 10000)
if (loopmillis-last_change >= 5000)
{
Serial.print("Change to Solid color ="); Serial.println(color);
flip.setBuffer_solid(color);
color=1-color;
//Serial.print("Change to Solid color ="); Serial.println(color);
//flip.setBuffer_solid(color);
//color=1-color;
uint8_t _randomvalue=random(256);
Serial.print("set buffer random. ");
Serial.println(_randomvalue);
flip.setBuffer_random(_randomvalue);
last_change=loopmillis;
}
static bool last_result;
bool result=flip.updateByColumn(0,0,0,0); //0=not finished, 1=finished
if (result && !last_result) //just finished
{
unsigned long duration=millis()-last_change;
Serial.print("Last Change took "); Serial.print(duration); Serial.println(" ms");
Serial.print("Update max took "); Serial.print(flip.updateDuration); Serial.println(" ms");
flip.updateDuration=0; //reset
}
last_result=result;
/*
if (loopmillis > last_update + UPDATE_INTERVAL)
{
Serial.print("UpdateByColumn ");
@ -45,6 +63,7 @@ void loop() {
last_update=loopmillis;
}
*/
/*