A
A
Anonymous54545872021-05-31 20:08:40
Arduino
Anonymous5454587, 2021-05-31 20:08:40

Arduino sketch won't load. Which mistakes?

Gives an error message

Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Leonardo"
C:\Users\Kostya\ArduinoIDE1.0.6\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega32u4 -DF_CPU=16000000L -MMD -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DARDUINO=106 -IC:\Users\Kostya\ArduinoIDE1.0.6\hardware\arduino\cores\arduino -IC:\Users\Kostya\ArduinoIDE1.0.6\hardware\arduino\variants\leonardo -IC:\Users\Kostya\ArduinoIDE1.0.6\libraries\SPI -IC:\Users\Kostya\ArduinoIDE1.0.6\libraries\Wire -IC:\Users\Kostya\Documents\Arduino\libraries\Adafruit-GFX-Library-master -IC:\Users\Kostya\Documents\Arduino\libraries\Adafruit_SSD1306-master C:\Users\Kostya\AppData\Local\Temp\build8495016340664567829.tmp\sketch_may31c.cpp -o C:\Users\Kostya\AppData\Local\Temp\build8495016340664567829.tmp\sketch_may31c.cpp.o 

sketch_may31c.ino: In function 'void setup()':
sketch_may31c.ino:18: warning: only initialized variables can be placed into program memory area
sketch_may31c.ino: In function 'void loop()':
sketch_may31c:26: error: 'i' was not declared in this scope


The code:
#include <SPI.h> //spi library
#include <Wire.h> //i2c library
#include <Adafruit_GFX.h> //display library
#include <Adafruit_SSD1306.h> //oled library

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  Serial.begin(9600);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
}
  
void loop() {
    display.clearDisplay(); //clear

    for(i=display.width()-1; i>=0; i-=4) {
        display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE); //:)
        display.display();
        delay(1);
        
    }
}


IDE version: Arduino 1.0.6

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Volkov, 2021-06-01
@Anonymous5454587

void loop() {
    int i = 0;
    display.clearDisplay(); //clear

    for(i=display.width()-1; i>=0; i-=4) {
        display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE); //:)
        display.display();
        delay(1);
        
    }
}

or
void loop() {
    display.clearDisplay(); //clear

    for(int i=display.width()-1; i>=0; i-=4) {
        display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE); //:)
        display.display();
        delay(1);
        
    }
}

V
Vasily Bannikov, 2021-05-31
@vabka

you don't declare variable i in the loop

B
Borys Latysh, 2021-07-15
@nava2002

Most likely the loader is to blame .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question