frumperino/FrekvensPanel

drawPixel method

troglodisme opened this issue · 1 comments

I'd like to use your library for a new hack on the frekvens but can't seem to understand how the drawPixel method works.

What's the simplest way to write a function that turns on (and off) a specific pixel? I tried a few combinations of this below with no luck.. the sparkles example works fine though.

panel.drawPixel(1,1,10 == 0);
delay(500);
panel.scan();

What does the "== 0" do?

Thanks

The quoted code does not come from the examples I provided with the library.

The relevant line from the sparkles example looks like this:

` panel.drawPixel(random(16),random(16),random(10) == 0);

The third function argument - color of the pixel - in this example is the output of a comparison operation. If the random number between 0 and 9 equals 0 then the comparison is true, which is logical 1, therefore pixel value 1 in 1 out of 10 cases, otherwise 0. Is that clear enough?

In the code you provided, you only need to provide a number or a variable for the color argument. So if you want the pixel to be lit then use a 1 in the third argument, otherwise 0.

I'd heartily encourage you to take a 1-day basic C course, it would help you read and write this type of code.