How to draw circles and lines with Arduboy Library?


#1

Im trying to draw a circle on my Arduboy and I don’t know if its possible to draw it with the default Arduboy Library.

I think its possible, isn’t it?


(Scott) #2

Yes. Lines, circles, rectangles, triangles, rectangles with rounded corners, and filled versions of the shapes.

Both the Arduboy library and the Arduboy2 library have the same drawing functions but I suggest you use Arduboy2 so you can refer to its more extensive documentation.
https://mlxxxp.github.io/documents/Arduino/libraries/Arduboy2/Doxygen/html/index.html

Here’s a simple sketch that will just draw a circle with a 10 pixel radius at the centre of the screen (over and over):

#include <Arduboy2.h>

Arduboy2 arduboy;

void setup() {
  arduboy.begin();
}

void loop() {
  arduboy.clear(); // Clear the screen buffer
  // Draw a circle centred at 63 pixels across and 31 pixels down
  // with a radius of 10 pixels
  // using colour WHITE to set the pixels on
  arduboy.drawCircle(63, 31, 10, WHITE);
  arduboy.display(); // Display the contents of the screen buffer  
}

#3

What about a line?
I use your Library


(Scott) #4

Please refer to the documentation. There is drawLine(), drawFastHLine() and drawFastVLine().


#5

Thanks, your library help me to make this little example: GitHub


(Scott) #6

@Jose_Fabio,
Next, you may wish to change your sketch to use the library frame functions, to run the sketch at a constant frame rate, instead of using delay() to slow things down.

In setup() after arduboy.audio.begin(); add line:

  arduboy.setFrameRate(30); // Run at 30 frames per second

At the start of loop(), before arduboy.clear() add:

  // Wait until it's time for the next frame
  if (!arduboy.nextFrame())
    return;

Delete the delay(35); line near the end of loop()

Now your sketch will run at a constant 30 frames per second. You don’t have to use delay(), which you would need to keep adjusting as you add more code. You can change the frame rate to something other than 30 if you wish, to speed up or slow down the sketch.


#7

Thanks, like this?


(Scott) #8

Yes, that is correct. :smile:


#9