1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Đồ Án môn học hệ thống truyền thông mạch led Đồng hồ

78 0 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Hệ Thống Truyền Thông Mạch Led Đồng Hồ
Tác giả Vũ Hoàng Tài, Hồ Minh Quang, Bùi Công Tính
Người hướng dẫn TS. Trần Duy Cường
Trường học Trường Đại Học Công Nghệ Tp. Hồ Chí Minh
Chuyên ngành Điện Tử - Viễn Thông
Thể loại Đồ Án
Năm xuất bản 2024
Thành phố Tp. Hồ Chí Minh
Định dạng
Số trang 78
Dung lượng 2,35 MB

Cấu trúc

  • CHƯƠNG 1 TỔNG QUAN (13)
  • CHƯƠNG 2: GIỚI THIỆU LINH KIỆN QUAN TRỌNG VÀ LÝ THUYẾT LIÊN QUAN. .2 (13)
  • Chương 3 THIẾT KẾ (34)
  • CHƯƠNG 4: THI CÔNG (35)
  • CHƯƠNG 5 KẾT LUẬN VÀ HƯỚNG PHÁT TRIỂN ĐỀ TÀI (77)
  • TÀI LIỆU THAM KHẢO (78)

Nội dung

Đặc biệt, sau khikết thúc đồ án môn học này em có thêm được nhiều kinh nghiệm trong lĩnh vực điện tử-vi điều khiển, biết cách hoạt động của ESP32, nguyên lý hoạt động của mạch LEDmatrix

TỔNG QUAN

Hiện nay, đèn LED đã trở thành phần không thể thiếu trong cuộc sống hàng ngày, xuất hiện ở mọi nơi như đèn đường, đèn xe và điều khiển tivi Chúng tôi đang thực hiện dự án tạo ra một đồng hồ trang trí để bàn, sử dụng LED panel P10 kết nối với ESP32 để điều khiển và hiển thị thông tin.

Tạo một mạch LED dẫn đường hoàn chỉnh, sử dụng code để nạp và điều khiển LED P10.

Nhiệm vụ của đề tài này là nghiên cứu cách hoạt động của dây LED P10 và ESP32, bao gồm việc tìm hiểu các câu lệnh code cần thiết để nạp và điều khiển dây LED phát sáng theo yêu cầu Đồng thời, đề tài cũng tập trung vào thiết kế và xây dựng mô hình mô phỏng thực tế cũng như lắp đặt và thử nghiệm sản phẩm trực tiếp trên mô hình.

Để thu thập thông tin, bạn có thể sử dụng nhiều phương pháp khác nhau, từ tìm kiếm trên Google đến tham khảo sách về điện tử và các nghiên cứu khoa học Phần mềm Proteus có thể được sử dụng để thiết kế và mô phỏng các mạch điện Đối với phương pháp tính toán, việc sử dụng máy tính là cần thiết.

5 Kết cấu của Đồ Án Môn Học:

Kết cấu đồ án môn học của chúng em gồm 6 chương, bao gồm:

GIỚI THIỆU LINH KIỆN QUAN TRỌNG VÀ LÝ THUYẾT LIÊN QUAN .2

 CHƯƠNG 6: KẾT LUẬN VÀ HƯỚNG PHÁT TRIỂN ĐỀ TÀI

CHƯƠNG 2: GIỚI THIỆU LINH KIỆN QUAN TRỌNG VÀ LÝ THUYẾT

LIÊN QUAN 2.1 ) LÝ THUYẾT VỀ LINH KIỆN

Màn hình LED Panel P10 nổi bật với tính linh hoạt và dễ dàng sử dụng, cho phép điều khiển riêng biệt Đặc biệt, các đèn LED này được trang bị IC điều khiển tích hợp, giúp người dùng điều chỉnh màu sắc và độ sáng một cách hiệu quả.

*Thông số kỹ thuật của LED Panel P10:

• Điện áp hoạt động: 5V DC.

• Dòng tối đa: Khoảng 2-3A/module.

• Công suất tối đa: 10-15W/module.

Màn hình LED ma trận P10 được cấu tạo từ nhiều module LED nhỏ, mỗi module có kích thước 16cm x 32cm và khoảng cách điểm ảnh 10mm, cho phép hiển thị nội dung đa dạng và rõ nét từ khoảng cách xa.

