Trying to switch between two sizes of text Arduino IOT cloud messenger on OLED

  • Thread starter Deleted member 750607
  • Start date

Thread Starter

Deleted member 750607

Joined Dec 31, 1969
0
I'm not sure why this is happening, but I can only use my widget to make the text bigger...not smaller. im unable to switch from size 2 text to size 1 text, but I can do it vice versa (switch size 1 to 2)...I set up an if/else statement at the end of the code that I thought would serve this purpose, but its not working.

I can make it smaller again, but only when I send a new message via serial monitor or the messenger in the Arduino IOT cloud dashboard app

maybe someone can help?

arduino MKR WiFi 1010, Arduino IOT Cloud/dashboard/widgets, 0.96 inch OLED display, also there's an LED function thrown in there, but you can ignore that part

Screen Shot 2021-06-11 at 3.06.18 PM.png

Code:
/*
  Sketch generated by the Arduino IoT Cloud Thing "Instant Messenger"
  https://create.arduino.cc/cloud/things/6fa0b6d2-8bac-475e-aff6-0cc7836e7cab

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  String message;
  CloudSwitch textSize;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

#include <Adafruit_SSD1306.h>
#include <splash.h>
#include <Adafruit_GrayOLED.h>
#include <gfxfont.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <SPI.h>
#include <Wire.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

const unsigned int MAX_MESSAGE_LENGTH = 100;
const int LEDpin = A6;
const bool TextSize = 1;


void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
*/
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();


Serial.begin (9600);

display.begin(SSD1306_SWITCHCAPVCC, 0X3C);
display.clearDisplay ();

pinMode (LEDpin, OUTPUT);

}

void loop() {
  ArduinoCloud.update();
  // Your code here


//Check to see if anything is available in the serial receive buffer
while (Serial.available() > 0)
{
   //Create a place to hold the incoming message
   static char message[MAX_MESSAGE_LENGTH];
   static unsigned int message_pos = 0;

   //Read the next available byte in the serial receive buffer
   char inByte = Serial.read();

   //Message coming in (check not terminating character) and guard for over message size
   if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) )
   {
     //Add the incoming byte to our message
     message[message_pos] = inByte;
     message_pos++;
   }
   //Full message received...
   else
   {
     //Add null character to string
     message[message_pos] = '\0';

     //Print the message (or do other things)
     Serial.println(message);

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println(message);
display.display();
display.clearDisplay ();

digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);
digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);
digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);
digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);


     //Reset for the next message
     message_pos = 0;
   }
}
}

// "who's a good boy?" voice command for robot dog


void onMessageChange() {
  // Do somethingSerial.println(message);

display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println(message);
display.display();
display.clearDisplay ();

  digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);
digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);
digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);
digitalWrite (LEDpin, HIGH);
delay (500);
digitalWrite (LEDpin, LOW);
delay (500);

}


void onTextSizeChange()
{
  // Do something

  if (TextSize == 2)
{
  display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println(message);
display.display();
display.clearDisplay ();
}

  else
{
  display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println(message);
display.display();
display.clearDisplay ();
}
}
 
Last edited by a moderator:

click_here

Joined Sep 22, 2020
548
Why are you clearing the screen straight after writing to it?
Code:
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.println(message);
display.display();
display.clearDisplay(); /////// Here ///////
 
Top