I need help error compiling arduino nano

Hey I'm quite new at coding.
I'm currently doing a course in embedded systems. The first assignment is creating a lcd clock. unfortunately due to lockdown i dont have access to the board and lcd screen that the code template was created for.
The teacher decided that he is happy with me using the arduino nano and wavgat oled 128x64 1306 screen on hand. unfortunately im having issue compiling saying "Error compiling for board Arduino Nano". i would appreciate any assistance in getting this to work.

[code]




/**
  Project:  AVR X-mini clock
  File:     tod_clock_outline_arduino.INO

  The LCD module and push-buttons must be wired according to the library requirements.
  (Refer to AVR board code library documentation.)

  Operating instructions:
  To set the time, hold down button 'A' and press 'B' to set hours, 'C' to set minutes.
  To switch between 24-hour and 12-hour (am/pm) display mode, press button 'D'.

  Author:    <Cameron Vonarx>   2020-08-16

*/


// Function prototype declarations...
// `````````````````````````````````````
#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
byte ButtonA = 5;
byte ButtonB = 4;
byte ButtonC = 3;
byte ButtonD = 2;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     4  // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void  DisplayTimeOfDay();
void  SettingTimeOfDay();


// ------------  Global variables  --------------------------------------

char  rtcHour, rtcMinutes, rtcSeconds;    // time-of-day clock "registers" (24-hour mode)
unsigned long  LEDturnOffTime;            // Time to turn LED off (ms since Reset)
boolean  is12hourMode;                       // Flag: True if 12-hour display mode selected

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
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...
  // put your setup code here, to run once:

  // Invert and restore display, pausing in-between
  display.invertDisplay(true);
  delay(1000);
  display.invertDisplay(false);
  delay(1000);

  byte  toggle = 0;

  rtcHour = 11;      // Initialise time-of-day "registers"
  rtcMinutes = 50;
  rtcSeconds = 0;

  // Configure I/O pins (data directions) for push-buttons and LED(s)
  bitSet(LED_BUILTIN, 1);

  display.setCursor(0, 0);
  display.println("AVR X'mini clock");   // string to go on top line
  pinMode(ButtonA, INPUT);
  pinMode(ButtonB, INPUT);
  pinMode(ButtonC, INPUT);
  pinMode(ButtonD, INPUT);
}
void loop() {   // put your main code here, to run repeatedly:
  unsigned long currentMillis = millis();
  unsigned long previousMillis;
  unsigned long previousMillis2;
  unsigned long previousMillis3;

  if (currentMillis - previousMillis > 500)  // True every 0.5 second
  {
    previousMillis = currentMillis;

    if (currentMillis - previousMillis3 > 1000)   // <---- this happens every 1 second (500ms x 2)
    {
      rtcSeconds++;

      bitSet(LED_BUILTIN, 1);   // Turn heartbeat LED ON
      LEDturnOffTime = millis() + 100;

      if (rtcSeconds >= 60)  // 60 seconds up; "roll-over" minute
      {
        rtcSeconds = 0;
        rtcMinutes++;
      }
      if  (rtcMinutes >= 60)  // 60 minutes up; "roll-over" Hour
      {
        rtcMinutes = 0;
        rtcHour++;
      }
      if  (rtcHour >= 24)  // 24 hours up; "roll-over" day
      {
        rtcHour = 0;
      }
    }
  }

  if (currentMillis - previousMillis2 > 50)
  {
    previousMillis2 = currentMillis;
    digitalRead(ButtonD);   // ButtonScan is called every 50ms
  }
  // Check if the LED on-time (duty) has reached 100ms...
  if (millis() >= LEDturnOffTime)  bitClear(LED_BUILTIN, 0); // Turn LED off

  // test for button A held down --> setting mode
  if (ButtonA = HIGH)
  {
    SettingTimeOfDay();
  }
}
void DisplayTimeOfDay() {

  display.clearDisplay();
  display.setTextSize(2);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.setCursor(0, 0);     // Start at top-left corner
  display.cp437(true);         // Use full 256 char 'Code Page 437' font
  byte  hours_12 = 0;
  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  for (int16_t i = 0; i < 256; i++) {
    if (i == '\n') display.write(' ');
    else          display.write(i);
  }
  if (ButtonD = HIGH)
  {
    display.setCursor(1, 2);
    // Determine value of hours_12 based on value of rtcHour
    if  (hours_12 >= 12)  // 12 hours up; "roll-over" day
    {
      hours_12 = 0;
    }


    // 12-hour mode only
    if ((hours_12 / 10) == 0) display.write(' ');
    else display.write((hours_12 / 10) + '0');
    display.write((hours_12 % 10) + '0');
  }
  // what if 24-hour mode selected ?
  if (ButtonD = HIGH)// 24 hours up; "roll-over" day
  {
    display.setCursor(1, 2);
    if (hours_12 >= 24)
    {
      hours_12 = 0;
    }
    if ((hours_12 / 10) == 0) display.write(' ');
    else display.write((hours_12 / 10) + '0');
    display.write((hours_12 % 10) + '0');

  }

  display.print(":");
  display.write((rtcMinutes / 10) + '0' );
  display.write((rtcMinutes % 10) + '0' );
  display.print(":");

  display.write((rtcSeconds / 10) + '0' );
  display.write((rtcSeconds % 10) + '0' );
  display.write(' ');

  // 12-hour mode only
  if (rtcHour < 12)  display.print("am");
  else  display.print("pm");
}


