if statement question, multiple definitions of a variable

Status
Not open for further replies.

Dellyjoe

Active member
Good Evening everyone, I have been looking at this issue for a long time. I feel it is something simple but I can't seem to figure this one out.

my goal here is to use a interrupt to clear my OLED screen. It will be a switch in the long run and when the switch is high I would like to clear the display and use a pot to set the current time and make a timer.

I got this to work with just one function OLEDflag. Which had the code that clocktimerset has now.

I was told you want to keep the interrupt code short and simple. THis is why i'm just making a if statement to change the state which will feed info another loop to run the code.

The error I have is a warring, Multiple definitions of 'OLEDclockset' not sure how to fix this.

i'm now here so go easy on me :)
Let me know if you need more info !!

Thank you ,
Joe

Code:
#include <U8g2lib.h> // OLED
#ifdef U8X8_HAVE_HW_I2C
#endif
#include <Wire.h>

class OLED
{
private:
public:
  void intdisplay();
  void OLEDdraw(int potvalue, int currenttimer, String RelayString);
}; // end class OLED

int OLEDclockset;
void OLEDflag(); //Not in a class Because this is used for an interrupt function it needs to be global
int clocktimerset();

Code:
#include <OLED.h>
#include <Arduino.h>
#include <wire.h>

//******************************************Declare*****************************//
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
//******************************************Setup*****************************//
void OLED::intdisplay()
{
    u8g2.begin(); // Start the Library code for the OLED
} // end void OLED

//*****************************************Functions**************************//
void OLED::OLEDdraw(int potvalue, int currenttimer, String RelayString)
{
    u8g2.clearBuffer();                 // clear the internal memory
    u8g2.setFlipMode(1);                // Flips display 180 (1) = True
    u8g2.setFont(u8g2_font_koleeko_tr); // choose a suitable font
    u8g2.drawStr(0, 10, "Pot Value:");
    u8g2.setCursor(70, 10); // set cursor location
    u8g2.print(potvalue);   // print at current cursor location
    u8g2.drawStr(85, 10, " % ");
    u8g2.drawStr(0, 25, "Relay State:");
    u8g2.setCursor(85, 25); // set cursor location
    u8g2.print(RelayString);
    u8g2.drawStr(0, 50, "Runing Timer(s):");
    u8g2.setCursor(0, 60);    // set cursor location
    u8g2.print(currenttimer); // print at current cursor location
    u8g2.sendBuffer();        // transfer internal memory to the display
} // end void OLED

void OLEDflag()
{
    if (HIGH)
    {
        OLEDclockset = 1;
    }
    else
    {
        OLEDclockset = 0;
    }
} // end void OLEDflag

int clocktimerset()
{
    while (OLEDclockset == 1)
    {
        u8g2.clearBuffer(); // clears current display
        u8g2.drawStr(0, 10, "Set Clock:");
        u8g2.drawStr(0, 25, "Set Timer");
        u8g2.sendBuffer();
        delay(500); // Needs to change, I can't have my timer get deplayed because I want to change the time... Think about?
    }
    return (0);
} //end clocktimerset

Following code show main.cpp
Code:
// Start Date: 03/15/19
// Completion Date: n/A
// Discription: This project will be able to display current time, set relay on/off
// time, the use of pots and buttons to navigate around the OLED display and set
// time to use for a timer.

#include <potentiometer.h>
#include <OLED.h>
#include <rtc.h>
#include <timer.h>
#include <wire.h>          // i/O pins
#include <avr/io.h>        // interrupt
#include <avr/interrupt.h> // interrupt
//******************************************Declare*****************************//
Timer12hour Timer12hour0; // Setting Object 0 for Timer12hour0
OLED OLED0;               // Setting Object 0 for OLED
//******************************************Setup*****************************//
void setup()
{
  Timer12hour0.setuptimer();
  OLED0.intdisplay();
  intrtc(); // get current time, set Serial
  pinMode(0, INPUT);
  attachInterrupt(digitalPinToInterrupt(0), OLEDflag, HIGH); // Setting interrupt pin D0
} //end setup
//******************************************Main******************************//
void loop()
{
  displaytime();
  Timer12hour0.timer();
  Potentiometer Potentiometer0; // Updated Pot Value
  OLED0.OLEDdraw(Potentiometer0.getpot(), Timer12hour0.timer(), Timer12hour0.getRelayString());
} // end void loop
 
Last edited:
Code:
#include <OLED.h>
#include <Potentiometer.h>
#include <wire.h>

//******************************************Declare*****************************//
U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
//******************************************Setup*****************************//
void OLED::intdisplay()
{
    u8g2.begin(); // Start the Library code for the OLED
} // end void OLED

//*****************************************Functions**************************//
void OLED::OLEDdraw(int potvalue, int currenttimer, String RelayString)
{
    u8g2.clearBuffer();                 // clear the internal memory
    u8g2.setFlipMode(1);                // Flips display 180 (1) = True
    u8g2.setFont(u8g2_font_koleeko_tr); // choose a suitable font
    u8g2.drawStr(0, 10, "Pot Value:");
    u8g2.setCursor(70, 10); // set cursor location
    u8g2.print(potvalue);   // print at current cursor location
    u8g2.drawStr(85, 10, " % ");
    u8g2.drawStr(0, 25, "Relay State:");
    u8g2.setCursor(85, 25); // set cursor location
    u8g2.print(RelayString);
    u8g2.drawStr(0, 50, "Runing Timer(s):");
    u8g2.setCursor(0, 60);    // set cursor location
    u8g2.print(currenttimer); // print at current cursor location
    u8g2.sendBuffer();        // transfer internal memory to the display
} // end void OLED

void OLEDflag()
{
    while (digitalRead(0) == HIGH)
    {
        Potentiometer Potentiometer1;           // why should I use a different Object here ? is it because it is a saporate .cpp file?
        clocktimerset(Potentiometer1.getpot()); // playing around with how I will change the timer vaules
    }
} // end void OLEDflag

int clocktimerset(int pv)
{
    u8g2.clearBuffer(); // clears current display
    u8g2.drawStr(0, 10, "Set Clock:");
    u8g2.drawStr(0, 25, "Set Timer");
    u8g2.setCursor(85, 25); // set cursor location
    u8g2.print(pv);
    u8g2.sendBuffer();
    delay(500); // Needs to change, I can't have my timer get delayed because I want to change the time... Think about?
    return (0);
} //end void clocktimerset

Sorry for the post I ended up fixing it, I ended up fixing it.
 
Last edited:
Status
Not open for further replies.
Back
Top