struct useage

Good Evening everyone thank you for taking the time out of the day to look into this problem.

I first want to say I have looked at a lot of example and starting to get confused.

I have this header file.

struct timeralarmpara
{
    int timer; // This is a member of the struct
    int clockset;

}; // ; is needed when using a struct

I then use it in my OLED_RTC.cpp file.
With this code I want to map potvalue 1 to timerpot and potvalue2 to alarmpot

void OLED::sendvaluestimer(int potvalue1, int potvalue2)
{
    u8g2.clearBuffer();                 // clear the internal memory
    u8g2.setFont(u8g2_font_helvB12_te); // choose a suitable font
    u8g2.clearBuffer();                 // clears current display
    u8g2.drawStr(35, 25, "Vaules");
    u8g2.drawStr(35, 45, "Saved!");
    u8g2.sendBuffer();

    timeralarmpara timerpot;
    timerpot.timer = potvalue1;
    timeralarmpara alarmpot;
    alarmpot.clockset = potvalue2;

    delay(1000);
}

This will then get passed into

int Timer12hour::timer()

So my first question is do I have my OLED_RTC.cpp file set up to have potvalue1 and potvalue2 equal to timerpot and alarmpot respectfully. If so great, I don't get any build errors so I believe this is right.

Now if I want to pass these two values into int Timer12hour::timer() would it have to look like

int Timer12hour::timer(timeralarmpara, int timer, int clockset)

and then I can set timerpot and alarmpot to whatever I need?

Rewind a little. What are you building? An alarm clock? Something else?

A function with a name like sendvaluestimer() should take a timer value and send it somewhere. Maybe that somewhere is the OLED screen but it seems like you are doing a lot of different things in that function that aren't sending a value anywhere.

MorganS:
Rewind a little. What are you building? An alarm clock? Something else?

A function with a name like sendvaluestimer() should take a timer value and send it somewhere. Maybe that somewhere is the OLED screen but it seems like you are doing a lot of different things in that function that aren't sending a value anywhere.

Hey MorganS,

For me to activate I have to hit a button for the interrupt

  attachInterrupt(digitalPinToInterrupt(1), SendValuesflag, HIGH); // Setting interrupt pin D1

which will then flag to run.

void SendValuesflag() // Button Flag
{
    while (digitalRead(1) == HIGH && digitalRead(0) == HIGH)
    {
        OLED OLED2;
        Potentiometer Potentiometer2;
        OLED2.sendvaluestimer(Potentiometer2.getpot1(), Potentiometer2.getpot2());
    }

This will then call

void OLED::sendvaluestimer(int potvalue1, int potvalue2)
{
    u8g2.clearBuffer();                 // clear the internal memory
    u8g2.setFont(u8g2_font_helvB12_te); // choose a suitable font
    u8g2.clearBuffer();                 // clears current display
    u8g2.drawStr(35, 25, "Vaules");
    u8g2.drawStr(35, 45, "Saved!");
    u8g2.sendBuffer();

    timeralarmpara timerpot;
    timerpot.timer = potvalue1;
    timeralarmpara alarmpot;
    alarmpot.clockset = potvalue2;

    delay(1000);
}

So when I hit the button I want to send the updated pot values to the timer function to change the setpoint on the alarm and on the length of the timer.

Does this help?

Ok. So it's a secret.

MorganS:
Ok. So it's a secret.

I don't mean to be maybe I'm just not explaining myself correctly

What is it you are building? What is the goal?

Without details, the only thing I can see is that you need to learn about how C++ does variable scoping.

Where a variable is declared determines it's visibility (where it's able to be used) and it's lifetime (how long it continues to exist).

void OLED::sendvaluestimer(int potvalue1, int potvalue2)
{
    u8g2.clearBuffer();                 // clear the internal memory
    u8g2.setFont(u8g2_font_helvB12_te); // choose a suitable font
    u8g2.clearBuffer();                 // clears current display
    u8g2.drawStr(35, 25, "Vaules");
    u8g2.drawStr(35, 45, "Saved!");
    u8g2.sendBuffer();

    timeralarmpara timerpot;
    timerpot.timer = potvalue1;
    timeralarmpara alarmpot;
    alarmpot.clockset = potvalue2;

    delay(1000);
}

Here, declaring timerpot and alarmpot inside the function like this means that those variables only exist inside this function. They can only be used in this function, and they are destroyed immediately after the function finishes. If you intend for these values to be used elsewhere or to persist after the function is finished, you need to declare them somewhere else.