lineExample();//Thenthelineexamplefunction
shapeExample();//Thentheshapeexample
textExamples();//Finallythetextexample
}
void pixelExample()
{
printTitle("Pixels",1);
for (int i=0;i<512;i++)
{
oled.pixel(random(oled.getLCDWidth()),random(oled.getLCDH
eight()));
oled.display();
}
}
void lineExample()
{
int middleX= oled.getLCDWidth()/2;
int middleY= oled.getLCDHeight()/2;
int xEnd,yEnd;
int lineWidth= min(middleX,middleY);
printTitle("Lines!",1);
for (int i=0;i<3;i++)
{
for (int deg=0;deg<360;deg+=15)
{
xEnd= lineWidth* cos(deg* M_PI/180.0);

yEnd= lineWidth* sin(deg* M_PI/180.0);
oled.line(middleX,middleY,middleX+ xEnd,middleY+yE
nd);
oled.display();
delay(10);
}
for (int deg=0;deg<360;deg+=15)
{
xEnd= lineWidth* cos(deg* M_PI/180.0);
yEnd= lineWidth* sin(deg* M_PI/180.0);
oled.line(middleX,middleY,middleX+ xEnd,middleY+yE
nd,BLACK,NORM);
oled.display();
delay(10);
}
}
}
void shapeExample()
{
printTitle("Shapes!",0);
//Sillypongdemo.Ittakesalotofworktofakepong
...
int paddleW=3;//Paddlewidth
int paddleH= 15;//Paddleheight
//Paddle0(left)positioncoordinates
int paddle0_Y= (oled.getLCDHeight()/2) (paddleH/2);
int paddle0_X=2;
//Paddle1(right)positioncoordinates
int paddle1_Y= (oled.getLCDHeight()/2) (paddleH/2);
int paddle1_X= oled.getLCDWidth() 3 paddleW;
int
ball_rad=2;//Ballradius
Page 7 of 1
2
//Ballpositioncoordinates
int ball_X= paddle0_X+ paddleW+ ball_rad;
int ball_Y= random(1 + ball_rad,oled.getLCDHeight() ball
_rad);//paddle0_Y+ball_rad;
int ballVelocityX=1;//Ballleft/rightvelocity
int ballVelocityY=1;//Ballup/downvelocity
int paddle0Velocity= 1;//Paddle0velocity
int paddle1Velocity=1;//Paddle1velocity
//while(ball_X>=paddle0_X+paddleW 1)
while ((ball_X ball_rad>1)&&
(ball_X+ ball_rad< oled.getLCDWidth() 2))
{
//Incrementball'sposition
b
all_X+=ballVelocityX;
ball_Y+=ballVelocityY;
//Checkiftheballiscollidingwiththeleftpaddle
if (ball_X ball_rad< paddle0_X+ paddleW)
{
//Checkifballiswithinpaddle'sheight
if ((ball_Y> paddle0_Y)&& (ball_Y< paddle0_Y+ paddle
H))
{
ball_X++;//Moveballoveronetotheright
ballVelocityX= ballVelocityX;//Changevelocity
}
}
//Checkiftheballhitth
erightpaddle
if (ball_X+ ball_rad> paddle1_X)
{
//Checkifballiswithinpaddle'sheight
if ((ball_Y> paddle1_Y)&& (ball_Y< paddle1_Y+ paddle
H))
{
ball_X;//Moveballoveronetotheleft
ballVelocityX= ballVelocityX;//changevelocity
}
}
//Checkiftheballhitth
etoporbottom
if ((ball_Y<= ball_rad)|| (ball_Y>= (oled.getLCDHeight
() ball_rad 1)))
{
//Changeup/downvelocitydirection
ballVelocityY= ballVelocityY;
}
//Movethepaddlesupanddown
paddle0_Y+= paddle0Velocity;
paddle1_Y+= paddle1Velocity;
//Changepaddle0'sdirectionifithittop/bottom
if ((paddle0_Y<= 1)|| (paddle0_Y> oled.getLCDHeight()
2 paddleH))
{
paddle0Velocity= paddle0Velocity;
}
//Changepaddle1'sdirect
ionifithittop/bottom
if ((paddle1_Y<= 1)|| (paddle1_Y> oled.getLCDHeight()
2 paddleH))
{
paddle1Velocity= paddle1Velocity;
}
//DrawthePongField
oled.clear(PAGE);//Clearthepage
//Drawanoutlineofthescreen:
oled.rect(0,0,oled.getLCDWidth() 1,oled.getLCDHeight
Page 8 of 1
2
());
//Drawthecenterline
oled.rectFill(oled.getLCDWidth()/2 1,0,2,oled.getLCDH
eight());
//DrawthePaddles:
oled.rectFill(paddle0_X,paddle0_Y,paddleW,paddleH);
oled.rectFill(paddle1_X,paddle1_Y,paddleW,paddleH);
//Drawtheball:
oled.circle(ball_X,ball_Y,ball_rad);
//Actuallydraweverythingonthescreen:
oled.display();
delay(25);//Delayforvisibility
}
delay(1000);
}
void textExamples()
{
printTitle("Text!",1);
//Demonstratefont0.5x8fo
nt
oled.clear(PAGE);//Clearthescreen
oled.setFontType(0);//Setfonttotype0
oled.setCursor(0,0);//Setcursortotopleft
//Thereare255possiblecharactersinthefont0type.
//Letsrunthroughallofthemandprintthemout!
for (int i=0;i<=255;i++)
{
//Youcanwritebytevalue
sandthey'llbemappedto
//theirASCIIequivalentcharacter.
oled.write(i);//Writeabyteoutasacharacter
oled.display();//Drawonthescreen
delay(10);//Wait10ms
//Wecanonlydisplay60font0charactersatatime.
//Every60characters,pauseforamoment.Thenclear
//thepageandstartover.
i
f ((i%60 == 0)&& (i!= 0))
{
delay(500);//Delay500ms
oled.clear(PAGE);//Clearthepage
oled.setCursor(0,0);//Setcursortotopleft
}
}
delay(500);//Wait500msbeforenextexample
//Demonstratefont1.8x16.Let'susetheprintfunction
//todisplayeverycharacterdefinedinthisfont.
ole
d.setFontType(1);//Setfonttotype1
oled.clear(PAGE);//Clearthepage
oled.setCursor(0,0);//Setcursortotopleft
//Printcanbeusedtoprintastringtothescreen:
oled.print("!\"#$%&'()*+,./01234");
oled.display();//Refreshthedisplay
delay(1000);//Delayasecondandrepeat
oled.clear(PAGE);
ole
d.setCursor(0,0);
oled.print("56789:;<=>?@ABCDEFGHI");
oled.display();
delay(1000);
oled.clear(PAGE);
oled.setCursor(0,0);
oled.print("JKLMNOPQRSTUVWXYZ[\\]^");
oled.display();
delay(1000);
oled.clear(PAGE);
Page 9 of 1
2

DEV-13628

Mfr. #:
Manufacturer:
SparkFun
Description:
Display Development Tools PhotonMicro OLED Shield
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet