Bird
0
0
Arduinoprogramming~10 mins

OLED display with I2C (SSD1306) in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A0x3C
B0x68
C0x27
D0x50
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong I2C address causes the display not to initialize.
Confusing OLED address with other sensor addresses.
2fill in blank
medium

Complete 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'
Areset
BclearScreen
Cclear
DclearDisplay
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.
3fill in blank
hard

Fix 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'
A"counter"
Bcounter
Ccounter()
DCounter
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.
4fill in blank
hard

Fill 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'
A>
Blength
Clength()
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' reverses the filter logic.
Using 'length' without parentheses is incorrect for Arduino Strings.
5fill in blank
hard

Fill 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'
Ai * 6
BcharAt
C*
Di + 6
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' causes overlapping characters.
Using message[i] instead of charAt(i) is invalid for Arduino String.