From ea0d71a1c2b5549b92afb5c36d0924d5c451d0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Wed, 30 Jun 2021 12:15:12 +0200 Subject: [PATCH 1/2] Add docs folder --- docs/api.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/readme.md | 13 +++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 docs/api.md create mode 100644 docs/readme.md diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..b9f3b87 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,52 @@ +# ArduinoGraphics Library + +## Methods + +### `begin()` + +Description +Initializes the graphics device. + +#### Syntax + +`YourScreen.begin()` + +#### Parameters + +None + +#### Returns + +1 for success, 0 on failure. + +#### Example + +```arduino +if (!YourScreen.begin() { + Serial.println(“Failed to initialize the display!”); + while (1); +} +``` + +### `end()` + +Description +Stops the graphics device. + +#### Syntax + +`YourScreen.end()` + +#### Parameters + +None + +#### Returns + +Nothing + +#### Example + +```arduino +YourScreen.end(); +``` diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..92ff8db --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,13 @@ +# Arduino Graphics Library + +This is a library that allows you to draw and write on screens with graphical primitives; it requires a specific hardware interfacce library to drive the screen you are using, therefore every screen type should have its own hardware specific library. + +To use this library + +``` +#include +``` + +To let you easily understand the usage of the graphics primitives, we are using a dummy screen object named YourScreen that should be substituted with the real one, Eg. MATRIX, OLED, TFT and so on. Refer to the hardware interfacing library of your screen to get more details. + +The style and syntax of this library is inspired by [Processing 3](https://processing.org/) and we believe that learning Processing is very helpful to develop complex applications that combine the versatility of Arduino driven hardware with the power of a pc based graphical interface. \ No newline at end of file From 486e46cd0e42c8eb0af411a0f388cf65b06f0de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Mon, 26 Jul 2021 09:54:50 +0200 Subject: [PATCH 2/2] Update api.md --- docs/api.md | 789 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 782 insertions(+), 7 deletions(-) diff --git a/docs/api.md b/docs/api.md index b9f3b87..491bb9c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,15 +1,20 @@ -# ArduinoGraphics Library +# Arduino Graphics Library ## Methods ### `begin()` -Description +#### Description + + Initializes the graphics device. #### Syntax -`YourScreen.begin()` +``` +YourScreen.begin() +``` + #### Parameters @@ -21,32 +26,802 @@ None #### Example -```arduino +``` if (!YourScreen.begin() { Serial.println(“Failed to initialize the display!”); while (1); } ``` + + ### `end()` -Description +#### Description + Stops the graphics device. #### Syntax -`YourScreen.end()` +``` +YourScreen.end() + +``` + #### Parameters + None + #### Returns Nothing #### Example -```arduino +``` YourScreen.end(); ``` + + + +### `width()` + +#### Description + + +Returns the pixel width of the graphics device. + +#### Syntax + +``` +YourScreen.width() + +``` + + +#### Parameters + + +None + +#### Returns + +Returns the pixel width of the graphics device. + +#### Example + +``` +int w = YourScreen.width(); +``` + + +### `height()` + +#### Description + + +Returns the pixel height of the graphics device. + +#### Syntax + +``` +YourScreen.height() + +``` + + +#### Parameters + + +None + +#### Returns + +Returns the pixel height of the graphics device. + +#### Example + +``` +int h = YourScreen.height(); +``` + + +### `beginDraw()` + +#### Description + + +Begins a drawing operation. + +#### Syntax + +``` +YourScreen.beginDraw() + +``` + + +#### Parameters + + +None + + +#### Returns + +Nothing + +#### Example + + +YourScreen.beginDraw(); +YourScreen.set(0, 0, 255, 0, 0); +YourScreen.endDraw(); + + + +### `endDraw()` + +#### Description + + +Ends a drawing operation, any drawing operations after beginDraw() is called will be displayed to the screen. + +#### Syntax + +``` +YourScreen.endDraw() + +``` + + +#### Parameters + + +None + + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.set(0, 0, 255, 0, 0); +YourScreen.endDraw(); +``` + + +### `background()` + +#### Description + + +Set the background color of drawing operations. Used when calling clear() or drawing text. + +#### Syntax + +``` +YourScreen.background(r, g, b) +YourScreen.background(color) + +``` + + +#### Parameters + + +- r: red color value (0 - 255) +- g: green color value (0 - 255) +- b: blue color value (0 - 255) +- color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.background(255, 0, 0); +YourScreen.clear(); +YourScreen.endDraw(); +``` + + +### `clear()` + +#### Description + + +Set clear the screen contents, uses the background colour set in background(). + +#### Syntax + +``` +YourScreen.clear() + +``` + + +#### Parameters + + +None + + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.background(255, 0, 0); +YourScreen.clear(); +YourScreen.endDraw(); +``` + + + +### `fill()` + +#### Description + + +Set the fill color of drawing operations. + +#### Syntax + +``` +YourScreen.fill(r, g, b) +YourScreen.fill(color) + +``` + + +#### Parameters + + +- r: red color value (0 - 255) +- g: green color value (0 - 255) +- b: blue color value (0 - 255) +- color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + + +### `noFill()` + +#### Description + + +Clears the fill color of drawing operations. + +#### Syntax + +``` +YourScreen.noFill() + +``` + + +#### Parameters + + +None + + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 0, 255); +YourScreen.noFill(); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + + +### `stroke()` + +#### Description + + +Set the stroke color of drawing operations. + +#### Syntax + +``` +YourScreen.stroke(r, g, b) +YourScreen.stroke(color) + +``` + + +#### Parameters + + +- r: red color value (0 - 255) +- g: green color value (0 - 255) +- b: blue color value (0 - 255) +- color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 0, 255); +YourScreen.noFill(); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + + + +### `noStroke()` + +#### Description + + +Clears the stroke color of drawing operations. + +#### Syntax + +``` +YourScreen.noStroke() + +``` + + +#### Parameters + + +None + + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + + +### `line()` + +#### Description + + +Stroke a line, uses the stroke color set in stroke(). + +#### Syntax + +``` +YourScreen.line(x1, y1, x2, y2) + +``` + + +#### Parameters + + +- x1: x position of the starting point of the line +- y1: y position of the starting point of the line +- x2: x position of the end point of the line +- y2: y position of the end point of the line + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(0, 0, 255); +YourScreen.line(0, 0, YourScreen.width() - 1, YourScreen.height() - 1); +YourScreen.endDraw(); +``` + + +### `point()` + +#### Description + + +Stroke a point, uses the stroke color set in stroke(). + +#### Syntax + +``` +YourScreen.point(x, y) + +``` + + +#### Parameters + + +x: x position of the point +y: y position of the point + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(0, 255, 0); +YourScreen.point(1, 1); +YourScreen.endDraw(); +``` + + +### `rect()` + +#### Description + + +Stroke and fill a rectangle, uses the stroke color set in stroke() and the fill color set in fill(). + +#### Syntax + +``` +YourScreen.rect(x, y, width, height) + +``` + + +#### Parameters + + +- x: x position of the rectangle +- y: y position of the rectangle +- width: width of the rectangle +- height: height of the rectangle + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.noStroke(); +YourScreen.fill(255, 255, 0); +YourScreen.rect(0, 0, YourScreen.width(), YourScreen.height()); +YourScreen.endDraw(); +``` + + +### `text()` + +#### Description + + +Draw some text, uses the stroke color set in stroke() and the background color set in background(). + +#### Syntax + +``` +YourScreen.text(string) +YourScreen.text(string, x, y) + +``` + + +#### Parameters + + +- string: string to draw +- x: x position for the start of the text +- y: y position for the start of the text + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 255, 255); +YourScreen.text("abc", 0, 1); +YourScreen.endDraw(); +``` + + +### `textFont()` + +#### Description + + +Sets the font uses for text. The library current has the Font_4x6 and Font_5x7 built in. + +#### Syntax + +``` +YourScreen.textFont(font) + +``` + + +#### Parameters + + +font: font to set + + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.clear(); +YourScreen.stroke(255, 255, 255); +YourScreen.textFont(Font_5x7); +YourScreen.text("abc", 0, 1); +YourScreen.endDraw(); +``` + + +### `textFontWidth()` + +#### Description + + +Returns the width, in pixels, of the current font. + +#### Syntax + +``` +YourScreen.textFontWidth() + +``` + + +#### Parameters + + +None + + +#### Returns + +Nothing + +#### Example + +``` +int w = YourScreen.textFontWidth(); +``` + + +### `textFontHeight()` + +#### Description + + +Returns the height, in pixels, of the current font. + +#### Syntax + +``` +YourScreen.textFontHeight() + +``` + + +#### Parameters + + +None + + +#### Returns + +Nothing + +#### Example + +``` +int h = YourScreen.textFontHeight(); +``` + + +### `set()` + +#### Description + + +Set a pixel’s color value. + +#### Syntax + +``` +YourScreen.set(x, y, r, g, b) +YourScreen.set(x, y, color) + +``` + + +#### Parameters + + +x: x position of the pixel +y: y position of the pixel +r: red color value (0 - 255) +g: green color value (0 - 255) +b: blue color value (0 - 255) +color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginDraw(); +YourScreen.point(1, 1, 0, 255, 0); +YourScreen.endDraw(); +``` + + +### `beginText()` + +#### Description + + +Start the process of displaying and optionally scrolling text. The Print interface can be used to set the text. + +#### Syntax + +``` +YourScreen.beginText() +YourScreen.beginText(x, y, r, g, b) +YourScreen.beginText(x, y, color) + +``` + + +#### Parameters + + +x: x position of the text +y: y position of the text +r: red color value (0 - 255) +g: green color value (0 - 255) +b: blue color value (0 - 255) +color: 24-bit RGB color, 0xrrggbb + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginText(0, 0, 127, 0, 0); +YourScreen.print("Hi"); +YourScreen.endText(); +``` + + +### `endText()` + +#### Description + + +End the process of displaying and optionally scrolling text. + +#### Syntax + +``` +YourScreen.endText() +YourScreen.endText(scrollDirection) + +``` + + +#### Parameters + + +scrollDirection: (optional) the direction to scroll, defaults to NO_SCROLL if not provided. Valid options are NO_SCROLL, SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP, SCROLL_DOWN + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginText(0, 0, 127, 0, 0); +YourScreen.print("Hi"); +YourScreen.endText(); +``` + + +### `textScrollSpeed()` + +#### Description + + +Sets the text scrolling speed, the speed controls the delay in milliseconds between scrolling each pixel. + +#### Syntax + +``` +YourScreen.textScrollSpeed(speed) + +``` + + +#### Parameters + + +speed: scroll speed + + +#### Returns + +Nothing + +#### Example + +``` +YourScreen.beginText(0, 0, 127, 0, 0); +YourScreen.textScrollSpeed(500); +YourScreen.print("Hello There!"); +YourScreen.endText(true); +``` +