Whys is this happening to me?? I have to meet a deadline please help!! Here is my code.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 display connected using software SPI (default case):
#define OLED_MOSI 11
#define OLED_CLK 12
#define OLED_DC 9
#define OLED_CS 8
#define OLED_RESET 10
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
void setup()
{
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
delay(2000);
display.clearDisplay();
display.drawPixel(10, 10, SSD1306_WHITE);
display.display();
delay(2000);
display.invertDisplay(true);
delay(1000);
display.invertDisplay(false);
delay(1000);
}
void loop()
{
drawLine(20,60,5,50,256);
}
The Error
C:\Users\hp\AppData\Local\Temp\ccyB6dO1.ltrans0.ltrans.o: In function
loop': C:\Users\hp\Desktop\Sunfox\Sunfox\BP_Plus_ECG\February_11\OLED_Testing_w_Adafruit\Test_2\Test_2/Test_2.ino:51: undefined reference to
drawLine(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)' collect2.exe: error: ld returned 1 exit status exit status 1 Error compiling for board Arduino Nano.
-
Kind Sir @MichelKeijzers what does that even mean?Shrie Sharma– Shrie Sharma02/11/2021 10:58:06Commented Feb 11, 2021 at 10:58
-
1I will make an answer.Michel Keijzers– Michel Keijzers02/11/2021 11:01:26Commented Feb 11, 2021 at 11:01
-
@MichelKeijzers But I am using Adafruits built in library. I thought they would have done that for me.Shrie Sharma– Shrie Sharma02/11/2021 11:01:50Commented Feb 11, 2021 at 11:01
-
1I thought initially that you want to create your own function, but I made an answer to use the library instead of your own function.Michel Keijzers– Michel Keijzers02/11/2021 11:03:42Commented Feb 11, 2021 at 11:03
1 Answer 1
Currently, you defined a forward declaration for drawLine
, however I assume you want to call the method (function) inside display
.
So change
drawLine(20,60,5,50,256);
into
display.drawLine(20,60,5,50,256);
And you can remove the forward declaration, because this method is already defined in the library.
void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
Note, if you call drawLine
without an instance (which is display
), then the linker tries to find the drawLine
function which it cannot find, so you get a linker error (see ld returned
in your error, together with undefined reference
).
Explore related questions
See similar questions with these tags.