Skip to main content

Slike s weba

Što ovaj primjer prikazuje​

Spojite se na Wi-Fi i crtajte slike izravno s web adrese jednom funkcijom, image.draw(). Skica crta dvije bitmape jednu za drugom, čeka tri sekunde, briše frame buffer i zatim crta JPG, a na kraju isključuje Wi-Fi.

Prije učitavanja upišite naziv svoje mreže i lozinku između navodnika kod ssid i password. Komentari u skici navode da bitmap datoteke mogu imati dubinu boje od 1, 4, 8 ili 24 bita, moraju biti bez kompresije i manje od 800x480 piksela da stanu na zaslon.

Ovaj primjer koristi i WiFi (arduino-esp32), koji nije dio Inkplate biblioteke i dolazi s paketom za ESP32 pločicu.

Primjer koda​

Select Board
Inkplate7SPECTRA_Show_Pictures_From_Web.ino
#include "HTTPClient.h" //Include library for HTTPClient
#include "Inkplate.h" //Include Inkplate library to the sketch
#include "WiFi.h" //Include library for WiFi
Inkplate inkplate; // Create an object on Inkplate library and also set library into 1 Bit mode (BW)

const char ssid[] = ""; // Your WiFi SSID
const char *password = ""; // Your WiFi password

void setup()
{
inkplate.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
inkplate.clearDisplay(); // Clear frame buffer of display
inkplate.display(); // Put clear image on display

Serial.print("Connecting to WiFi...");

// Connect to the WiFi network.
WiFi.mode(WIFI_MODE_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi OK! Downloading...");

// Draw the first image from web.
// Monochromatic bitmap with 1 bit depth. Images like this load quickest.
// NOTE: Both drawImage methods allow for an optional fifth "invert" parameter. Setting this parameter to true
// will flip all colors on the image, making black white and white black. This may be necessary when exporting
// bitmaps from certain softwares. Forth parameter will dither the image. Photo taken by: Roberto Fernandez
if (!inkplate.image.draw("https://varipass.org/neowise_mono.bmp", 0, 0, true, false))
{
// If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
// REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no compression!
inkplate.println("Image open error");
inkplate.display();
}
inkplate.display();

if (!inkplate.image.draw("https://varipass.org/neowise.bmp", 0, 0, true, false))
{
// If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
// REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no compression!
inkplate.println("Image open error");
inkplate.display();
}
inkplate.display();

inkplate.clearDisplay();
delay(3000);

// Try to load image and display it on e-paper at position X=0, Y=100
// NOTE: Both drawJpegFromWeb methods allow for an optional fifth "invert" parameter. Setting this parameter to
// true will flip all colors on the image, making black white and white black. forth parameter will dither the
// image.
if (!inkplate.image.draw("https://varipass.org/destination.jpg", 0, 100, true, false))
{
// If is something failed (wrong filename or format), write error message on the screen.
inkplate.println("Image open error");
inkplate.display();
}
inkplate.display();

WiFi.mode(WIFI_OFF);
}

void loop()
{
// Nothing...
}

Korištene funkcije​

Inkplate()returns None

Stvara Inkplate objekt. Inkplate 7SPECTRA ima jedan šesterobojni način rada, pa konstruktor ne prima argument načina rada (komentar o 1-bitnom načinu potječe od drugih Inkplate pločica).

ReturnsKonstruktor; nema povratne vrijednosti.

inkplate.begin()returns void

Inicijalizira biblioteku, periferiju i frame buffer. Pozovite je jednom u `setup()`.

ReturnsNišta.

inkplate.clearDisplay()returns void

Popunjava frame buffer bijelom bojom. Ne mijenja zaslon.

ReturnsNišta.

inkplate.display(bool _leaveOn = 0)returns void

Šalje cijeli frame buffer na zaslon i osvježava ga.

ReturnsNišta.

inkplate.image.draw(const char *path, int x, int y, bool dither = 1, bool invert = 0)returns bool

Crta sliku na položaju x, y. Kada adresa počinje s http:// ili https://, biblioteka preuzima datoteku i dekoder odabire prema ekstenziji datoteke (bmp, dib, jpg, jpeg ili png); bez tog prefiksa datoteku čita s microSD kartice. Skica crta dvije bitmape na (0, 0) i JPG na (0, 100), svaku s uključenim ditheringom i isključenom inverzijom. Kada je inverzija uključena, sve boje slike se invertiraju.

Returns`true` ako je slika nacrtana, `false` ako se nije mogla otvoriti ili dekodirati.

inkplate.println(text)returns size_t

Ispisuje tekst u frame buffer i prelazi u sljedeći redak. Skica ga koristi za poruku o pogrešci `Image open error`.

ReturnsBroj ispisanih bajtova.

WiFi.mode(wifi_mode_t mode)returns bool

Paket za ESP32 pločicu: postavlja Wi-Fi način rada. Skica koristi `WIFI_MODE_STA` za spajanje na mrežu, a `WIFI_OFF` na kraju za isključivanje Wi-Fi-ja.

Returns`true` ako je način rada postavljen.

WiFi.begin(ssid, password)returns wl_status_t

Paket za ESP32 pločicu: počinje spajanje na mrežu.

ReturnsStatus veze.

WiFi.status()returns wl_status_t

Paket za ESP32 pločicu: status veze; `WL_CONNECTED` kada je veza uspostavljena.

ReturnsStatus veze.

Što očekivati​

Zaslon se tri puta osvježi slikama: prvo crno-bijela bitmapa neowise_mono.bmp u gornjem lijevom kutu, zatim bitmapa u boji neowise.bmp preko nje i, nakon stanke od tri sekunde, JPG destination.jpg smješten 100 piksela od vrha. Ako se slika ne može otvoriti, na zaslonu se prikaže Image open error.

Skica ispisuje svoj napredak pomoću Serial.print(), ali nikada ne poziva Serial.begin(), pa sama ne postavlja brzinu prijenosa (baud rate).

🔗Otvorite cijeli primjer

examples/Inkplate7SPECTRA/Advanced/WEB_WiFi/Inkplate7SPECTRA_Show_Pictures_From_Web

→