if statement and display print question

although there is alot happening here, question is simple, to make an if statement for pinStatus value to display a bitmap, this just simply displays the bitmap in all circumstances, i am able to display.print the pinStatus value in my other simpler code but would rather have it call up a bitmap when pinStatus = 1
forgive my super messy coding, i am new :slight_smile:

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

int pinStatus = 0; initial value of Status

// Bitmap of splashcreen
const unsigned char myBitmap [] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x67, 0xfe, 0x00, 0x03, 0xfe, 0x67, 0xc0, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x67, 0xf0, 0x80, 0x78, 0xfe, 0x67, 0xf0, 0x00, 0x1f, 0xff, 0x81, 0xe0, 0x00, 0x00, 
  0x00, 0x00, 0x7f, 0xc7, 0xc0, 0x7f, 0x3f, 0xe0, 0xf8, 0x00, 0x7e, 0x03, 0xe0, 0xf0, 0x00, 0x00, 
  0x00, 0x00, 0x7f, 0x9f, 0xe0, 0x7f, 0xcf, 0xe0, 0x3f, 0x01, 0xf0, 0x00, 0xf8, 0x78, 0x00, 0x00, 
  0x00, 0x00, 0x7e, 0x7f, 0xf0, 0x7f, 0xc7, 0xe0, 0x0f, 0xff, 0xe0, 0x00, 0x7f, 0xfe, 0x00, 0x00, 
  0x00, 0x00, 0x7c, 0xff, 0xf0, 0x7f, 0xc3, 0xe0, 0x03, 0xff, 0x00, 0x00, 0x1f, 0xfe, 0x00, 0x00, 
  0x00, 0x00, 0x78, 0x1f, 0xf8, 0x7f, 0x81, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 
  0x00, 0x00, 0x78, 0x07, 0xfc, 0x7f, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 
  0x00, 0x00, 0x70, 0x01, 0xfc, 0x7e, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 
  0x00, 0x00, 0x60, 0x00, 0x60, 0x7c, 0x03, 0x60, 0x38, 0x00, 0x00, 0x1f, 0xe0, 0x80, 0x00, 0x00, 
  0x00, 0x00, 0x60, 0x00, 0x1f, 0x98, 0x0f, 0x20, 0x3f, 0x00, 0x00, 0x7f, 0xf8, 0x0e, 0x00, 0x00, 
  0x00, 0x00, 0x6f, 0xff, 0x3f, 0xe0, 0x3f, 0x20, 0x1f, 0xc0, 0x01, 0xf8, 0x7e, 0x0f, 0x00, 0x00, 
  0x00, 0x00, 0x6f, 0xff, 0x7f, 0xe1, 0xff, 0xa0, 0x03, 0xe0, 0x07, 0xc0, 0x0f, 0x87, 0xc0, 0x00, 
  0x00, 0x00, 0x4f, 0xff, 0x7f, 0xf7, 0xff, 0xa0, 0x00, 0xfe, 0x7f, 0x00, 0x07, 0xf7, 0xe0, 0x00, 
  0x00, 0x00, 0x4f, 0xfe, 0x7f, 0xf7, 0xff, 0xa0, 0x00, 0x3f, 0xfc, 0x00, 0x01, 0xff, 0xf0, 0x00, 
  0x00, 0x00, 0x6f, 0xf0, 0x7f, 0xef, 0xff, 0xa0, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x3f, 0xe0, 0x00, 
  0x00, 0x00, 0x6f, 0x80, 0xbf, 0xc7, 0xff, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 
  0x00, 0x00, 0x66, 0x01, 0xcf, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 
  0x00, 0x00, 0x74, 0x03, 0xe0, 0xf0, 0x00, 0x62, 0x00, 0x00, 0x00, 0x70, 0x00, 0x0e, 0x00, 0x00, 
  0x00, 0x00, 0x70, 0x07, 0xe3, 0xfc, 0x00, 0xe7, 0xc0, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x78, 0x0f, 0xe1, 0xff, 0x00, 0xe3, 0xf0, 0x00, 0x1f, 0xff, 0xc0, 0xe0, 0x00, 0x00, 
  0x00, 0x00, 0x7c, 0x1f, 0xe0, 0xff, 0xe1, 0xe0, 0x7c, 0x00, 0x7e, 0x03, 0xf0, 0xf8, 0x00, 0x00, 
  0x00, 0x00, 0x7e, 0x1f, 0xe0, 0xff, 0xf3, 0xe0, 0x1f, 0x01, 0xf8, 0x00, 0xfc, 0x7c, 0x00, 0x00, 
  0x00, 0x00, 0x7f, 0x3f, 0xe0, 0x7f, 0xe7, 0xe0, 0x07, 0xff, 0xe0, 0x00, 0x3f, 0xfe, 0x00, 0x00, 
  0x00, 0x00, 0x7f, 0x9f, 0xe0, 0x3f, 0x9f, 0xe0, 0x01, 0xff, 0x00, 0x00, 0x0f, 0xfe, 0x00, 0x00, 
  0x00, 0x00, 0x7f, 0xe3, 0xe0, 0x1e, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 
  0x00, 0x00, 0x67, 0xf8, 0x60, 0x01, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 
  0x00, 0x00, 0x67, 0xff, 0x00, 0x0f, 0xfe, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 
  0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "06720"; //NRF Address

