Project 7.01 Writing Text to the Screen

In this code, you'll 嘟嘟嘟www在线观看免费高清 how to display text and numbers on the OLED screen!
In this project you’ll 嘟嘟嘟www在线观看免费高清 how to write text to the OLED, change its size, and about printing variables.

Project Code:

				
					////////////////////////////////////////////////////////////////////////
// 7.01 - Writing Text to The Screen

#include <Adafruit_SSD1306.h>
#include <splash.h>

byte screenWidth = 128;
byte screenHeight = 64;
byte screenAddress = 0x3C;
byte numberToPrint = 123;

Adafruit_SSD1306 display(screenWidth, screenHeight, &Wire);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, screenAddress);
  display.setTextColor(SSD1306_WHITE); 
}

void loop() {
  display.clearDisplay();
  display.setCursor(0,0); 

  display.setTextSize(3); 

  display.println("Hello!");
  display.print(numberToPrint); 
  display.display();
}
////////////////////////////////////////////////////////////////////////
				
			

*If you’re copying and pasting the code, or typing from scratch, delete everything out of a new Arduino sketch and paste / type in the above text.

First, we have to include the correct libraries, declare our standard variables, and include the constructor.

				
					#include <Adafruit_SSD1306.h>
#include <splash.h>

byte screenWidth = 128;
byte screenHeight = 64;
byte screenAddress = 0x3C;
byte numberToPrint = 123;

Adafruit_SSD1306 display(screenWidth, screenHeight, &Wire);
				
			

In the setup() function, we need to set the OLED up. The only two things that you absolutely need to do are use the begin and setTextColor functions.

				
					void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, screenAddress);
  display.setTextColor(SSD1306_WHITE); 
}
				
			

In the loop() function, the first thing we want to do is clear any text that is currently on the screen and reset the cursor to (0,0).

				
					void loop() {
  display.clearDisplay();
  display.setCursor(0,0);    
				
			

Next, we need to set the text size that we would like. Good options are 1-3, but you can go bigger.

				
					display.setTextSize(3); 
				
			

Then we can print some text! First, we print “Hello!” and then we print a variable. You can use the print and println functions to print all of the same things that you can print using the Serial functions.

				
					  display.println("Hello!");
  display.print(numberToPrint); 
  display.display();
}
////////////////////////////////////////////////////////////////////////
				
			

嘟嘟嘟www在线观看免费高清 More In Our Free Instructional Guidebook

This comprehensive guidebook for the 嘟嘟嘟www在线观看免费高清 人禽杂交18禁网站免费 Trainer provides a comprehensive introduction to the world of Arduino programming for beginners. It guides users through the foundational concepts of 人禽杂交18禁网站免费s, detailing the unique features of the Arduino Leonardo-compatible MCU Trainer board. The manual offers a step-by-step journey from understanding the hardware components and the Arduino programming language to the vibrant global community of Arduino enthusiasts. It delves into the intricacies of each onboard circuit, explaining their functionalities and applications. With a focus on hands-on 嘟嘟嘟www在线观看免费高清ing, the manual includes a series of coding exercises, tutorials in C/C++, and insights into the Arduino IDE.

More Projects

Project 1.00 Blink

In this project, you’ll 嘟嘟嘟www在线观看免费高清 how to blink an LED!

Project 1.01 Blink x2

In this project, you’ll 嘟嘟嘟www在线观看免费高清 how to blink more than one LED!