Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the OLED display with the correct I2C address.
Arduino
#include <Wire.h> #include <Adafruit_SSD1306.h> #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); void setup() { Wire.begin(); if(!display.begin(SSD1306_SWITCHCAPVCC, [1])) { for(;;); // Don't proceed, loop forever } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong I2C address causes the display not to initialize.
Confusing OLED address with other sensor addresses.
✗ Incorrect
The common I2C address for SSD1306 OLED displays is 0x3C. Using this address initializes the display correctly.
2fill in blank
mediumComplete the code to clear the display before showing new content.
Arduino
void loop() {
display.[1]();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println("Hello, OLED!");
display.display();
delay(2000);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like clearScreen() or clear().
Not clearing the display before drawing new content causes overlapping text.
✗ Incorrect
The method clearDisplay() clears the buffer so the new content can be drawn fresh.
3fill in blank
hardFix the error in the code to display a number on the OLED.
Arduino
int counter = 0; void loop() { display.clearDisplay(); display.setCursor(0, 10); display.print("Count: "); display.print([1]); display.display(); counter++; delay(1000); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable name in quotes prints the word 'counter' instead of the number.
Using parentheses like counter() treats it like a function, causing errors.
✗ Incorrect
To print the value of the variable counter, use its name without quotes or parentheses.
4fill in blank
hardFill both blanks to loop through an array of words, printing those longer than 3 characters along with their lengths to the Serial monitor.
Arduino
String words[] = {"cat", "house", "dog", "elephant"};
int size = 4;
void setup() {
Serial.begin(9600);
for (int i = 0; i < size; i++) {
if (words[i].length() [1] 3) {
Serial.print(words[i]);
Serial.print(": ");
Serial.println(words[i].[2]());
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' reverses the filter logic.
Using 'length' without parentheses is incorrect for Arduino Strings.
✗ Incorrect
To filter words longer than 3 characters, use '>' and to get the length, use the length() method.
5fill in blank
hardFill all three blanks to create a loop that displays each character of a string on the OLED at increasing x positions.
Arduino
String message = "Hi!"; void loop() { display.clearDisplay(); for (int i = 0; i < message.length(); i++) { display.setCursor([1], 0); display.print(message.[2](i)); } display.display(); delay(2000); } // Calculate x position as i times 6 pixels // int xPos = i [3] 6; // Use xPos or equivalent expression for [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' causes overlapping characters.
Using message[i] instead of charAt(i) is invalid for Arduino String.
✗ Incorrect
The x position is i multiplied by 6 pixels, the method to get a character is charAt, and the operator is '*'.
