if statement help/ with interrupt pin

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 :slight_smile:
Let me know if you need more info !!

Thank you ,
Joe

#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();
#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
// Programmer: Joseph __Vitale
// 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

OPs error

Dellyjoe:
Seems to me that the error is coming from me using the same variable in the while loop.

Thank you for the post Larryd but im not sure what OP means?

OP = Original Poster i.e. that's you

You had a link to this image but it appears that you have now deleted.

#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()
{
    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.sendBuffer();
    delay(500); // Needs to change, I can't have my timer get deplayed because I want to change the time... Think about?
} //end void OLEDflag

int clocktimerset()
{
    while (digitalRead(0) == HIGH)
    {
        OLEDflag();
    }
    return (0);
}

Fixed it !, I knew this was an easy thing, sorry for the post, just needed a little bit longer

Great!

You should tell us what fixed the problem.

larryd:
Great!

You should tell us what fixed the problem.

#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

Will, I no longer have the same variable defined to two different things.

I now need to figure out how to send the updated pot value to main code after exiting the while loop.

Thanks for all the help larryd !!

I now need to figure out how to send the updated pot value to main code after exiting the while loop.

You can't do that. You can't push data. All you can do is make the value available for other code to pull.

        Potentiometer Potentiometer1;           // why should I use a different Object here ? is it because it is a saporate .cpp file?

Different from what?

int clocktimerset(int pv)
{
// snip happened
} //end void clocktimerset

Useless comments need to be accurate useless comments.

        clocktimerset(Potentiometer1.getpot()); // playing around with how I will change the timer va

You are not getting a pot from the ridiculously-long-named object. You are getting a value.

PaulS:

        clocktimerset(Potentiometer1.getpot()); // playing around with how I will change the timer va

You are not getting a pot from the ridiculously-long-named object. You are getting a value.

Good Evening PaulS thank you for taking the time to look through my problem. I fixed the issue and I have fixed my commit error

thanks for looking out, now onto the next problem !!

Joe