Hello everyone,
I’m trying to send messages longer than 128 pixels from terminal widget to 0.96" OLED and have the entire message scroll across the screen. OLED is connected to Wemos D1 mini.
I’m having trouble compiling this code as I don’t know how to properly define message as param.asStr() on V1. I’m not a coder, all this is copy/paste from other projects people have done. Anyone has any ideas?
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define BLYNK_MAX_SENDBYTES 256 // Default is 128
bool mssg;
char message;
int x, minX;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "my token";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "my ssid";
char pass[] = "my password";
// Attach virtual serial terminal to Virtual Pin V1
WidgetTerminal terminal(V1);
BLYNK_WRITE(V1)
{
if (String("text") == param.asStr())//Initiate OLED transfer
{
display.clearDisplay();
terminal.println(F("Enter Message"));
mssg=true;
terminal.flush();
}
if(mssg==true&&(String("text") != param.asStr()) )//Prints To OLED
{
message = param.asStr();
display.clearDisplay();
//x=x-2; // scroll speed, make more positive to slow down the scroll
//if(x < minX) x= display.width();
display.setCursor(0,32);
display.print(param.asString());
display.display();
mssg=false;
}
if(--x < minX) x = display.width();
}
void setup()
{
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setTextWrap(false);
//display.startscrollleft(0x00, 0x0F);
x = display.width();
minX = -12 * strlen(message); // 12 = 6 pixels/character * text size 2
Blynk.begin(auth, ssid, pass);
// You can also specify server;
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Clear the terminal content
terminal.clear();
// This will print Blynk Software version to the Terminal Widget when
// your hardware gets connected to Blynk Server
terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
terminal.println(F("-------------"));
terminal.println(F("Type your command>"));
terminal.flush();
}
void loop()
{
Blynk.run();
}