simple error?

Folks, I’ve got a few lines of code here. Getting an error - I’m not sure what it means. Any help would be appreciated. The Else If line is getting flagged it seems.

#include <Wire.h>                                 //
#include "SevSeg.h"                               //

#include "Adafruit_LEDBackpack.h"                 // Library for the 7 segment display
#include "Adafruit_GFX.h"                         // 
#include "RTClib.h"                               // Library for the RTC
    
RTC_DS1307 RTC;                                   // 

Adafruit_7segment disp = Adafruit_7segment();     // 

SevSeg sevseg;                                    // 

uint32_t currentTime;                             // 

void setup(){

  byte numDigits = 4;                             // 
  byte digitPins[] = {10, 11, 12, 13};            // 
  byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};  // 

  bool resistorsOnSegments = true;                // 
  bool updateWithDelaysIn = true;                 // 
  byte hardwareConfig = COMMON_CATHODE;           // 
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);   //
  sevseg.setBrightness(200);                      // -100 to 0 and quite dim, 100 to 200 brighter but not much diff bewteen 100 and 200

  Wire.begin();                                   //
  RTC.begin();                                    //
  if (! RTC.isrunning()) {RTC.adjust(DateTime(__DATE__, __TIME__));}                      //
  disp.begin(0x70);                               //
}

void loop() 
{  
  sevseg.setNumber(getDecimalTime(),2);           //
  sevseg.refreshDisplay();                        //
}

int getDecimalTime()                              // 
{
  DateTime now = RTC.now();                       // 
  
  if (now.hour()<12) {
    int decimalTime = now.hour() * 100 + now.minute();
  }
  
  else if (now.hour()=12) {
    int decimalTime = 1200 + now.minute();
  }
  
  else int decimalTime = (now.hour()-12) * 100 + now.minute();    //Formats time as HH:MM
  
  
  return decimalTime;                             // 
}

The error…

Using library Adafruit_GFX_Library at version 1.10.2 in folder: /Users/tonyperry/Documents/Arduino/libraries/Adafruit_GFX_Library

Using library RTClib at version 1.12.4 in folder: /Users/tonyperry/Documents/Arduino/libraries/RTClib

Using library Adafruit_BusIO at version 1.6.0 in folder: /Users/tonyperry/Documents/Arduino/libraries/Adafruit_BusIO

Using library SPI at version 1.0 in folder: /Users/tonyperry/Library/Arduino15/packages/arduino/hardware/avr/1.8.3/libraries/SPI

exit status 1

lvalue required as left operand of assignment

Please read these reference pages to understand the difference between the assignment operator and the comparison operator:

else if (now.hour()=12) {

you have to compare, not assign.

Use == instead please

int decimalTime = 1200 + now.minute(); It’s going out of scope very soon.

Geez. I do that every now and then. I just have a hard time seeing it. Still quite new to coding. Thanks all.

tperry724:
Geez. I do that every now and then. I just have a hard time seeing it. Still quite new to coding. Thanks all.

Set your compiler warning level to "all" in the IDE. It will see it.

TheMemberFormerlyKnownAsAWOL:

int decimalTime = 1200 + now.minute();

It's going out of scope very soon.

Hey TPerry. AWOL is right here. How long should your application run? int boundary is "only" 32767. So after almost 23 days, you are out of scope. Please consider this, according to your application :slight_smile: (considering, you are probably using an Atmega based Arduino)

dr-o:
Hey TPerry. AWOL is right here. How long should your application run? int boundary is "only" 32767. So after almost 23 days, you are out of scope. Please consider this, according to your application :slight_smile: (considering, you are probably using an Atmega based Arduino)

But you are not right about the same thing. AWOL is not referring to the integer overflow. Scope and overflow are not the same thing. You made a nice catch, but it's not the only problem, here it is both scope and overflow that are wrong.

aarg:
But you are not right about the same thing. AWOL is not referring to the integer overflow. Scope and overflow are not the same thing. You made a nice catch, but it's not the only problem, here it is both scope and overflow that are wrong.

Oh yes you are totally correct. I didn't checked for the context of this variable. Yes sure, this variable is not usable anywhere else. ^^