samedi 29 juillet 2017

Generating random visual noise using For loop (C, Arduino)

I'm starting to get into the mild depths of C, using arduinos and such like, and just wanted some advice on how I'm generating random noise using a For loop. The important bit:

void testdrawnoise() {  
  int j = 0;
  for (uint8_t i=0; i<display.width(); i++) {
    if (i == display.width()-1) {
      j++;
      i=0;
    }
    M = random(0, 2); (Random 0/1)
    display.drawPixel(i, j, M); // (Width, Height, Pixel on/off)
    display.refresh();
    }
  }

The function draws a pixel one by one across the screen, moving to the next line down once i is has reached display.width()-1. Whether the pixel appears on(black) or off(white) is determined by M.

The code is working fine, but I feel like it could be done better, or at least neater, and perhaps more efficiently.

Input and critiques greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire