O'Reilly logo

Mastering Arduino by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Drawing a line

We could put several of the drawPixel() function calls together to draw a line, but it would be a lot easier to use the drawLine() function as shown in the following code:

// draw a line
display.drawLine(3,3,30,30, BLACK);
display.display();

The drawLine() function takes five parameters. The first two parameters are the X/Y coordinates of the starting point for the line. The next two parameters are the X/Y coordinates for the ending point of the line, and the final parameter is the color to draw the line. Since the Nokia 5110 LCD is a monochrome display, the only options here are BLACK or WHITE.

If we ran this code, we would see a line on the display like the one seen in the following photograph:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required