oled program gives error but not a different program?

Hello,
I am trying to use an oled display and I made a hello world program and it fails to upload.

C:\Users\benjc\AppData\Local\Temp\ccVabx9A.ltrans0.ltrans.o: In function `main':
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "Adafruit_SSD1306.h"
 Used: C:\Users\benjc\OneDrive\Documents\Arduino\libraries\Adafruit_SSD1306
 Not used: C:\Users\benjc\OneDrive\Documents\Arduino\libraries\Adafruit_SSD1306-master
Multiple libraries were found for "Adafruit_GFX.h"
 Used: C:\Users\benjc\OneDrive\Documents\Arduino\libraries\Adafruit_GFX_Library
 Not used: C:\Users\benjc\OneDrive\Documents\Arduino\libraries\Adafruit-GFX-Library-master
Using library Adafruit_GFX_Library at version 1.10.5 in folder: C:\Users\benjc\OneDrive\Documents\Arduino\libraries\Adafruit_GFX_Library 
Using library Adafruit_SSD1306 at version 2.4.2 in folder: C:\Users\benjc\OneDrive\Documents\Arduino\libraries\Adafruit_SSD1306 
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SPI 
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
Using library Adafruit_BusIO at version 1.7.2 in folder: C:\Users\benjc\OneDrive\Documents\Arduino\libraries\Adafruit_BusIO 
exit status 1
Error compiling for board Arduino Uno.

code:

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(-1);
void setup()
{
display.clearDisplay();
display.setTextColor(WHITE);
display.setCursor(0,24);
display.setTextSize(2);
display.println("Hello!");
display.display();
delay(2000);
}

and when I upload this:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(-1);

void setup()   
{                
	// initialize with the I2C addr 0x3C
	display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  

	// Clear the buffer.
	display.clearDisplay();

	// Display Text
	display.setTextSize(1);
	display.setTextColor(WHITE);
	display.setCursor(0,28);
	display.println("Hello world!");
	display.display();
	delay(2000);
	display.clearDisplay();

	// Display Inverted Text
	display.setTextColor(BLACK, WHITE); // 'inverted' text
	display.setCursor(0,28);
	display.println("Hello world!");
	display.display();
	delay(2000);
	display.clearDisplay();

	// Changing Font Size
	display.setTextColor(WHITE);
	display.setCursor(0,24);
	display.setTextSize(2);
	display.println("Hello!");
	display.display();
	delay(2000);
	display.clearDisplay();

	// Display Numbers
	display.setTextSize(1);
	display.setCursor(0,28);
	display.println(123456789);
	display.display();
	delay(2000);
	display.clearDisplay();

	// Specifying Base For Numbers
	display.setCursor(0,28);
	display.print("0x"); display.print(0xFF, HEX); 
	display.print("(HEX) = ");
	display.print(0xFF, DEC);
	display.println("(DEC)"); 
	display.display();
	delay(2000);
	display.clearDisplay();

	// Display ASCII Characters
	display.setCursor(0,24);
	display.setTextSize(2);
	display.write(3);
	display.display();
	delay(2000);
	display.clearDisplay();

	// Scroll full screen
	display.setCursor(0,0);
	display.setTextSize(1);
	display.println("Full");
	display.println("screen");
	display.println("scrolling!");
	display.display();
	display.startscrollright(0x00, 0x07);
	delay(2000);
	display.stopscroll();
	delay(1000);
	display.startscrollleft(0x00, 0x07);
	delay(2000);
	display.stopscroll();
	delay(1000);    
	display.startscrolldiagright(0x00, 0x07);
	delay(2000);
	display.startscrolldiagleft(0x00, 0x07);
	delay(2000);
	display.stopscroll();
	display.clearDisplay();

	// Scroll part of the screen
	display.setCursor(0,0);
	display.setTextSize(1);
	display.println("Scroll");
	display.println("some part");
	display.println("of the screen.");
	display.display();
	display.startscrollright(0x00, 0x00);
}

void loop() {}

it works (I didn’t make the 2nd one) does anyone know the problem?

The compiler is telling you the problem:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop'

Where's your loop() function in the code that doesn't work?

Ummm... oh that’s why :slight_smile: (+ 1 karma)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.