LED ma trận P10 được phân loại dựa trên số màu hiển thị:

LED ma trận P10 đơn sắc hiển thị một màu duy nhất như đỏ, xanh lá, hoặc xanh dương Loại LED này thường được ứng dụng cho các biển quảng cáo đơn giản và mang lại hiệu quả chi phí thấp.

LED ma trận P10 ba màu tích hợp ba màu đỏ, xanh lá và xanh dương, mang lại khả năng hiển thị vượt trội và thu hút sự chú ý hiệu quả hơn so với các loại đèn đơn sắc.

LED ma trận P10 full màu có khả năng hiển thị 16.777.216 màu, lý tưởng cho quảng cáo cao cấp, biểu diễn ánh sáng và sự kiện lớn Ưu điểm nổi bật của LED P10 bao gồm độ sáng cao lên đến 6500mcd, cho phép hiển thị rõ ràng ngay cả dưới ánh sáng mặt trời Bên cạnh đó, với tiêu chuẩn chống nước IP65 và tuổi thọ lên tới 100.000 giờ, LED P10 rất bền bỉ, phù hợp cho sử dụng ngoài trời.

Tính linh hoạt: Dễ dàng thay đổi nội dung hiển thị thông qua phần mềm điều khiển, phù hợp cho nhiều loại hình quảng cáo và thông tin.

Màn hình LED ma trận P10 là một trong những loại màn hình LED phổ biến nhất hiện nay, được ưa chuộng trong nhiều lĩnh vực nhờ vào độ sáng cao, khả năng hiển thị sắc nét và độ bền vượt trội Dưới đây là một số ứng dụng phổ biến của màn hình LED ma trận P10.

LED ma trận P10 là lựa chọn phổ biến cho các bảng quảng cáo ngoài trời lớn, cho phép hiển thị hình ảnh và video một cách sống động Với độ sáng cao, LED P10 đảm bảo nội dung được hiển thị rõ ràng, ngay cả trong điều kiện ánh sáng mặt trời mạnh.

Cửa hàng, siêu thị và trung tâm thương mại hiện nay sử dụng LED ma trận P10 để tạo ra bảng hiệu điện tử, hiển thị thông tin sản phẩm, khuyến mãi và sự kiện đặc biệt Việc này không chỉ thu hút khách hàng mà còn nâng cao hiệu quả truyền thông.

3 Màn hình sân khấu và sự kiện

Màn hình LED ma trận P10 là lựa chọn phổ biến trong các sự kiện lớn như buổi hòa nhạc, hội nghị và lễ hội, nhờ khả năng hiển thị video, hình ảnh và hiệu ứng sân khấu ấn tượng Việc ghép nối các module LED P10 thành màn hình lớn mang đến trải nghiệm hình ảnh tuyệt vời cho khán giả.

4 Hiển thị thông tin giao thông

LED ma trận P10 được ứng dụng rộng rãi trong hệ thống hiển thị thông tin giao thông, bao gồm biển báo điện tử trên đường cao tốc, bảng hiển thị thời gian chờ tại bến xe buýt, và các trạm tàu điện Thông tin như tình hình giao thông, giờ tàu chạy và các thông báo khẩn cấp được cập nhật liên tục và rõ ràng, giúp người dân dễ dàng nắm bắt thông tin cần thiết.

5 Ứng dụng trong giáo dục

Các trường học và cơ sở giáo dục đang áp dụng màn hình LED ma trận P10 để hiển thị lịch học, thông báo và các hoạt động của nhà trường Việc sử dụng màn hình LED mang lại hiệu quả cao trong việc truyền đạt thông tin một cách nhanh chóng.

6 Hiển thị trong nhà máy và khu công nghiệp

Trong các nhà máy và khu công nghiệp, việc sử dụng LED ma trận P10 để hiển thị thông tin sản xuất, chỉ dẫn an toàn và các thông báo quan trọng là rất cần thiết Điều này không chỉ nâng cao hiệu quả quản lý mà còn đảm bảo an toàn lao động cho nhân viên.

