User Tools

Site Tools


tutorials:gfx

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
tutorials:gfx [2012/04/05 04:50]
pburgess [Rectangles]
tutorials:gfx [2012/04/09 23:21]
pburgess [Overview]
Line 3: Line 3:
 The Adafruit_GFX library for Arduino provides a common syntax and set of graphics functions for all of our LCD and OLED displays. This allows Arduino sketches to easily be adapted between display types with minimal fuss…and any new features, performance improvements and bug fixes will immediately apply across our complete offering of color displays. The Adafruit_GFX library for Arduino provides a common syntax and set of graphics functions for all of our LCD and OLED displays. This allows Arduino sketches to easily be adapted between display types with minimal fuss…and any new features, performance improvements and bug fixes will immediately apply across our complete offering of color displays.
  
-The Adafruit_GFX library works together with a second library provided for each specific display type — for example, the ST7735 1.8" color LCD requires installing both the Adafruit_GFX and Adafruit_ST7735 libraries. [[http://​www.ladyada.net/​library/​arduino/​libraries.html|For information how to use and install libraries, see our tutorial!]]+The Adafruit_GFX library works together with a second library provided for each specific display type — for example, the ST7735 1.8" color LCD requires installing both the Adafruit_GFX and Adafruit_ST7735 libraries. ​The following libraries now operate in this manner: 
 + 
 +  * [[https://​github.com/​adafruit/​RGB-matrix-Panel|RGBmatrixPanel]],​ for our [[http://​www.adafruit.com/​products/​420|16x32]] and [[http://​www.adafruit.com/​products/​607|32x32]] RGB LED matrix panels. 
 +  * [[https://​github.com/​adafruit/​TFTLCD-Library|Adafruit_TFTLCD]],​ for our 2.8" [[http://​www.adafruit.com/​products/​335|TFT LCD touchscreen breakout]] and [[http://​www.adafruit.com/​products/​376|TFT Touch Shield for Arduino]]. 
 +  * [[https://​github.com/​adafruit/​Adafruit-ST7735-Library|Adafruit_ST7735]],​ for our [[http://​www.adafruit.com/​products/​358|1.8"​ TFT Display with microSD]]. 
 +  * [[https://​github.com/​adafruit/​Adafruit-PCD8544-Nokia-5110-LCD-library|Adafruit_PCD8544]],​ for the [[http://​www.adafruit.com/​products/​338|Nokia 5110/3310 monochrome LCD]]. 
 +  * (In progress — list will be updated shortly) 
 + 
 +[[http://​www.ladyada.net/​library/​arduino/​libraries.html|For information how to use and install libraries, see our tutorial!]]
  
 The libraries are written in C++ for Arduino but could easily be ported to any microcontroller by rewriting the low-level pin access functions. The libraries are written in C++ for Arduino but could easily be ported to any microcontroller by rewriting the low-level pin access functions.
Line 9: Line 17:
 ====== Coordinate System and Units ====== ====== Coordinate System and Units ======
  
-Pixels — picture elements, the blocks comprising a digital image — are addressed by their horizontal (X) and vertical (Y) coordinates. The coordinate system places the origin (0,0) at the top left corner, with positive X increasing to the right and positive Y increasing downward. This is upside-down relative to the standard Cartesian coordinate system of mathematics,​ but is established practice in many computer graphics systems (a throwback to the days of raster-scan CRT graphics, which worked top-to bottom). To use a tall “portrait” layout rather than wide “landscape” format, or if physical constraints dictate the orientation of a display in an enclosure, one of four rotation settings can also be applied, indicating which corner of the display represents the top left.+Pixels — picture elements, the blocks comprising a digital image — are addressed by their horizontal (X) and vertical (Y) coordinates. The coordinate system places the origin (0,0) at the top left corner, with positive X increasing to the right and positive Y increasing downward. This is upside-down relative to the standard Cartesian coordinate system of mathematics,​ but is established practice in many computer graphics systems (a throwback to the days of raster-scan CRT graphics, which worked top-to-bottom). To use a tall “portrait” layout rather than wide “landscape” format, or if physical constraints dictate the orientation of a display in an enclosure, one of four rotation settings can also be applied, indicating which corner of the display represents the top left.
  
 Also unlike the mathematical Cartesian coordinate system, points here have dimension — they are always one full integer pixel wide and tall. Also unlike the mathematical Cartesian coordinate system, points here have dimension — they are always one full integer pixel wide and tall.
Line 15: Line 23:
 {{ :​tutorials:​gfx:​coordsys.png?​nolink&​ |}} {{ :​tutorials:​gfx:​coordsys.png?​nolink&​ |}}
  
-Coordinates are always expressed in pixel units; there is no implicit scale to a real-world measure like millimeters or inches, and the size of a displayed graphic will be a function of that specific display’s //dot pitch// or pixel density. If seeking ​specific ​real-world dimension, you’ll need to scale your coordinates to suit. Dot pitch can often be found in the device datasheet, or by measuring the screen width and dividing the number of pixels across by this measurement.+Coordinates are always expressed in pixel units; there is no implicit scale to a real-world measure like millimeters or inches, and the size of a displayed graphic will be a function of that specific display’s //dot pitch// or pixel density. If you’re aiming for a real-world dimension, you’ll need to scale your coordinates to suit. Dot pitch can often be found in the device datasheet, or by measuring the screen width and dividing the number of pixels across by this measurement.
  
 For color-capable displays, colors are represented as unsigned 16-bit values. Some displays may physically be capable of more or fewer bits than this, but the library operates with 16-bit values…these are easy for the Arduino to work with while also providing a consistent data type across all the different displays. The primary color components — red, green and blue — are all “packed” into a single 16-bit variable, with the most significant 5 bits conveying red, middle 6 bits conveying green, and least significant 5 bits conveying blue. That extra bit is assigned to green because our eyes are most sensitive to green light. //​Science!//​ For color-capable displays, colors are represented as unsigned 16-bit values. Some displays may physically be capable of more or fewer bits than this, but the library operates with 16-bit values…these are easy for the Arduino to work with while also providing a consistent data type across all the different displays. The primary color components — red, green and blue — are all “packed” into a single 16-bit variable, with the most significant 5 bits conveying red, middle 6 bits conveying green, and least significant 5 bits conveying blue. That extra bit is assigned to green because our eyes are most sensitive to green light. //​Science!//​
Line 85: Line 93:
  
 void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);</​code>​ void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);</​code>​
 +
 +{{ :​tutorials:​gfx:​circle.png?​nolink&​ |}}
  
 [[http://​www.ladyada.net/​images/​18tftbreakout/​st7735circles.jpg|{{ ​ http://​www.ladyada.net/​images/​18tftbreakout/​st7735circles_t.jpg?​nolink&​500x311 ​ |}}]] [[http://​www.ladyada.net/​images/​18tftbreakout/​st7735circles.jpg|{{ ​ http://​www.ladyada.net/​images/​18tftbreakout/​st7735circles_t.jpg?​nolink&​500x311 ​ |}}]]
Line 96: Line 106:
 void fillRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);</​code>​ void fillRoundRect(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t radius, uint16_t color);</​code>​
  
-(Image will go here)+{{ :​tutorials:​gfx:​roundrect.png?​nolink&​ |}}
  
 Here’s an added bonus trick: because the circle functions are always drawn relative to a center pixel, the resulting circle diameter will always be an odd number of pixels. If an even-sized circle is required (which would place the center point //between// pixels), this can be achieved using one of the rounded rectangle functions: pass an identical width and height that are even values, and a corner radius that’s exactly half this value. Here’s an added bonus trick: because the circle functions are always drawn relative to a center pixel, the resulting circle diameter will always be an odd number of pixels. If an even-sized circle is required (which would place the center point //between// pixels), this can be achieved using one of the rounded rectangle functions: pass an identical width and height that are even values, and a corner radius that’s exactly half this value.
Line 107: Line 117:
 void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);</​code>​ void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);</​code>​
  
-(Image will be added here) +{{ :​tutorials:​gfx:​triangle.png?​nolink&​ |}}
 ===== Characters and text ===== ===== Characters and text =====
  
Line 114: Line 123:
  
 <code C>void drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint8_t size);</​code>​ <code C>void drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint8_t size);</​code>​
 +
 +{{ :​tutorials:​gfx:​char.png?​nolink&​ |}}
  
 Text is very flexible but operates a bit differently. Instead of one procedure, the text size, color and position are set up in separate functions and then the ''​print()''​ function is used — this makes it easy and provides all of the same string and number formatting capabilities of the familiar ''​Serial.print()''​ function! Text is very flexible but operates a bit differently. Instead of one procedure, the text size, color and position are set up in separate functions and then the ''​print()''​ function is used — this makes it easy and provides all of the same string and number formatting capabilities of the familiar ''​Serial.print()''​ function!
/home/ladyada/public_html/wiki/data/pages/tutorials/gfx.txt · Last modified: 2016/01/28 18:05 (external edit)