unsigned long lastRecvTime = 0; //Used for latency check

struct data{
  float temper; first piece of data to receive
  int pinStatus; second piece of data to receive
};

data receive_data;

void reset_the_Data() //Set default values
{
   receive_data.temper=0;
   receive_data.pinStatus=0;
}

void receive_the_data() //Read
{
 while ( radio.available() ) {
    radio.read(&receive_data, sizeof(data));
    lastRecvTime = millis();
  }
}

void setup() {

   
  
  radio.begin();
  radio.setAutoAck(false);
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.setDataRate(RF24_250KBPS);
  radio.startListening();

   Wire.begin();
   display.begin(SSD1306_SWITCHCAPVCC, 0x3D);// initialize with the I2C addr 0x3C (for the 128x64)(initializing the display)
  
}
void loop() {

  
  receive_the_data();
  int unsigned long now = millis();
  if ( now - lastRecvTime > 1000 ) {  //Check for latency
    reset_the_Data();
  }
 
  if (pinStatus = 0);{
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2); 
  display.setCursor(35,10);
  display.print(receive_data.temper,1);
  display.setCursor(90,10);
  display.print("C");
  display.setCursor(0,10);
  display.print(receive_data.pinStatus); //displays pinStatus ,, should 0
  display.display();
 }
   else if (pinStatus =1);   {
 display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2); 
  display.setCursor(35,10);
  display.print(receive_data.temper,1);
  display.setCursor(90,10);
  display.print("C");
  display.drawBitmap(0, 0, myBitmap, 128, 32, WHITE); // supposed to display bitmap
  display.display();
 }
}
if (pinStatus = 0);{

== for comparison, lose the semicolon.

if (pinStatus =1); Ditto.
Or, more simply, just "else"

i tried that and it simply ignores the disply bitmap protion,, i really dont understand,

if (pinStatus == 1) {
  display.clearDisplay();
  display.drawBitmap(0, 32, myBitmap, 128, 32, WHITE);
  display.setTextColor(WHITE);
  display.setTextSize(2); 
  display.setCursor(35,10);
  display.print(receive_data.temper,1);
  display.setCursor(90,10);
  display.print("C");  
  display.display();
 }
 
  if (pinStatus == 0) {
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2); 
  display.setCursor(35,10);
  display.print(receive_data.temper,1);
  display.setCursor(90,10);
  display.print("C"); 
  display.display();
 }

Because you set pinStatus to zero?

How should I declare pinStatus then?
Can I simply do
int pinStatus ?
I appreciate your help.

You're able to compile this?

struct data{
  float temper; first piece of data to receive
  int pinStatus; second piece of data to receive
};

-jim lee

You never set pinStatus to anything but 0. Are you confusing that with the pinStatus in your receive data? Those are two different things.

But then again. In another script I wrote it simply displays current status being read and it works
display.print(pinStatus,1); works fine.

I have since changed it’s name to be less confusing.
I am able to compile it np and it works for displaying the status numerically on my OLED screen but when I decided to have a bitmap called up when value was 1 it won’t work.

Let me ask in a different way. Did you mean to test receive_data.pinStatus == 1 rather than pinStatus == 1. Again pinStatus never changes from 0 in your code.

Yes. pinStatus is the status being received from another Arduino’s input. I know it’s confusing. Imagine me, lol.
Should I be declaring at all the status as it is a piece of received? Should I do rather
if ( receive_data.pinStatus == 1 ) {. ??

Just wondering why the word “pinStatus” works for
display.print(pinStatus,1); but not
display.drawBitmap

anthonyuno:
Yes. pinStatus is the status being received from another Arduino’s input. I know it’s confusing. Imagine me, lol.
Should I be declaring at all the status as it is a piece of received? Should I do rather
if ( receive_data.pinStatus == 1 ) {. ??

Should it? If you are testing the data actually received then yes it should be. Otherwise you are testing a variable pinStatus that NEVER changes.

Just wondering why the word “pinStatus” works for
display.print(pinStatus,1); but not
display.drawBitmap

I never saw where you did that anywhere in the code you posted. If you did that in a different sketch then I would need to see that sketch to tell you.

thanks for the help, solved, code below working well, i just didnt see

void loop() {
  
  receive_the_data();
    int unsigned long now = millis();
    if ( now - lastRecvTime > 1000 ) {  //Check for latency
    reset_the_Data();
  }
 
  if (receive_data.outstat == 1) {   // Display bitmap when oustat = 1 & update temp
  display.clearDisplay();
  display.drawBitmap(0, 32, myBitmap, 128, 32, WHITE); // calls bitmap file from above
  display.setTextColor(WHITE);
  display.setTextSize(2); 
  display.setCursor(35,10);
  display.print(receive_data.temper,1);
  display.setCursor(90,10);
  display.print("C");  
  display.display();
 }
 
  if (receive_data.outstat == 0) {  // update temp only
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2); 
  display.setCursor(35,10);
  display.print(receive_data.temper,1);
  display.setCursor(90,10);
  display.print("C"); 
  display.display();
 }

the issue

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.