LED ma trận P10 mang lại khả năng tùy chỉnh linh hoạt về kích thước và hình dạng, phù hợp với nhiều nhu cầu sử dụng khác nhau Với độ bền cao và khả năng chịu đựng điều kiện môi trường khắc nghiệt, LED P10 là sự lựa chọn lý tưởng cho cả không gian trong nhà và ngoài trời.

LED ma trận P10 là giải pháp hiển thị hiện đại, đa dạng và hiệu quả, phù hợp cho các nhu cầu quảng cáo, thông tin và giải trí.

*Nguyên lý hoạt động của LED Panel P10

Màn hình LED Panel P10 hoạt động theo nguyên lý điều khiển ma trận LED, trong đó mỗi điểm ảnh (pixel) được điều chỉnh để bật/tắt hoặc thay đổi màu sắc thông qua một mạch điều khiển Các thành phần chính và nguyên lý hoạt động của nó sẽ được trình bày chi tiết.

1 Cấu trúc điều khiển ma trận

LED Panel P10 là một ma trận LED với:

Hàng và cột: Các bóng LED được sắp xếp theo ma trận, ví dụ: 32 cột x 16 hàng (tổng cộng 512 điểm ảnh/module).

IC driver: Các IC điều khiển như 74HC595 hoặc dòng IC chuyên dụng (như MBI5124, MBI5024) được tích hợp để điều khiển dòng và điện áp cho LED.

Hub75: Giao diện chuẩn để giao tiếp giữa module LED và vi điều khiển, bao gồm các tín hiệu điều khiển như dữ liệu, đồng hồ, và chọn hàng.

2 Nguyên lý điều khiển a Quét hàng (Row Scanning)

LED Panel P10 sử dụng phương pháp quét đa hàng (multiplexing):

Tại một thời điểm, chỉ một hoặc một nhóm hàng trong ma trận được kích hoạt. Hàng được chọn bằng tín hiệu từ IC shift register (hoặc mạch decoder).

Trong mỗi hàng, các cột sẽ nhận dữ liệu pixel tương ứng để hiển thị. b Điều khiển cường độ sáng

THIẾT KẾ

3.1 ) Tính toán các thông số trong mạch :

Ta có thể dùng bộ nguồn 5V cho mạch ,nguồn 5v sử dụng cho led panel P10,dùng mạch hạ áp để cấp cho esp32 ở mức 3.3V->3.7V.

3.3 ) Nguyên lí hoạt động của mạch :

+ Khối nguồn : Cấp nguồn 5V cung cấp cho toàn mạch,dùng thêm mạch hạ áp để cấp nguồn riêng 3.3V->3.7V cho esp32.

+ Khối Vi điều khiển: Cấp nguồn cho Khối hiển thị cũng như xử lý tín hiệu vào từ

Khối điều khiển là thành phần quan trọng trong việc xử lý mã HEX đã được lập trình, nhằm điều khiển khối hiển thị theo yêu cầu khi nhận tín hiệu từ khối điều khiển.

+ Khối hiển thị : Nhiệm vụ là hiển thị LED theo lập trình đã lưu và biên dịch từ Khối

+ Khối điều khiển : Dùng để nhận và truyền tín hiệu đến Khối Vi điều khiển

Khi Vi điều khiển nhận tín hiệu từ Blynk qua kết nối Wi-Fi, ESP32 sẽ tiếp nhận và xử lý tín hiệu đó, sau đó hiển thị lên P10 theo yêu cầu của người dùng.

Vi ĐiềuKhiểnKhốiNguồn

THI CÔNG

Hình 4.1.1 Sơ đồ kết nối

Hình 4.1.2 Hướng dẫn sử dụng giao diện web

4.2) Chuẩn bị chương trình của mạch và giải thích

// Defines the width and height of the panel in pixels.

// Create a hardware timer of ESP32. hw_timer_t * timer = NULL; portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

// This defines the 'on' time of the display is us.

// The larger this number, the brighter the display If too large the ESP will crash. uint8_t display_draw_time = 30; // 30-70 is usually fine.

// Declaring the "PxMATRIX" object as a "display" and its settings.

PxMATRIX display(matrix_width, matrix_height, P_LAT, P_OE, P_A, P_B, P_C);