//void testdrawchar(void) {
//display.clearDisplay();
//display.setTextSize(1);      // Normal 1:1 pixel scale
//display.setTextColor(SSD1306_WHITE); // Draw white text
//display.setCursor(0, 0);     // Start at top-left corner
//display.cp437(true);         // Use full 256 char 'Code Page 437' font
// Not all the characters will fit on the display. This is normal.
// Library will draw what it can and the rest will be clipped.
//for(int16_t i=0; i<256; i++) {
//if(i == '\n') display.write(' ');
//else          display.write(i);
//}
// display.display();
// delay(2000);
// }
/*
   To do: Describe workings of this function.  (What does it do and how?)
      Add C code to implement the comments!
      `````````````````````````````````````

*/
void SettingTimeOfDay() // if button B is hit, adjust hours setting, setHours
{
if (ButtonB = HIGH)
{
rtcHour ++;
rtcSeconds = 0;
}

// if button C is hit, adjust minutes setting, setMins
if (ButtonC = HIGH)
{
rtcMinutes ++;
rtcSeconds = 0;
}
}
// real-time seconds = 0

// end of file
[/code]

HI @lumistellar. I'm going to ask you to post some additional information that might help us to identify the problem.

Please do this:

  1. When you encounter an error, you'll see a button on the right side of the orange bar in the Arduino IDE: Copy error messages (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button.
  2. Open a forum reply here by clicking the Reply button.
  3. Click the </> icon on the post composer toolbar. This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block
  4. Press Ctrl+V. This will paste the compilation output into the code block.
  5. Move the cursor outside of the code block markup before you add any additional text to your reply.
  6. Click the Reply button to post the output.

here is the error message btw

Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Nano, ATmega328P"





















In file included from sketch\tod_clock_outline_arduino.ino.cpp:1:0:

G:\My Drive\Study\2021\Semester 2\UEENEED152A\Assignment 1\tod_clock_outline_arduino\tod_clock_outline_arduino.ino: In function 'void setup()':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:112:53: error: lvalue required as left operand of assignment

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                                     ^

G:\My Drive\Study\2021\Semester 2\UEENEED152A\Assignment 1\tod_clock_outline_arduino\tod_clock_outline_arduino.ino:97:3: note: in expansion of macro 'bitSet'

   bitSet(LED_BUILTIN, 1);

   ^~~~~~

G:\My Drive\Study\2021\Semester 2\UEENEED152A\Assignment 1\tod_clock_outline_arduino\tod_clock_outline_arduino.ino: In function 'void loop()':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:112:53: error: lvalue required as left operand of assignment

 #define bitSet(value, bit) ((value) |= (1UL << (bit)))

                                                     ^

G:\My Drive\Study\2021\Semester 2\UEENEED152A\Assignment 1\tod_clock_outline_arduino\tod_clock_outline_arduino.ino:120:7: note: in expansion of macro 'bitSet'

       bitSet(LED_BUILTIN, 1);   // Turn heartbeat LED ON

       ^~~~~~

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:113:56: error: lvalue required as left operand of assignment

 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))

                                                        ^

G:\My Drive\Study\2021\Semester 2\UEENEED152A\Assignment 1\tod_clock_outline_arduino\tod_clock_outline_arduino.ino:146:36: note: in expansion of macro 'bitClear'

   if (millis() >= LEDturnOffTime)  bitClear(LED_BUILTIN, 0); // Turn LED off

                                    ^~~~~~~~

exit status 1

Error compiling for board Arduino Nano.



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

LED_BUILTIN is a pin number. Use digitalWrite(LED_BUILTIN, HIGH); to turn on the LED. Similarly, use digitalWrite(LED_BUILTIN, LOW); to turn it off.

I also get these warnings on your sketch:

235:15: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if (ButtonB = HIGH)
242:15: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   if (ButtonC = HIGH)

They are pointing out that you appear to be doing an assignment (=) where you mean to be doing a comparison (==). Change the '=' to '==' for each of your button checks.

1 Like

thank you for your help mate. Its compiling now. What's your thoughts on on the code layout?

I wouldn't put a 1-second timer inside a 500 millisecond timer.
I would use INPUT_PULLUP and active-low buttons.
Your use of LEDturnOffTime is bad. Always use if (millis() - startTime >= interval) because anything else will fail across the millis() rollover.

1 Like