Passing/updating variable?

I am currently trying to create a couple variables so i can call/update them. Im doing this as i have a true or false check on 4 conditions in my code. each condition turns itself to true while also setting the other 3 to false. but on to my problem. I want the wav file and volume level to be controlled through this variable.
I currently specified the following
void p_play_day (char p_file, int p_volume)
and here are the definitions
char p_file = ‘a’;
int p_volume = 3;
these are the values i want to change and then have my p_play_day function use those updated variables…am I making sense? I ask because my code keeps getting into a reboot cycle and the decoded information says these are pointing to a 0x00000 or NULL value.
Thank you for your help it is much appreciated.

Good Morning

Could you please share with us related pieces of your code?

Thank you.

Sure! Here is the variable list

bool p_alarm_high = false;
bool p_alarm_low = false;
bool p_warn_high = false;
bool p_warn_low = false;
bool p_error = false;
bool p_no_readings = false;
bool p_in_range = false;
char p_file = 'a';
int p_volume = 3;
int p_mute = 0;
char p_repeat_voice_update = 1800000;
char p_repeat_voice_conditions = 900000;
char p_check_for_state_change = 3000;
char p_audio_wait_5_seconds = 5000;
char p_audio_wait_10_seconds = 10000;
char p_audio_wait_20_seconds = 20000;
char p_audio_wait_1_minute = 60000;
char p_audio_wait_5_minutes = 300000;

Here is an example of the condition code

if((ns->sensSgv<=cfg.snd_warning) && (ns->sensSgv>=0.1)) {
      // yellow warning state
      // M5.Lcd.fillRect(110, 220, 100, 20, TFT_YELLOW);
      Serial.println("WARNING LOW");
      M5.Lcd.fillRect(0, 220, 320, 20, TFT_YELLOW);
      M5.Lcd.setTextColor(TFT_BLACK, TFT_YELLOW);
      int stw=M5.Lcd.textWidth(tmpStr);
      M5.Lcd.drawString(tmpStr, 159-stw/2, 220, GFXFF);
      if( (alarmDifSec>cfg.alarm_repeat*60) && (snoozeRemaining<=0) ) {
        p_file = 'c';
p_warn_low = true;
        lastAlarmTime = mktime(&timeinfo);

i dont think im passing the variable values correctly?

ok im feeling dumb…
p_file = ‘i’;

p_volume = 3;
Isn’t this correct? i put iot in my setup() but the restart loop still happens and decoding it points to null

Where does your code use any of these variables?

p_file = ‘i’;

p_volume = 3; ? They are used on each condition. i have 4 conditions. warn high warn low alarm high and alarm low. each have their own sound files. i want a global varialbe set so another function (an action taken after 15 minutes) knows what file to play based on the active condition…hope that makes sense.

OK I’m an idiot hehe

It’s var1 = xyz

That can’t possibly work – a char is a datatype that is 1 byte long, and signed (by default), so the value range is -127 to +128. It can’t hold values beyond that, they will be clipped within the 8-bit range. p_repeat_voice_update will actually be holding the value 64. Not what you want and leads to unexpected logic errors.

You need to use a larger data type that can hold this value. E.g., a uint16_t can go up to 65535 (so it’s e.g. not enough to even hold the first value), a uint32_t (= unsigned int for 32-bit based platforms like an ESP32, unisgned long for 8-bit based platforms like an AVR) goes from 0 to 4,294,967,294. So you should be using that.

See C# | Data Types - GeeksforGeeks for a table of datatypes and their value rangues. Beware that even things int mean different things on different microcontroller architectures per above – best to use Fixed width integer types (since C99) -

Your right it doesn’t work. The device goes into a reboot cycle however when I opened the same project in arduino ide it wouldn’t let me build unlike vscode…

@maxgerhardt , you’re right. But should that be the reason for crashing? I guess it’s most likely to cause wrong value assignment.

There might be some infinite recursive function call.

Anyway, @shaw.isabel.krystal , you must change it, according to Max’s instructions:

@shaw.isabel.krystal , you mention:

So far, I can’t see where you’re passing the values and which function receives them.

Probably, you’ll want to pass variables as references, using pointers. That’d allow your function to receive the addresses where these variables are located and manipulate their values directly.

The way I guess you’re trying to do

will provide your function “p_play_day” just a copy of them and will preserve their original values.

Regards, Ciro.