In programming, colors can be defined using the RGB color model, where each color is represented by values ranging from 0 to 255 for red, green, and blue components For instance, the color red can be created with the code `uint16_t myRED = display.color565(255, 0, 0);`, while blue is represented as `uint16_t myBLUE = display.color565(0, 0, 255);` Additional colors like white, yellow, cyan, magenta, and violet can also be defined using similar syntax A color array can be created to store multiple colors efficiently, such as `uint16_t myCOLOR_ARRAY[8] = {myRED, myGREEN, myBLUE, myWHITE, myYELLOW, myCYAN, myMAGENTA, myVIOLET};`, enabling easy access and manipulation of these colors in programming projects.

// Interrupt handler for Timer. void IRAM_ATTR display_updater(){

// Increment the counter and set the time of ISR. portENTER_CRITICAL_ISR(&timerMux); display.display(display_draw_time); portEXIT_CRITICAL_ISR(&timerMux);

// Subroutine to enable and disable interrupt timers. void display_update_enable(bool is_enable) { timer = timerBegin(0, 80, true); timerAttachInterrupt(timer, &display_updater, true); timerAlarmWrite(timer, 1500, true); timerAlarmEnable(timer);

} else{ timerDetachInterrupt(timer); timerAlarmDisable(timer);

// put your setup code here, to run once: delay(2000);

// Display initialization. display.begin(8); // > Value 8 for 1/8 row scan panel. delay(100);

To enable timer interrupts, begin by activating the display update and introducing a brief delay of 100 milliseconds Clear the display after another delay and set the brightness to a value between 0 and 255 Sequentially fill the screen with red, green, blue, and white colors, each displayed for two seconds, followed by a clearing of the display Adjust the text settings by disabling text wrapping, setting the text size to one, and rotating the display to zero degrees Fill the screen with red and set the text color to white Position the cursor to print "UTEH" and "STR" at specified coordinates, holding the display for five seconds before clearing it once more.

The provided code snippet demonstrates how to iterate through a color array to display text on a screen It calculates the length of the color array and uses a loop to set the text color for each iteration The display shows the numbers "1234" and the letters "ABCD" at different cursor positions, with a delay of 2500 milliseconds between each display and a clearing of the screen after each sequence This process repeats with adjustments to the cursor's position, ensuring a visually dynamic output while maintaining a consistent delay for readability.

2 Set font chữ bằng thư viện Adafruit

>>>>>>>>>>>>>>>>>>>>>>>>>>>> 02_P10_RGB_32x16_Adafruit_GFX_SetFont // This is how many color levels the display shows - the more the slower the update. //#define PxMATRIX_COLOR_DEPTH 4

// Defines the speed of the SPI bus (reducing this may help if you experience noisy images).

// Creates a second buffer for backround drawing (doubles the required RAM).

//#define PxMATRIX_double_buffer true

// Includes fonts from the "Adafruit GFX Library".

// Defines the width and height of the panel in pixels.

// Create a hardware timer of ESP32. hw_timer_t * timer = NULL; portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

// This defines the 'on' time of the display is us.

// The larger this number, the brighter the display If too large the ESP will crash. uint8_t display_draw_time = 30; // 30-70 is usually fine.

// Declaring the "PxMATRIX" object as a "display" and its settings.

PxMATRIX display(matrix_width, matrix_height, P_LAT, P_OE, P_A, P_B, P_C);

In programming, standard colors can be defined using the `color565` function, which converts RGB values into a 16-bit color format For instance, red is represented as `myRED` with the value (255, 0, 0), green as `myGREEN` (0, 255, 0), and blue as `myBLUE` (0, 0, 255) Other colors include white (`myWHITE` - 255, 255, 255), yellow (`myYELLOW` - 255, 255, 0), cyan (`myCYAN` - 0, 255, 255), violet (`myVIOLET` - 127, 0, 255), and black (`myBLACK` - 0, 0, 0) These colors can be stored in an array, such as `myCOLOR_ARRAY`, which includes all eight defined colors for easy access and manipulation in graphics programming.

// Interrupt handler for Timer. void IRAM_ATTR display_updater(){

// Increment the counter and set the time of ISR. portENTER_CRITICAL_ISR(&timerMux); display.display(display_draw_time); portEXIT_CRITICAL_ISR(&timerMux);

The function `display_update_enable` manages the activation and deactivation of interrupt timers When enabled, it initializes a timer with a frequency of 80, attaches an interrupt for the `display_updater`, sets the timer alarm to trigger every 1500 microseconds, and activates the alarm.

// put your setup code here, to run once: delay(2000);

// Display initialization. display.begin(8); // > Value 8 for 1/8 row scan panel. delay(100);

To enable timer interrupts, first activate the display update and introduce a delay of 100 milliseconds Clear the display, then wait for another second before setting the brightness to 125, which ranges from 0 to 255 After a brief delay, fill the screen with red for two seconds, followed by green for another two seconds After two additional seconds, fill the screen with white, then clear the display once more Finally, wait for one second, disable text wrapping, set the rotation to 0, and introduce a final delay of 100 milliseconds.

// put your main code here, to run repeatedly:

Serial.println("Font : FreeMonoBold9pt7b"); display.setFont(&FreeMonoBold9pt7b); display.setTextColor(myRED); display.setCursor(0, 12); display.print("A1"); delay(5000); display.clearDisplay(); delay(1000);

Serial.println("Font : FreeSansBold9pt7b"); display.setTextColor(myGREEN); display.setCursor(0, 13); display.print("A1"); delay(5000); display.clearDisplay(); delay(1000);

Serial.println("Font : FreeSerifBold9pt7b"); display.setFont(&FreeSerifBold9pt7b); display.setTextColor(myBLUE); display.setCursor(0, 12); display.print("A1"); delay(5000); display.clearDisplay(); delay(1000);

// This is how many color levels the display shows - the more the slower the update. //#define PxMATRIX_COLOR_DEPTH 4

// Defines the speed of the SPI bus (reducing this may help if you experience noisy images).

// Creates a second buffer for backround drawing (doubles the required RAM).

// Defines the width and height of the panel in pixels.

// Create a hardware timer of ESP32. hw_timer_t * timer = NULL; portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

// This defines the 'on' time of the display is us.

// The larger this number, the brighter the display If too large the ESP will crash. uint8_t display_draw_time = 30; // 30-70 is usually fine.

// Declaring the "PxMATRIX" object as a "display" and its settings.

To initialize a PxMATRIX display, use the command `PxMATRIX display(matrix_width, matrix_height, P_LAT, P_OE, P_A, P_B, P_C);` Standard colors can be defined using the `color565` function, which includes myGREEN (0, 255, 0), myBLUE (0, 0, 255), myWHITE (255, 255, 255), myYELLOW (255, 255, 0), myCYAN (0, 255, 255), myMAGENTA (255, 0, 255), myVIOLET (127, 0, 255), and myBLACK (0, 0, 0).

// Interrupt handler for Timer. void IRAM_ATTR display_updater(){

// Increment the counter and set the time of ISR. portENTER_CRITICAL_ISR(&timerMux); display.display(display_draw_time); portEXIT_CRITICAL_ISR(&timerMux);

The `display_update_enable` function manages the activation and deactivation of interrupt timers When enabled, it initializes a timer with specific parameters, attaches an interrupt for the display updater, sets an alarm to trigger every 1500 microseconds, and enables the timer Conversely, when disabled, it detaches the interrupt and disables the timer alarm to stop the updates.

The `run_Scrolling_Text` subroutine enables scrolling text on the display by taking parameters such as the vertical position, speed, content, and color of the text It calculates the text's pixel length using the `getTextWidth` function, ensuring that the text is properly rendered on the screen This function is particularly useful for dynamic displays requiring continuous text movement.

The code snippet demonstrates a scrolling text effect on a display by adjusting the horizontal position of the text based on the width of the matrix and the length of the text in pixels It sets the text color and cursor position, printing the scrolling text while iterating through the positions A delay is introduced to control the scrolling speed, creating a smooth visual transition.

_ _ getTextWidth() uint16_t getTextWidth(const char* text) { int16_t x1, y1; uint16_t w, h; display.getTextBounds(text, 0, 0, &x1, &y1, &w, &h); return w;

// put your setup code here, to run once: delay(2000);

// Display initialization. display.begin(8); // > Value 8 for 1/8 row scan panel. delay(100);

To enable timer interrupts, initiate the display update and clear the display After a one-second delay, set the brightness to 125, allowing a range from 0 to 255, followed by a brief pause Sequentially fill the screen with red, green, blue, and white colors, each lasting two seconds, before clearing the display again After another one-second delay, configure the text settings by disabling text wrap, setting the text size to 1, and adjusting the rotation to 0, allowing for a final one-second pause.

// put your main code here, to run repeatedly:

// run_Scrolling_Text(uint8_t scrolling_Y_Pos, unsigned long scrolling_Speed, char

* scrolling_Text, uint16_t scrolling_Text_Color);

// - scrolling_Y_Pos : Y position settings for scrolling text.

// - scrolling_Speed : Speed settings for scrolling text.

// - scrolling_Text : Displayed text settings for scrolling text.

To customize scrolling text on your display, you can adjust the color settings using commands like `display.color565(255, 0, 0)` for red Start by running scrolling text at a specific position with various text sizes and colors For instance, use `run_Scrolling_Text(0, 35, "Scrolling Text Text Size : 1, Text Color : Red, Font : Default", myRED)` with a text size of 1 and red color Then, change the text size to 2 for green text using `run_Scrolling_Text(0, 35, "Scrolling Text Text Size : 2, Text Color : Green, Font : Default", myGREEN)` You can also set a custom font, such as `FreeMonoBold9pt7b`, for blue text at size 1 with `run_Scrolling_Text(12, 35, "Scrolling Text Text Size : 1, Text Color : Blue, Font : FreeMonoBold9pt7b", myBLUE)` Finally, revert to the default font and display white text using `run_Scrolling_Text(9, 35, "Scrolling Text Text Size : 1, Text Color : White, Font : Default", myWHITE)`.

>>>>>>>>>>>>>>>>>>>>>>>>>>>> 04_Erase_and_Reformat_The_NVS_Memory void setup() {

// put your setup code here, to run once:

Serial.println("erase the NVS partition."); nvs_flash_erase(); // erase the NVS partition and

Serial.println("initialize the NVS partition."); nvs_flash_init(); // initialize the NVS partition.

// put your main code here, to run repeatedly: delay(10);

4 Cài đặt trang web điều khiển

05_P10_RGB_32x16_Set_Scroll_Text_Web_Server_SM

// This is how many color levels the display shows - the more the slower the update. //#define PxMATRIX_COLOR_DEPTH 4

// Defines the speed of the SPI bus (reducing this may help if you experience noisy images).

// Creates a second buffer for backround drawing (doubles the required RAM).

// Defines the width and height of the panel in pixels.

// Create a hardware timer of ESP32. hw_timer_t * timer = NULL; portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

// This defines the 'on' time of the display is us.

// The larger this number, the brighter the display If too large the ESP will crash. uint8_t display_draw_time = 30; // 30-70 is usually fine.

// Declaring the "PxMATRIX" object as a "display" and its settings.

In this article, we define several standard colors using the `color565` function for display purposes The colors include myRED (255, 0, 0), myGREEN (0, 255, 0), myBLUE (0, 0, 255), myWHITE (255, 255, 255), myYELLOW (255, 255, 0), myCYAN (0, 255, 255), myMAGENTA (255, 0, 255), myVIOLET (127, 0, 255), and myBLACK (0, 0, 0) Each color is represented as a 16-bit unsigned integer, allowing for efficient storage and rendering on display devices.

// -Variable declaration for your network credentials. const char* ssid = "YOUR_WIFI_SSID"; // > Your wifi name. const char* password = "YOUR_WIFI_PASSWORD"; // > Your wifi password. // -

// The "key" works like a password To control the "P10 RGB 32x16", users must know the “key”.

// You can change it to another word.

#define key_Txt "p10rgbesp32ws"

// - byte st_Brightness, st_Color_R, st_Color_G, st_Color_B, st_Size, st_Y_Position, st_Speed; uint16_t myCOLOR; char st_Text[150] = ""; bool new_Settings_Come_In = false;

// Declaring the "Preferences" object as "preferences".

// This routine is executed when you open ESP32 IP Address in browser. void handleRoot() { server.send(200, "text/html", MAIN_page); // > Send web page.

// Subroutines for handling handle settings from clients. void handleSettings() {

String incoming_Settings; incoming_Settings = server.arg("key");

// Conditions for checking keys. if (incoming_Settings == key_Txt) { incoming_Settings = server.arg("sta");

// Conditions for setting. if (incoming_Settings == "set") { incoming_Settings = server.arg("st_Brightness"); st_Brightness = incoming_Settings.toInt();

The code retrieves the brightness value using `Serial.println(st_Brightness);` and captures the RGB color settings from the server It processes the incoming red, green, and blue color values by converting them from strings to integers with `toInt()`, ensuring accurate color representation for the application.

Serial.println("Text Color Settings.");

Serial.print(st_Color_R);Serial.print(",");Serial.print(st_Color_G);Serial.print(",");Seri al.println(st_Color_B); incoming_Settings = server.arg("st_Size"); st_Size = incoming_Settings.toInt();

Serial.println("Text Size Settings.");

Serial.println(st_Size); incoming_Settings = server.arg("st_Y_Position");

Serial.println(st_Y_Position); incoming_Settings = server.arg("st_Speed"); st_Speed = incoming_Settings.toInt();

Serial.println("Scrolling Text Speed Settings.");

Serial.println(st_Speed); incoming_Settings = server.arg("st_Text"); int st_Text_Length = incoming_Settings.length() + 1; incoming_Settings.toCharArray(st_Text, st_Text_Length); Serial.println();

Serial.println("Scrolled Text Settings.");

Serial.println(strlen(st_Text));

// Disable Timer Interrupts. display_update_enable(false); delay(1000); save_Settings_to_Flash_Memory(); delay(1000); gets_Settings_Stored_in_Flash_Memory(); delay(1000); new_Settings_Come_In = true; delay(100);

// Enable Timer Interrupts. display_update_enable(true); delay(1000);

// Sends settings stored in flash memory to the client. if (incoming_Settings == "get") {

Serial.println("Get Settings."); char send_Settings[180]; sprintf(send_Settings, "%d|%d|%d|%d|%d|%d|%d|%s", st_Brightness, st_Color_R, st_Color_G, st_Color_B, st_Size, st_Y_Position, st_Speed, st_Text);

Serial.println(send_Settings); server.send(200, "text/plane", send_Settings); // > Sending replies to the client. delay(500);

Serial.println(" -"); server.send(200, "text/plane", "+OK"); // > Sending replies to the client. delay(500);

Serial.println("Wrong Key Text !");

Serial.println("Please enter the correct Key Text."); server.send(200, "text/plane", "+ERR"); // > Sending replies to the client. delay(500);

_ _ gets_Settings_Stored_in_Flash_Memory() void gets_Settings_Stored_in_Flash_Memory() {

Serial.println(" -Get settings stored in Flash Memory.");

// Open Preferences with my-app namespace Each application module, library, etc // has to use a namespace name to prevent key name collisions.

// We will open storage in RW-mode (second parameter has to be false).

To manage user preferences effectively, initiate the preferences with a namespace limited to 15 characters using `preferences.begin("mySettings", false)` and allow a brief delay of 500 milliseconds Retrieve essential settings such as brightness, color components (red, green, blue), size, vertical position, and speed using `getInt` method, with default values set for each parameter: brightness at 125, RGB values at 0, size at 1, Y position at 0, and speed at 50.

String myText = preferences.getString("st_Text", ""); int myText_Length = myText.length() + 1; myText.toCharArray(st_Text, myText_Length); delay(500);

// Close the Preferences. preferences.end(); delay(500);

Serial.print("Brightness : ");Serial.println(st_Brightness);

Serial.print("Text Color (RGB) :

");Serial.print(st_Color_R);Serial.print(",");Serial.print(st_Color_G);Serial.print(",");S erial.println(st_Color_B);

Serial.print("st_Size : ");Serial.println(st_Size);

Serial.print("st_Y_Position : ");Serial.println(st_Y_Position);

Serial.print("st_Speed : ");Serial.println(st_Speed);

Serial.print("st_Text : ");Serial.println(st_Text);

_ _ save_Settings_to_Flash_Memory() void save_Settings_to_Flash_Memory() {

Serial.println(" -Saves settings to flash memory.");

Ngày đăng: 19/12/2024, 16:01

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w