Trouble updating value on Featherwing OLED


#1

Hello,

I’m hoping someone can help me out with a coding issue. I feel like the solution is right in front of me but i can’t seem to figure it out. As background, I have 1 Argon device and 2 xenon devices. The Argon and one of the Xenons are being used to collect temperature data and publishing them to the cloud. The other Xenon device subscribes to both device’s data and displays it on the Featherwing OLED attached to it.

I want to be able to display one device when button A on the OLED is push and the other when button B is pushed. And I have the backbones of that in place now, however the data won’t update until the button is pressed again. I am trying to see if there is a way to have the data continuously update within the button pressed if statement.

#include "oled-wing-adafruit.h"

OledWingAdafruit display;

double Xenon1_num;
double Argon_num;

void setup() {
	display.setup();

	display.clearDisplay();
	display.display();
	Particle.subscribe("Xenon1", Xenon_Event);
	Particle.subscribe("Argon", Argon_Event);
}

void loop() {
	display.loop();

	if (display.pressedA()) {

		display.clearDisplay();

		display.setTextSize(1);
		display.setTextColor(WHITE);
		display.setCursor(0,0);
		display.loop();

		display.println("Xenon1 Temperature: ");
		display.print(Xenon1_num);
		display.print(" degrees F");
		display.display();

	
	}
	
	if (display.pressedB()) {

		display.clearDisplay();

		display.setTextSize(1);
		display.setTextColor(WHITE);
		display.setCursor(0,0);
		display.println("Argon Temperature: ");
		display.print(Argon_num);
		display.print(" degrees F");
		display.display();
	}

	if (display.pressedC()) {
	}
}


void Xenon_Event(const char *event, const char *data) {
	
	    //Serial.println(data);     //uncomment to check serial monitor 
	    Xenon1_num = atof(data);    //Convert to double to truncate decimal places
}

void Argon_Event(const char *event, const char *data) {
    
	    //Serial.println(data);     //uncomment to check serial monitor 
	    Argon_num = atof(data);    //Convert to double to truncate decimal places    
}

#2

You don’t want to display the data when the respective button is pressed, but you rather want to set a flag which data should be displayed continously.

For that you’d break out the common stuff and do that unconditionally and the individual/device specific stuff would be done respective to the current state of the flag.