Creates a variable of type VGA, to communciate with the VGA Shield.
VGA(address)
address - Address on the I2C bus of the shield to communicate with
Instance of VGA associated with a specific VGA Shield.
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
Initialize the shield and start communicating with it.
VGAinstance.begin(**)
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
}
Clear the screen.
VGAInstance.clearScreen(**)
*none
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Clear the screen
vgaInstance.clearScreen();
}
Set the current screen resolution.
VGAInstance.setResolution(resolution)
resolution - One of RES_320x240, RES_640x480, or RES_800x480
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set the resolution to 640x480
vgaInstance.setResolution(RES_640x480);
}
Set which memory page is currently being displayed.
VGAInstance.setDisplayPage(page)
page - Page number to display
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set the current display page to 2, so all video on the VGA output will come from page 2
// NOTE: multi-page support is only available in 320x240 resolution
vgaInstance.setDisplayPage(2);
}
Set which memory page is used for read operations.
VGAInstance.setReadPage(page)
page - Page number to use for read operations
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set the current read page to 2, so all future calls which read pixels will read them from page 2
// NOTE: multi-page support is only available in 320x240 resolution
vgaInstance.setReadPage(2);
}
Set which memory page is used for write operations.
VGAInstance.setWritePage(page)
page - Page number to use for write operations
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set the current write page to 2, so all future drawing will take place on page 2
// NOTE: multi-page support is only available in 320x240 resolution
vgaInstance.setWritePage(2);
}
Set the background colour used for drawing opaque text.
VGAInstance.setBackground(colour)
colour - Colour to use for background when drawing opaque text.
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set the background colour of any text drawn in the future to green
vgaInstance.setBackground(vgaInstance.generateColour(0, 255, 0));
}
Set whether any shapes drawn are filled or outlined. Affects only newly drawn shapes, existing shapes are not changed.
VGAInstance.fillShapes(fill)
fill - 0 to draw outlined shapes, 1 to draw filled shapes
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set any future shapes drawn to be filled
vgaInstance.fillShapes(1);
}
Copy one rectangular area of the screen onto another area.
VGAInstance.copyArea(xSrc, ySrc, xDest, yDest, width, height)
xSrc - Horizontal pixel position for the top of the source area ySrc - Vertical pixel position for the left side of the source area xDest - Horizontal pixel position for the top of the destination area yDest - Vertical pixel position for the left side of the destination area width - Width of the area to copy, in pixels height - Height of the area to copy, in pixels
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Copy a 100x100 pixel rectangular area of the currently displayed image from pixel location 50, 50 to 200, 200
vgaInstance.copyArea(50, 50, 200, 200, 100, 100);
}
Draw a single pixel.
VGAInstance.drawPixel(x1, y1, x2, y2, colour)
x - Horizontal pixel position for the pixel y - Vertical pixel position for the pixel colour - Colour to draw the pixel in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a red pixel at screen location 50, 50
vgaInstance.drawPixel(50, 50, vgaInstance.generateColour(255, 0, 0));
}
Draw a line.
VGAInstance.drawLine(x1, y1, x2, y2, colour)
x1 - Horizontal pixel position for the start of the line y1 - Vertical pixel position for the start of the line x2 - Horizontal pixel position for the start of the line y2 - Vertical pixel position for the start of the line colour - Colour to draw the line in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a green line from screen location 50, 50 to 150, 150
vgaInstance.drawLine(50, 50, 150, 150, vgaInstance.generateColour(0, 255, 0));
}
Draw a rectangle.
VGAInstance.drawLine(x1, y1, x2, y2, colour)
x1 - Horizontal pixel position for the left side of the rectangle y1 - Vertical pixel position for the top of the rectangle x2 - Horizontal pixel position for the right side of the rectangle y2 - Vertical pixel position for the bottom of the rectangle colour - Colour to draw the rectangle in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a green line from screen location 50, 50 to 150, 150
vgaInstance.drawLine(50, 50, 150, 150, vgaInstance.generateColour(0, 255, 0));
}
Draw a circle.
VGAInstance.drawCircle(x, y, radius, colour)
x - Horizontal pixel position for the center of the circle y - Vertical pixel position for the center of the circle radius - Radius of the circle in pixels colour - Colour to draw the circle in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a red circle centered at screen location 250, 250, with a radius of 50 pixels
vgaInstance.drawCircle(250, 250, 50, vgaInstance.generateColour(255, 0, 0));
}
Draw an ellipse/oval.
VGAInstance.drawEllipse(x, y, radiusX, radiusY, colour)
x - Horizontal pixel position for the center of the circle y - Vertical pixel position for the center of the circle radiusX - Horizontal radius of the circle in pixels radiusY - Vertical radius of the circle in pixels colour - Colour to draw the ellipse in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a green ellipse centered at screen location 250, 250, with a radius of 50 pixels across and 25 pixels up/down
vgaInstance.drawEllipse(250, 250, 50, 25, vgaInstance.generateColour(255, 0, 0));
}
Replace one colour with another in a certain rectangular area.
VGAInstance.replaceColour(x1, y1, x2, y2, oldColour, newColour)
x1 - Horizontal pixel position for the left side of the area y1 - Vertical pixel position for the top of the area x2 - Horizontal pixel position for the right side of the area y2 - Vertical pixel position for the bottom of the area oldColour - Colour to be replaced newColour - Colour to replace with
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Replace all black pixels with purple pixels in a rectangular area from pixel location 50, 50 to 150, 150
vgaInstance.replaceColour(50, 50, 150, 150, vgaInstance.generateColour(0, 0, 0), vgaInstance.generateColour(255, 0, 255));
}
Set the current font to use when drawing characters or text.
VGAInstance.setFont(font)
font - Font name (one of the following monospace fonts: FONT_5x7, FONT_8x8, FONT_8x12, FONT_12x16, or one of the following proportional fonts: FONT_5x7_PROP, FONT_8x8_PROP, FONT_8x12_PROP, FONT_12x16_PROP)
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set the font for future text drawing operations to 12x16 pixel proportional
vgaInstance.setFont(FONT_12x16_PROP);
}
Set whether text is drawn with a transparent or opaque background.
VGAInstance.textBackgroundOpaque(opaque)
opaque - 0 to draw text with a transparent background, 1 to draw with an opaque background
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set text background to transparent for all future text drawing operations
vgaInstance.textBackgroundOpaque(0);
}
Initialize an 8x8 pixel sprite, storing the data on the shield for later drawing.
VGAInstance.initSprite(id, sprite)
id - Sprite ID to initialize sprite - Sprite data, as 8 8-bit bytes where each byte is one horizontal line of the sprite
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set up an 8x8 pixel sprite at ID 2 to later draw with drawSprite()
byte spriteData[8];
spriteData[0] = 0x18;
spriteData[1] = 0x24;
spriteData[2] = 0x42;
spriteData[3] = 0x81;
spriteData[4] = 0x81;
spriteData[5] = 0x42;
spriteData[6] = 0x24;
spriteData[7] = 0x18;
vgaShield.initSprite(2, spriteData);
}
Initialize a 16x16 pixel sprite, storing the data on the shield for later drawing.
VGAInstance.initSprite(id, sprite)
id - Sprite ID to initialize sprite - Sprite data, as 16 16-bit shorts where each short is one horizontal line of the sprite
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set up an 8x8 pixel sprite at ID 2 to later draw with drawSprite()
byte spriteData[8];
spriteData[0] = 0x18;
spriteData[1] = 0x24;
spriteData[2] = 0x42;
spriteData[3] = 0x81;
spriteData[4] = 0x81;
spriteData[5] = 0x42;
spriteData[6] = 0x24;
spriteData[7] = 0x18;
vgaShield.initSprite(2, spriteData);
}
Initialize a 32x32 pixel sprite, storing the data on the shield for later drawing.
VGAInstance.initSprite(id, sprite)
id - Sprite ID to initialize sprite - Sprite data, as 32 32-bit longs where each long is one horizontal line of the sprite
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set up an 8x8 pixel sprite at ID 2 to later draw with drawSprite()
byte spriteData[8];
spriteData[0] = 0x18;
spriteData[1] = 0x24;
spriteData[2] = 0x42;
spriteData[3] = 0x81;
spriteData[4] = 0x81;
spriteData[5] = 0x42;
spriteData[6] = 0x24;
spriteData[7] = 0x18;
vgaShield.initSprite(2, spriteData);
}
Initialize a 32x32 pixel sprite with X Bitmap (XBM) data, storing the data on the shield for later drawing.
VGAInstance.initSpriteXbm(id, xbmdata)
id - Sprite ID to initialize xbmdata - Sprite data, as XBM formatted data
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// array of XBM data to turn into a sprite
static byte xbmdata_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x0F, 0x00,
0xC0, 0xFF, 0x0F, 0x00, 0xC0, 0x0F, 0xCF, 0x00, 0xC0, 0x0F, 0xCF, 0x00,
0xC0, 0x0F, 0x0F, 0x00, 0xC0, 0x0F, 0x0F, 0x00, 0xC0, 0x0F, 0xFF, 0x03,
0xC0, 0x0F, 0xFF, 0x03, 0xC0, 0x0F, 0xFF, 0x03, 0xC0, 0x0F, 0xFF, 0x03,
0xC0, 0xFF, 0xFF, 0x03, 0xC0, 0xFF, 0xFF, 0x03, 0xC0, 0x0F, 0xFF, 0x03,
0xC0, 0x0F, 0xFF, 0x03, 0xCC, 0xFF, 0xFF, 0x33, 0xCC, 0xFF, 0xFF, 0x33,
0x0C, 0x00, 0x00, 0x30, 0x0C, 0x00, 0x00, 0x30, 0xFC, 0xFF, 0xFF, 0x3F,
0xFC, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFC, 0xFF, 0xFF, 0x3F, 0xFC, 0xFF, 0xFF, 0x3F, 0xFC, 0xFF, 0xFF, 0x33,
0xFC, 0xFF, 0xFF, 0x33, 0xFC, 0xFF, 0xFF, 0x3F, 0xFC, 0xFF, 0xFF, 0x3F,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Set up a 32x32 pixel sprite from the data above at ID 2 to later draw with drawSprite()
vgaInstance.initSpriteXbm(0, xbmdata_bits);
}
Draw a previously-initialized sprite at a given location in a given colour.
VGAInstance.drawSprite(type, id, x, y, colour)
type - Type of sprite, either SPRITE_8x8, SPRITE_16x16, or SPRITE_32x32 id - Sprite ID to draw x - Horizontal position at which to draw the upper left corner of the sprite y - Vertical position at which to draw the upper left corner of the sprite
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw 8x8 pixel sprite ID 2 (previously set up using initSprite()) at pixel location 50, 50 in blue
vgaInstance.drawSprite(SPRITE_8x8, 2, 50, 50, vgaInstance.generateColour(0, 0, 255));
}
Draw one character of text at a given text grid location using the previously set font.
VGAInstance.drawCharacter(chr, x, y, colour)
chr - Character to draw (normal ASCII values) x - Horizontal grid position at which to draw the character y - Vertical grid position at which to draw the character colour - Colour to draw the character in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a blue letter C at text grid location 10, 10
vgaInstance.drawCharacter('C', 10, 10, vgaInstance.generateColour(0, 0, 255));
}
Draw one character of text at a given pixel location.
VGAInstance.drawGraphicsCharacter(chr, x, y, colour)
chr - Character to draw (normal ASCII values) x - Horizontal pixel position at which to draw the character y - Vertical pixel position at which to draw the character width - Width of the character (stretches if it doesn't match the font size) height - Height of the character (stretches if it doesn't match the font size) colour - Colour to draw the character in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a large blue letter C at pixel location 200, 200
vgaInstance.drawGraphicsCharacter('C', 200, 200, 2, 2, vgaInstance.generateColour(0, 0, 255));
}
Draw a text string at a given text grid location.
VGAInstance.drawText(text, x, y, colour)
text - Pointer to string of text to draw x - Horizontal text grid position at which to draw the text y - Vertical text grid position at which to draw the text colour - Colour to draw the text in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw the word "Ostrich" in red starting at text grid location 10, 10
vgaInstance.drawText("Ostrich", 10, 10, vgaInstance.generateColour(255, 0, 0));
}
Draw a text string at a given pixel location.
VGAInstance.drawGraphicsText(text, x, y, colour)
text - Pointer to string of text to draw x - Horizontal pixel position at which to draw the text y - Vertical pixel position at which to draw the text colour - Colour to draw the text in
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Draw a the word Ostrich in large green letters at pixel location 200, 200
vgaInstance.drawGraphicsText("Ostrich", 200, 200, 2, 2, vgaInstance.generateColour(0, 255, 0));
}
Display an image stored on a raw (non-FAT) SD card. This image needs to be stored using 4D Systems Graphics Composer.
VGAInstance.displayImageFromRawSD(offset, x, y)
offset - Offset into the SD card at which the image is stored x - Horizontal pixel position at which to draw the left side of the image y - Vertical pixel position at which to draw the top of the image
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Display image at index 0 of a raw (non-FAT) MicroSD card
vgaInstance.displayImageFromRawSD(0, 150, 150);
}
Display a video clip stored on a raw (non-FAT) SD card. This video needs to be stored using 4D Systems Graphics Composer.
VGAInstance.playVideoFromRawSD(offset, x, y, ifd)
offset - Offset into the SD card at which the video is stored x - Horizontal pixel position at which to place the left side of the video y - Vertical pixel position at which to place the top of the video ifd - Inter-frame delay, in milliseconds
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Play the video stored at index 0 of a raw (non-FAT) MicroSD card at pixel location 150, 150, with 33mS between each frame
vgaInstance.playVideoFromRawSD(0, 150, 150, 33);
}
Display an image from a GCI file stored on a microSD card. GCI files can be created using 4D Systems Graphics Composer.
VGAInstance.displayImageFromSD(filename, offset, x, y)
filename - File name of the GCI file to pull images from offset - Offset in the GCI file of the image to display x - Horizontal pixel position for the left side of the image y - Vertical pixel position for the top of the image
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Display image at index 0 of file ostrich.gci at pixel location 150, 150
// ostrich.gci would need to be created using 4D Graphics Composer
vgaInstance.displayImageFromSD("ostrich.gci", 0, 150, 150);
}
Generate a PackedColour from red/green/blue values, which can then be passed to all functions that require colour specification.
VGAInstance.generateColour(r, g, b)
r - Red value, from 0 to 255 g - Green value, from 0 to 255 b - Blue value, from 0 to 255
none
#include <Wire.h>
#include <MultiSerial.h>
#include <VGA.h>
// Create a VGA instance to communicate with the shield at address 0x4D
VGA vgaInstance = VGA(0x4D);
void setup() {
PackedColour colour;
// Initialize the shield to get it ready to communicate with
vgaInstance.begin();
// Store the colour blue in the 'colour' variable for later use
colour = vgaInstance.generateColour(255, 0, 0);
}