Eccomi,
ci siamo quasi, ho 2 problemini.
-
inserendo la stringa nuova, questa viene sovrapposta al testo precedente, come se fosse sommata a quella precedente.
-
asynctelegram2 forse ha un baco sulla funzione myBot.endQuery.
Se utilizzo la tastiera inine, va in crash arduino r4 e sulla seriale ricevo questo:
Callback query message received: lightON
Set light ON
Firmware name: "C:\Users\User\AppData\Local\Temp\arduino\sketches\CC2ED7BC414D2C5392B26DA1181CFD21/SineWave.ino", compiled on: Jul 22 2023
Fault on interrupt or bare metal(no OS) environment
Error: Main stack(20007a08) was overflow
===== Thread stack information =====
addr: 20007b00 data: 20007c08
addr: 20007b04 data: ffffffe9
addr: 20007b08 data: 20003764
addr: 20007b0c data: 00016122
addr: 20007b10 data: 00000073
====================================
Bus fault is caused by precise data access violation
The bus fault occurred address is ce0caa77
Credo che asynctelegram2 non sia perfetta oggi per arduino R4..
il codice attuale e' questo:
/*
TLS WiFi Web client
Remeber to update the CA certificates using CertificateUploader sketch
before using this sketch.
*/
#include "WiFiS3.h"
#include "WiFiSSLClient.h"
//#include "IPAddress.h"
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
/*
Name: keyboards.ino
Created: 05/03/2022
Author: Tolentino Cotesta <cotestatnt@yahoo.com>
Description: a more complex example that do:
1) if a "/inline_keyboard" text message is received, show the inline custom keyboard,
if a "/reply_keyboard" text message is received, show the reply custom keyboard,
otherwise reply the sender with "Try /reply_keyboard or /inline_keyboard" message
2) if "LIGHT ON" inline keyboard button is pressed turn on the LED and show a message
3) if "LIGHT OFF" inline keyboard button is pressed, turn off the LED and show a message
4) if "GitHub" inline keyboard button is pressed,
open a browser window with URL "https://github.com/cotestatnt/AsyncTelegram"
*/
#include <AsyncTelegram2.h>
// Timezone definition
#include <time.h>
#define MYTZ "CET-1CEST,M3.5.0,M10.5.0/3"
WiFiSSLClient client;
AsyncTelegram2 myBot(client);
//const char* token = "xxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxx"; // Telegram token
// Check the userid with the help of bot @JsonDumpBot or @getidsbot (work also with groups)
// https://t.me/JsonDumpBot or https://t.me/getidsbot
int64_t userid = 0;
ReplyKeyboard myReplyKbd; // reply keyboard object helper
InlineKeyboard myInlineKbd; // inline keyboard object helper
bool isKeyboardActive; // store if the reply keyboard is shown
#define LIGHT_ON_CALLBACK "lightON" // callback data sent when "LIGHT ON" button is pressed
#define LIGHT_OFF_CALLBACK "lightOFF" // callback data sent when "LIGHT OFF" button is pressed
/*
* Purpose: Display a text message scrolling from right to left
* on the board's 8x12 LED matrix.
* Board: Arduino UNO R4 WiFi
* IDE: 1.8.19 with "Arduino Renesas Boards" version 0.8.5-ea
*
* Usage: Upload to the board and enjoy.
*
* Provides many possibilities for doing things better and more efficiently.
* Parts of this code work because of the way the display works. For instance,
* there is no need to draw black pixels, only white pixels need drawing.
* Naively porting this code to another kind of display will probably not work.
* Buffer overflow protection is probably flawed, so don't count on it.
*
* By: Clemens Valens, Elektor
* Date: 14/6/2023
*/
// Leading spaces ensure starting at the right.
const uint8_t scroll_speed = 50; // milliseconds
const uint16_t ontime = 521; // microseconds. 521 (us) * 96 (pixels) = 50 ms frame rate if all the pixels are on.
static uint8_t scroll = 0; // scroll position.
const uint8_t LED = 1;
//uint8_t banner_text[] = " Pippo Pluto Paperino e poi chissa' ";
uint8_t banner_text[] = " testo ";
// First value is the width of a character in columns. This allows for
// easy tight spacing on the display (TTF kind of thing).
const uint8_t font_5x8[] = {
3, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // space
1, 0b01011111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // !
3, 0b00000011, 0b00000000, 0b00000011, 0b00000000, 0b00000000, // "
5, 0b00010100, 0b00111110, 0b00010100, 0b00111110, 0b00010100, // #
4, 0b00100100, 0b01101010, 0b00101011, 0b00010010, 0b00000000, // $
5, 0b01100011, 0b00010011, 0b00001000, 0b01100100, 0b01100011, // %
5, 0b00110110, 0b01001001, 0b01010110, 0b00100000, 0b01010000, // &
1, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // '
3, 0b00011100, 0b00100010, 0b01000001, 0b00000000, 0b00000000, // (
3, 0b01000001, 0b00100010, 0b00011100, 0b00000000, 0b00000000, // )
5, 0b00101000, 0b00011000, 0b00001110, 0b00011000, 0b00101000, // *
5, 0b00001000, 0b00001000, 0b00111110, 0b00001000, 0b00001000, // +
2, 0b10110000, 0b01110000, 0b00000000, 0b00000000, 0b00000000, // ,
4, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000000, // -
2, 0b01100000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, // .
4, 0b01100000, 0b00011000, 0b00000110, 0b00000001, 0b00000000, // /
4, 0b00111110, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // 0
3, 0b01000010, 0b01111111, 0b01000000, 0b00000000, 0b00000000, // 1
4, 0b01100010, 0b01010001, 0b01001001, 0b01000110, 0b00000000, // 2
4, 0b00100010, 0b01000001, 0b01001001, 0b00110110, 0b00000000, // 3
4, 0b00011000, 0b00010100, 0b00010010, 0b01111111, 0b00000000, // 4
4, 0b00100111, 0b01000101, 0b01000101, 0b00111001, 0b00000000, // 5
4, 0b00111110, 0b01001001, 0b01001001, 0b00110000, 0b00000000, // 6
4, 0b01100001, 0b00010001, 0b00001001, 0b00000111, 0b00000000, // 7
4, 0b00110110, 0b01001001, 0b01001001, 0b00110110, 0b00000000, // 8
4, 0b00000110, 0b01001001, 0b01001001, 0b00111110, 0b00000000, // 9
2, 0b01010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // :
2, 0b10000000, 0b01010000, 0b00000000, 0b00000000, 0b00000000, // ;
3, 0b00010000, 0b00101000, 0b01000100, 0b00000000, 0b00000000, // <
3, 0b00010100, 0b00010100, 0b00010100, 0b00000000, 0b00000000, // =
3, 0b01000100, 0b00101000, 0b00010000, 0b00000000, 0b00000000, // >
4, 0b00000010, 0b01011001, 0b00001001, 0b00000110, 0b00000000, // ?
5, 0b00111110, 0b01001001, 0b01010101, 0b01011101, 0b00001110, // @
4, 0b01111110, 0b00010001, 0b00010001, 0b01111110, 0b00000000, // A
4, 0b01111111, 0b01001001, 0b01001001, 0b00110110, 0b00000000, // B
4, 0b00111110, 0b01000001, 0b01000001, 0b00100010, 0b00000000, // C
4, 0b01111111, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // D
4, 0b01111111, 0b01001001, 0b01001001, 0b01000001, 0b00000000, // E
4, 0b01111111, 0b00001001, 0b00001001, 0b00000001, 0b00000000, // F
4, 0b00111110, 0b01000001, 0b01001001, 0b01111010, 0b00000000, // G
4, 0b01111111, 0b00001000, 0b00001000, 0b01111111, 0b00000000, // H
3, 0b01000001, 0b01111111, 0b01000001, 0b00000000, 0b00000000, // I
4, 0b00110000, 0b01000000, 0b01000001, 0b00111111, 0b00000000, // J
4, 0b01111111, 0b00001000, 0b00010100, 0b01100011, 0b00000000, // K
4, 0b01111111, 0b01000000, 0b01000000, 0b01000000, 0b00000000, // L
5, 0b01111111, 0b00000010, 0b00001100, 0b00000010, 0b01111111, // M
5, 0b01111111, 0b00000100, 0b00001000, 0b00010000, 0b01111111, // N
4, 0b00111110, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // O
4, 0b01111111, 0b00001001, 0b00001001, 0b00000110, 0b00000000, // P
4, 0b00111110, 0b01000001, 0b01000001, 0b10111110, 0b00000000, // Q
4, 0b01111111, 0b00001001, 0b00001001, 0b01110110, 0b00000000, // R
4, 0b01000110, 0b01001001, 0b01001001, 0b00110010, 0b00000000, // S
5, 0b00000001, 0b00000001, 0b01111111, 0b00000001, 0b00000001, // T
4, 0b00111111, 0b01000000, 0b01000000, 0b00111111, 0b00000000, // U
5, 0b00001111, 0b00110000, 0b01000000, 0b00110000, 0b00001111, // V
5, 0b00111111, 0b01000000, 0b00111000, 0b01000000, 0b00111111, // W
5, 0b01100011, 0b00010100, 0b00001000, 0b00010100, 0b01100011, // X
5, 0b00000111, 0b00001000, 0b01110000, 0b00001000, 0b00000111, // Y
4, 0b01100001, 0b01010001, 0b01001001, 0b01000111, 0b00000000, // Z
2, 0b01111111, 0b01000001, 0b00000000, 0b00000000, 0b00000000, // [
4, 0b00000001, 0b00000110, 0b00011000, 0b01100000, 0b00000000, // '\'
2, 0b01000001, 0b01111111, 0b00000000, 0b00000000, 0b00000000, // ]
3, 0b00000010, 0b00000001, 0b00000010, 0b00000000, 0b00000000, // hat
4, 0b01000000, 0b01000000, 0b01000000, 0b01000000, 0b00000000, // _
2, 0b00000001, 0b00000010, 0b00000000, 0b00000000, 0b00000000, // `
4, 0b00100000, 0b01010100, 0b01010100, 0b01111000, 0b00000000, // a
4, 0b01111111, 0b01000100, 0b01000100, 0b00111000, 0b00000000, // b
4, 0b00111000, 0b01000100, 0b01000100, 0b00000000, 0b00000000, // c
4, 0b00111000, 0b01000100, 0b01000100, 0b01111111, 0b00000000, // d
4, 0b00111000, 0b01010100, 0b01010100, 0b00011000, 0b00000000, // e
3, 0b00000100, 0b01111110, 0b00000101, 0b00000000, 0b00000000, // f
4, 0b10011000, 0b10100100, 0b10100100, 0b01111000, 0b00000000, // g
4, 0b01111111, 0b00000100, 0b00000100, 0b01111000, 0b00000000, // h
3, 0b01000100, 0b01111101, 0b01000000, 0b00000000, 0b00000000, // i
4, 0b01000000, 0b10000000, 0b10000100, 0b01111101, 0b00000000, // j
4, 0b01111111, 0b00010000, 0b00101000, 0b01000100, 0b00000000, // k
3, 0b01000001, 0b01111111, 0b01000000, 0b00000000, 0b00000000, // l
5, 0b01111100, 0b00000100, 0b01111100, 0b00000100, 0b01111000, // m
4, 0b01111100, 0b00000100, 0b00000100, 0b01111000, 0b00000000, // n
4, 0b00111000, 0b01000100, 0b01000100, 0b00111000, 0b00000000, // o
4, 0b11111100, 0b00100100, 0b00100100, 0b00011000, 0b00000000, // p
4, 0b00011000, 0b00100100, 0b00100100, 0b11111100, 0b00000000, // q
4, 0b01111100, 0b00001000, 0b00000100, 0b00000100, 0b00000000, // r
4, 0b01001000, 0b01010100, 0b01010100, 0b00100100, 0b00000000, // s
3, 0b00000100, 0b00111111, 0b01000100, 0b00000000, 0b00000000, // t
4, 0b00111100, 0b01000000, 0b01000000, 0b01111100, 0b00000000, // u
5, 0b00011100, 0b00100000, 0b01000000, 0b00100000, 0b00011100, // v
5, 0b00111100, 0b01000000, 0b00111100, 0b01000000, 0b00111100, // w
5, 0b01000100, 0b00101000, 0b00010000, 0b00101000, 0b01000100, // x
4, 0b10011100, 0b10100000, 0b10100000, 0b01111100, 0b00000000, // y
3, 0b01100100, 0b01010100, 0b01001100, 0b00000000, 0b00000000, // z
3, 0b00001000, 0b00110110, 0b01000001, 0b00000000, 0b00000000, // {
1, 0b01111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // |
3, 0b01000001, 0b00110110, 0b00001000, 0b00000000, 0b00000000, // }
4, 0b00001000, 0b00000100, 0b00001000, 0b00000100, 0b00000000, // ~
};
// LED matrix info.
const uint8_t led_matrix_pin_first = 28;
const uint8_t led_matrix_pin_last = 38;
const uint8_t led_matrix_pin_count = led_matrix_pin_last - led_matrix_pin_first + 1;
const uint8_t led_matrix_rows = 8;
const uint8_t led_matrix_cols = 12;
// Pixel-to-pin translation table.
// A HEX value encodes two pin numbers. The MSB is to be driven LOW,
// the LSB is to be driven HIGH.
// Example: pixel (4,2) contains the value 0x60, meaning that pin 6 must
// be driven low and pin 0 must be driven high to activate the pixel.
// The pin number is an offset to the constant led_matrix_pin_first
// Note that they all appear in pairs, so you could make the table 50%
// smaller at the cost of doing some swapping for odd or even columns.
// (0,0) is upper left corner when the board's USB connector points to the left.
const uint8_t led_matrix_pins[led_matrix_rows][led_matrix_cols] = {
// 0 1 2 3 4 5 6 7 8 9 10 11
{ 0x37, 0x73, 0x47, 0x74, 0x43, 0x34, 0x87, 0x78, 0x83, 0x38, 0x84, 0x48 }, // 0
{ 0x07, 0x70, 0x03, 0x30, 0x04, 0x40, 0x08, 0x80, 0x67, 0x76, 0x63, 0x36 }, // 1
{ 0x64, 0x46, 0x68, 0x86, 0x60, 0x06, 0x57, 0x75, 0x53, 0x35, 0x54, 0x45 }, // 2
{ 0x58, 0x85, 0x50, 0x05, 0x56, 0x65, 0x17, 0x71, 0x13, 0x31, 0x14, 0x41 }, // 3
{ 0x18, 0x81, 0x10, 0x01, 0x16, 0x61, 0x15, 0x51, 0x27, 0x72, 0x23, 0x32 }, // 4
{ 0x24, 0x42, 0x28, 0x82, 0x20, 0x02, 0x26, 0x62, 0x25, 0x52, 0x21, 0x12 }, // 5
{ 0xa7, 0x7a, 0xa3, 0x3a, 0xa4, 0x4a, 0xa8, 0x8a, 0xa0, 0x0a, 0xa6, 0x6a }, // 6
{ 0xa5, 0x5a, 0xa1, 0x1a, 0xa2, 0x2a, 0x97, 0x79, 0x93, 0x39, 0x94, 0x49 }, // 7
};
// Every byte represents a column of the LED matrix.
// Can hold 32 5x8-font characters.
// Buffer can be smaller at the price of more code.
uint8_t led_matrix_buffer[5 * 128];
// Activate the pixel at (x,y) for ontime microseconds.
void put_pixel(uint8_t x, uint8_t y, uint32_t ontime) {
uint8_t pins = led_matrix_pins[y][x];
uint8_t l = (pins >> 4) + led_matrix_pin_first;
uint8_t h = (pins & 0xf) + led_matrix_pin_first;
pinMode(l, OUTPUT);
digitalWrite(l, LOW);
pinMode(h, OUTPUT);
digitalWrite(h, HIGH);
// If ontime = 0, pixel remains active until it is deactivated
// by another put_pixel that happens to use the same pin(s).
if (ontime != 0) {
delayMicroseconds(ontime);
pinMode(l, INPUT);
pinMode(h, INPUT);
}
}
// Call periodically at desired fps rate.
// ontime specifies how long a pixel remains on.
void led_matrix_buffer_show(uint32_t x_offset, uint32_t ontime) {
for (uint8_t i = 0; i < led_matrix_cols; i++) {
if (i + x_offset >= sizeof(led_matrix_buffer)) return;
uint8_t col = led_matrix_buffer[i + x_offset];
for (uint8_t row = 0; row < led_matrix_rows; row++) {
if ((col & 0x01) != 0) {
put_pixel(i, row, ontime);
}
col >>= 1;
}
}
}
// Write a character to the buffer.
uint8_t led_matrix_putch(uint8_t *p_buffer, uint16_t buffer_size, uint8_t ch) {
uint8_t i;
if (ch < ' ') return 0;
ch -= ' ';
uint16_t offset = 6 * ch;
uint8_t width = font_5x8[offset];
for (i = 0; i < width; i++) {
offset += 1;
// This is supposed to prevent buffer overflow.
if (i >= buffer_size) break;
p_buffer[i] = font_5x8[offset];
}
return i + 1;
}
// Write a string to the buffer.
uint16_t led_matrix_puts(uint8_t *p_buffer, uint16_t buffer_size, uint8_t *p_str) {
uint8_t *p = p_buffer;
while (*p_str != 0) {
p += led_matrix_putch(p, buffer_size - (p - p_buffer), *p_str);
p_str++;
}
return p - p_buffer;
}
uint32_t t_prev = 0;
/* -------------------------------------------------------------------------- */
void setup() {
for (uint8_t i = 0; i < led_matrix_pin_count; i++) {
pinMode(led_matrix_pin_first + i, INPUT); // all off
}
// Load text message.
led_matrix_puts(led_matrix_buffer, sizeof(led_matrix_buffer), banner_text);
// Ready...
t_prev = millis();
// Go!
/* -------------------------------------------------------------------------- */ for (uint8_t i = 0; i < led_matrix_pin_count; i++) {
pinMode(led_matrix_pin_first + i, INPUT); // all off
}
// Load text message.
led_matrix_puts(led_matrix_buffer, sizeof(led_matrix_buffer), banner_text);
// Ready...
t_prev = millis();
// Go!
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED, OUTPUT);
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true)
;
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network.
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// Set the Telegram bot properties
myBot.setUpdateTime(1000);
myBot.setTelegramToken(token);
// Check if all things are ok
Serial.print("\nTest Telegram connection... ");
myBot.begin() ? Serial.println("OK") : Serial.println("NOK");
Serial.print("Bot name: @");
Serial.println(myBot.getBotName());
// Add reply keyboard
isKeyboardActive = false;
// add a button that send a message with "Simple button" text
myReplyKbd.addButton("Button1");
myReplyKbd.addButton("Button2");
myReplyKbd.addButton("Button3");
// add a new empty button row
myReplyKbd.addRow();
// add another button that send the user position (location)
myReplyKbd.addButton("Send Location", KeyboardButtonLocation);
// add another button that send the user contact
myReplyKbd.addButton("Send contact", KeyboardButtonContact);
// add a new empty button row
myReplyKbd.addRow();
// add a button that send a message with "Hide replyKeyboard" text
// (it will be used to hide the reply keyboard)
myReplyKbd.addButton("/hide_keyboard");
// resize the keyboard to fit only the needed space
myReplyKbd.enableResize();
// Add sample inline keyboard
myInlineKbd.addButton("ON", LIGHT_ON_CALLBACK, KeyboardButtonQuery);
myInlineKbd.addButton("OFF", LIGHT_OFF_CALLBACK, KeyboardButtonQuery);
myInlineKbd.addRow();
myInlineKbd.addButton("GitHub", "https://github.com/cotestatnt/AsyncTelegram2/", KeyboardButtonURL);
char welcome_msg[128];
snprintf(welcome_msg, 128, "BOT @%s online\n/help all commands avalaible.", myBot.getBotName());
// Send a message to specific user who has started your bot
myBot.sendTo(userid, welcome_msg);
}
/* -------------------------------------------------------------------------- */
void loop() {
/* -------------------------------------------------------------------------- */
// In the meantime LED_BUILTIN will blink with a fixed frequency
// to evaluate async and non-blocking working of library
static uint32_t ledTime = millis();
if (millis() - ledTime > 200) {
ledTime = millis();
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
// if there is an incoming message...
// local variable to store telegram message data
TBMessage msg;
if (myBot.getNewMessage(msg)) {
// check what kind of message I received
MessageType msgType = msg.messageType;
String msgText = msg.text;
led_matrix_puts(led_matrix_buffer, sizeof(led_matrix_buffer), banner_text);
switch (msgType) {
case MessageText:
// received a text message
Serial.print("\nText message received: ");
Serial.println(msgText);
// check if is show keyboard command
if (msgText.equalsIgnoreCase("/reply_keyboard")) {
// the user is asking to show the reply keyboard --> show it
myBot.sendMessage(msg, "This is reply keyboard:", myReplyKbd);
isKeyboardActive = true;
} else if (msgText.equalsIgnoreCase("/inline_keyboard")) {
myBot.sendMessage(msg, "This is inline keyboard:", myInlineKbd);
}
// check if the reply keyboard is active
else if (isKeyboardActive) {
// is active -> manage the text messages sent by pressing the reply keyboard buttons
if (msgText.equalsIgnoreCase("/hide_keyboard")) {
// sent the "hide keyboard" message --> hide the reply keyboard
myBot.removeReplyKeyboard(msg, "Reply keyboard removed");
isKeyboardActive = false;
} else {
// print every others messages received
myBot.sendMessage(msg, msg.text);
//uint8_t banner_text[] = msg;
}
}
// the user write anything else and the reply keyboard is not active --> show a hint message
else {
myBot.sendMessage(msg, "Try /reply_keyboard or /inline_keyboard");
//uint8_t banner_text[] = "---------------";
uint8_t banner_text[] = " ";
size_t len = msgText.length();
memcpy(banner_text, (uint8_t *)msgText.c_str(), len);
led_matrix_puts(led_matrix_buffer, sizeof(led_matrix_buffer), banner_text);
led_matrix_buffer_show(0, 510);
}
break;
case MessageQuery:
// received a callback query message
msgText = msg.callbackQueryData;
Serial.print("\nCallback query message received: ");
Serial.println(msg.callbackQueryData);
if (msgText.equalsIgnoreCase(LIGHT_ON_CALLBACK)) {
// pushed "LIGHT ON" button...
Serial.println("\nSet light ON");
digitalWrite(LED_BUILTIN, HIGH);
// terminate the callback with an alert message
myBot.endQuery(msg, "Light on", true);
} else if (msgText.equalsIgnoreCase(LIGHT_OFF_CALLBACK)) {
// pushed "LIGHT OFF" button...
Serial.println("\nSet light OFF");
digitalWrite(LED_BUILTIN, LOW);
// terminate the callback with a popup message
myBot.endQuery(msg, "Light off");
}
break;
case MessageLocation:
{
// received a location message
String reply = "Longitude: ";
reply += msg.location.longitude;
reply += "; Latitude: ";
reply += msg.location.latitude;
Serial.println(reply);
myBot.sendMessage(msg, reply);
break;
}
case MessageContact:
{
// received a contact message
String reply = "Contact information received:";
reply += msg.contact.firstName;
reply += " ";
reply += msg.contact.lastName;
reply += ", mobile ";
reply += msg.contact.phoneNumber;
Serial.println(reply);
myBot.sendMessage(msg, reply);
break;
}
default:
break;
}
}
// Scroll speed is determined by both scroll_speed and ontime.
// Refresh display.
led_matrix_buffer_show(scroll, ontime);
// Update scroll position.
if (millis() >= t_prev + scroll_speed) {
t_prev = millis();
scroll += 1; // Scroll to the left.
if (scroll > 5 * strlen((char *)banner_text)) {
scroll = 0; // restart
}
}
}
/* -------------------------------------------------------------------------- */
void printWifiStatus() {
/* -------------------------------------------------------------------------- */
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Posto anche il codice originale per far scorrere un testo, per chi ne avesse bisogno.
/*
* Purpose: Display a text message scrolling from right to left
* on the board's 8x12 LED matrix.
* Board: Arduino UNO R4 WiFi
* IDE: 1.8.19 with "Arduino Renesas Boards" version 0.8.5-ea
*
* Usage: Upload to the board and enjoy.
*
* Provides many possibilities for doing things better and more efficiently.
* Parts of this code work because of the way the display works. For instance,
* there is no need to draw black pixels, only white pixels need drawing.
* Naively porting this code to another kind of display will probably not work.
* Buffer overflow protection is probably flawed, so don't count on it.
*
* By: Clemens Valens, Elektor
* Date: 14/6/2023
*/
// Leading spaces ensure starting at the right.
uint8_t banner_text[] = " testo scorrevole ";
// First value is the width of a character in columns. This allows for
// easy tight spacing on the display (TTF kind of thing).
const uint8_t font_5x8[] =
{
3, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // space
1, 0b01011111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // !
3, 0b00000011, 0b00000000, 0b00000011, 0b00000000, 0b00000000, // "
5, 0b00010100, 0b00111110, 0b00010100, 0b00111110, 0b00010100, // #
4, 0b00100100, 0b01101010, 0b00101011, 0b00010010, 0b00000000, // $
5, 0b01100011, 0b00010011, 0b00001000, 0b01100100, 0b01100011, // %
5, 0b00110110, 0b01001001, 0b01010110, 0b00100000, 0b01010000, // &
1, 0b00000011, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // '
3, 0b00011100, 0b00100010, 0b01000001, 0b00000000, 0b00000000, // (
3, 0b01000001, 0b00100010, 0b00011100, 0b00000000, 0b00000000, // )
5, 0b00101000, 0b00011000, 0b00001110, 0b00011000, 0b00101000, // *
5, 0b00001000, 0b00001000, 0b00111110, 0b00001000, 0b00001000, // +
2, 0b10110000, 0b01110000, 0b00000000, 0b00000000, 0b00000000, // ,
4, 0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00000000, // -
2, 0b01100000, 0b01100000, 0b00000000, 0b00000000, 0b00000000, // .
4, 0b01100000, 0b00011000, 0b00000110, 0b00000001, 0b00000000, // /
4, 0b00111110, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // 0
3, 0b01000010, 0b01111111, 0b01000000, 0b00000000, 0b00000000, // 1
4, 0b01100010, 0b01010001, 0b01001001, 0b01000110, 0b00000000, // 2
4, 0b00100010, 0b01000001, 0b01001001, 0b00110110, 0b00000000, // 3
4, 0b00011000, 0b00010100, 0b00010010, 0b01111111, 0b00000000, // 4
4, 0b00100111, 0b01000101, 0b01000101, 0b00111001, 0b00000000, // 5
4, 0b00111110, 0b01001001, 0b01001001, 0b00110000, 0b00000000, // 6
4, 0b01100001, 0b00010001, 0b00001001, 0b00000111, 0b00000000, // 7
4, 0b00110110, 0b01001001, 0b01001001, 0b00110110, 0b00000000, // 8
4, 0b00000110, 0b01001001, 0b01001001, 0b00111110, 0b00000000, // 9
2, 0b01010000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // :
2, 0b10000000, 0b01010000, 0b00000000, 0b00000000, 0b00000000, // ;
3, 0b00010000, 0b00101000, 0b01000100, 0b00000000, 0b00000000, // <
3, 0b00010100, 0b00010100, 0b00010100, 0b00000000, 0b00000000, // =
3, 0b01000100, 0b00101000, 0b00010000, 0b00000000, 0b00000000, // >
4, 0b00000010, 0b01011001, 0b00001001, 0b00000110, 0b00000000, // ?
5, 0b00111110, 0b01001001, 0b01010101, 0b01011101, 0b00001110, // @
4, 0b01111110, 0b00010001, 0b00010001, 0b01111110, 0b00000000, // A
4, 0b01111111, 0b01001001, 0b01001001, 0b00110110, 0b00000000, // B
4, 0b00111110, 0b01000001, 0b01000001, 0b00100010, 0b00000000, // C
4, 0b01111111, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // D
4, 0b01111111, 0b01001001, 0b01001001, 0b01000001, 0b00000000, // E
4, 0b01111111, 0b00001001, 0b00001001, 0b00000001, 0b00000000, // F
4, 0b00111110, 0b01000001, 0b01001001, 0b01111010, 0b00000000, // G
4, 0b01111111, 0b00001000, 0b00001000, 0b01111111, 0b00000000, // H
3, 0b01000001, 0b01111111, 0b01000001, 0b00000000, 0b00000000, // I
4, 0b00110000, 0b01000000, 0b01000001, 0b00111111, 0b00000000, // J
4, 0b01111111, 0b00001000, 0b00010100, 0b01100011, 0b00000000, // K
4, 0b01111111, 0b01000000, 0b01000000, 0b01000000, 0b00000000, // L
5, 0b01111111, 0b00000010, 0b00001100, 0b00000010, 0b01111111, // M
5, 0b01111111, 0b00000100, 0b00001000, 0b00010000, 0b01111111, // N
4, 0b00111110, 0b01000001, 0b01000001, 0b00111110, 0b00000000, // O
4, 0b01111111, 0b00001001, 0b00001001, 0b00000110, 0b00000000, // P
4, 0b00111110, 0b01000001, 0b01000001, 0b10111110, 0b00000000, // Q
4, 0b01111111, 0b00001001, 0b00001001, 0b01110110, 0b00000000, // R
4, 0b01000110, 0b01001001, 0b01001001, 0b00110010, 0b00000000, // S
5, 0b00000001, 0b00000001, 0b01111111, 0b00000001, 0b00000001, // T
4, 0b00111111, 0b01000000, 0b01000000, 0b00111111, 0b00000000, // U
5, 0b00001111, 0b00110000, 0b01000000, 0b00110000, 0b00001111, // V
5, 0b00111111, 0b01000000, 0b00111000, 0b01000000, 0b00111111, // W
5, 0b01100011, 0b00010100, 0b00001000, 0b00010100, 0b01100011, // X
5, 0b00000111, 0b00001000, 0b01110000, 0b00001000, 0b00000111, // Y
4, 0b01100001, 0b01010001, 0b01001001, 0b01000111, 0b00000000, // Z
2, 0b01111111, 0b01000001, 0b00000000, 0b00000000, 0b00000000, // [
4, 0b00000001, 0b00000110, 0b00011000, 0b01100000, 0b00000000, // '\'
2, 0b01000001, 0b01111111, 0b00000000, 0b00000000, 0b00000000, // ]
3, 0b00000010, 0b00000001, 0b00000010, 0b00000000, 0b00000000, // hat
4, 0b01000000, 0b01000000, 0b01000000, 0b01000000, 0b00000000, // _
2, 0b00000001, 0b00000010, 0b00000000, 0b00000000, 0b00000000, // `
4, 0b00100000, 0b01010100, 0b01010100, 0b01111000, 0b00000000, // a
4, 0b01111111, 0b01000100, 0b01000100, 0b00111000, 0b00000000, // b
4, 0b00111000, 0b01000100, 0b01000100, 0b00000000, 0b00000000, // c
4, 0b00111000, 0b01000100, 0b01000100, 0b01111111, 0b00000000, // d
4, 0b00111000, 0b01010100, 0b01010100, 0b00011000, 0b00000000, // e
3, 0b00000100, 0b01111110, 0b00000101, 0b00000000, 0b00000000, // f
4, 0b10011000, 0b10100100, 0b10100100, 0b01111000, 0b00000000, // g
4, 0b01111111, 0b00000100, 0b00000100, 0b01111000, 0b00000000, // h
3, 0b01000100, 0b01111101, 0b01000000, 0b00000000, 0b00000000, // i
4, 0b01000000, 0b10000000, 0b10000100, 0b01111101, 0b00000000, // j
4, 0b01111111, 0b00010000, 0b00101000, 0b01000100, 0b00000000, // k
3, 0b01000001, 0b01111111, 0b01000000, 0b00000000, 0b00000000, // l
5, 0b01111100, 0b00000100, 0b01111100, 0b00000100, 0b01111000, // m
4, 0b01111100, 0b00000100, 0b00000100, 0b01111000, 0b00000000, // n
4, 0b00111000, 0b01000100, 0b01000100, 0b00111000, 0b00000000, // o
4, 0b11111100, 0b00100100, 0b00100100, 0b00011000, 0b00000000, // p
4, 0b00011000, 0b00100100, 0b00100100, 0b11111100, 0b00000000, // q
4, 0b01111100, 0b00001000, 0b00000100, 0b00000100, 0b00000000, // r
4, 0b01001000, 0b01010100, 0b01010100, 0b00100100, 0b00000000, // s
3, 0b00000100, 0b00111111, 0b01000100, 0b00000000, 0b00000000, // t
4, 0b00111100, 0b01000000, 0b01000000, 0b01111100, 0b00000000, // u
5, 0b00011100, 0b00100000, 0b01000000, 0b00100000, 0b00011100, // v
5, 0b00111100, 0b01000000, 0b00111100, 0b01000000, 0b00111100, // w
5, 0b01000100, 0b00101000, 0b00010000, 0b00101000, 0b01000100, // x
4, 0b10011100, 0b10100000, 0b10100000, 0b01111100, 0b00000000, // y
3, 0b01100100, 0b01010100, 0b01001100, 0b00000000, 0b00000000, // z
3, 0b00001000, 0b00110110, 0b01000001, 0b00000000, 0b00000000, // {
1, 0b01111111, 0b00000000, 0b00000000, 0b00000000, 0b00000000, // |
3, 0b01000001, 0b00110110, 0b00001000, 0b00000000, 0b00000000, // }
4, 0b00001000, 0b00000100, 0b00001000, 0b00000100, 0b00000000, // ~
};
// LED matrix info.
const uint8_t led_matrix_pin_first = 28;
const uint8_t led_matrix_pin_last = 38;
const uint8_t led_matrix_pin_count = led_matrix_pin_last - led_matrix_pin_first + 1;
const uint8_t led_matrix_rows = 8;
const uint8_t led_matrix_cols = 12;
// Pixel-to-pin translation table.
// A HEX value encodes two pin numbers. The MSB is to be driven LOW,
// the LSB is to be driven HIGH.
// Example: pixel (4,2) contains the value 0x60, meaning that pin 6 must
// be driven low and pin 0 must be driven high to activate the pixel.
// The pin number is an offset to the constant led_matrix_pin_first
// Note that they all appear in pairs, so you could make the table 50%
// smaller at the cost of doing some swapping for odd or even columns.
// (0,0) is upper left corner when the board's USB connector points to the left.
const uint8_t led_matrix_pins[led_matrix_rows][led_matrix_cols] =
{
// 0 1 2 3 4 5 6 7 8 9 10 11
{ 0x37, 0x73, 0x47, 0x74, 0x43, 0x34, 0x87, 0x78, 0x83, 0x38, 0x84, 0x48 }, // 0
{ 0x07, 0x70, 0x03, 0x30, 0x04, 0x40, 0x08, 0x80, 0x67, 0x76, 0x63, 0x36 }, // 1
{ 0x64, 0x46, 0x68, 0x86, 0x60, 0x06, 0x57, 0x75, 0x53, 0x35, 0x54, 0x45 }, // 2
{ 0x58, 0x85, 0x50, 0x05, 0x56, 0x65, 0x17, 0x71, 0x13, 0x31, 0x14, 0x41 }, // 3
{ 0x18, 0x81, 0x10, 0x01, 0x16, 0x61, 0x15, 0x51, 0x27, 0x72, 0x23, 0x32 }, // 4
{ 0x24, 0x42, 0x28, 0x82, 0x20, 0x02, 0x26, 0x62, 0x25, 0x52, 0x21, 0x12 }, // 5
{ 0xa7, 0x7a, 0xa3, 0x3a, 0xa4, 0x4a, 0xa8, 0x8a, 0xa0, 0x0a, 0xa6, 0x6a }, // 6
{ 0xa5, 0x5a, 0xa1, 0x1a, 0xa2, 0x2a, 0x97, 0x79, 0x93, 0x39, 0x94, 0x49 }, // 7
};
// Every byte represents a column of the LED matrix.
// Can hold 32 5x8-font characters.
// Buffer can be smaller at the price of more code.
uint8_t led_matrix_buffer[5*128];
// Activate the pixel at (x,y) for ontime microseconds.
void put_pixel(uint8_t x, uint8_t y, uint32_t ontime)
{
uint8_t pins = led_matrix_pins[y][x];
uint8_t l = (pins>>4) + led_matrix_pin_first;
uint8_t h = (pins&0xf) + led_matrix_pin_first;
pinMode(l,OUTPUT);
digitalWrite(l,LOW);
pinMode(h,OUTPUT);
digitalWrite(h,HIGH);
// If ontime = 0, pixel remains active until it is deactivated
// by another put_pixel that happens to use the same pin(s).
if (ontime!=0)
{
delayMicroseconds(ontime);
pinMode(l,INPUT);
pinMode(h,INPUT);
}
}
// Call periodically at desired fps rate.
// ontime specifies how long a pixel remains on.
void led_matrix_buffer_show(uint32_t x_offset, uint32_t ontime)
{
for (uint8_t i=0; i<led_matrix_cols; i++)
{
if (i+x_offset>=sizeof(led_matrix_buffer)) return;
uint8_t col = led_matrix_buffer[i+x_offset];
for (uint8_t row=0; row<led_matrix_rows; row++)
{
if ((col&0x01)!=0)
{
put_pixel(i,row,ontime);
}
col >>= 1;
}
}
}
// Write a character to the buffer.
uint8_t led_matrix_putch(uint8_t *p_buffer, uint16_t buffer_size, uint8_t ch)
{
uint8_t i;
if (ch<' ') return 0;
ch -= ' ';
uint16_t offset = 6*ch;
uint8_t width = font_5x8[offset];
for (i=0; i<width; i++)
{
offset += 1;
// This is supposed to prevent buffer overflow.
if (i>=buffer_size) break;
p_buffer[i] = font_5x8[offset];
}
return i+1;
}
// Write a string to the buffer.
uint16_t led_matrix_puts(uint8_t *p_buffer, uint16_t buffer_size, uint8_t *p_str)
{
uint8_t *p = p_buffer;
while (*p_str!=0)
{
p += led_matrix_putch(p,buffer_size-(p-p_buffer),*p_str);
p_str++;
}
return p - p_buffer;
}
uint32_t t_prev = 0;
void setup(void)
{
// Initialize LED matrix pins.
for (uint8_t i=0; i<led_matrix_pin_count; i++)
{
pinMode(led_matrix_pin_first+i,INPUT); // all off
}
// Load text message.
led_matrix_puts(led_matrix_buffer,sizeof(led_matrix_buffer),banner_text);
// Ready...
t_prev = millis();
// Go!
}
void loop(void)
{
// Scroll speed is determined by both scroll_speed and ontime.
const uint8_t scroll_speed = 50; // milliseconds
const uint16_t ontime = 521; // microseconds. 521 (us) * 96 (pixels) = 50 ms frame rate if all the pixels are on.
static uint8_t scroll = 0; // scroll position.
// Refresh display.
led_matrix_buffer_show(scroll,ontime);
// Update scroll position.
if (millis()>=t_prev+scroll_speed)
{
t_prev = millis();
scroll += 1; // Scroll to the left.
if (scroll>5*strlen((char*)banner_text)) {
scroll = 0; // restart
}
}
}