End of Arduino_GFX setting
******************************************************************************/
#define BACKGROUND BLACK
#define MARK_COLOR WHITE
#define SUBMARK_COLOR DARKGREY // LIGHTGREY
#define HOUR_COLOR WHITE
#define MINUTE_COLOR BLUE // LIGHTGREY
#define SECOND_COLOR RED
// init LCD constant
w = gfx->width();
h = gfx->height();
if (w < h)
{
center = w / 2;
}
else
{
center = h / 2;
}
hHandLen = center * 3 / 8;
mHandLen = center * 2 / 3;
sHandLen = center * 5 / 6;
markLen = sHandLen / 6;
cached_points = (int16_t *)malloc((hHandLen + 1 + mHandLen + 1 + sHandLen + 1) * 2 * 2);
как сюда внести свои пины для подключения
To configure your Arduino Watch Lite with custom pin assignments, you'll need to modify the display initialization section of your code. This involves specifying your own pins for connections such as CS (Chip Select), DC (Data/Command), RST (Reset), BL (Backlight), SCK (Serial Clock), MOSI (Master Out Slave In), and MISO (Master In Slave Out).
Here's a step-by-step guide to help you integrate your custom pin configurations:
1. Define Your Custom Pins
Start by defining the pin numbers you intend to use for each connection. This makes your code cleaner and easier to manage.
cpp
// Define your custom pin assignments
#define CUSTOM_CS 10 // Chip Select
#define CUSTOM_DC 9 // Data/Command
#define CUSTOM_RST 8 // Reset
#define CUSTOM_BL 7 // Backlight
#define CUSTOM_SCK 13 // Serial Clock
#define CUSTOM_MOSI 11 // Master Out Slave In
#define CUSTOM_MISO 12 // Master In Slave Out (if used)
2. Instantiate the Data Bus with Custom Pins
Instead of using the create_default_Arduino_DataBus() function, you'll create your own Arduino_DataBus object with the custom pins you've defined. The specific DataBus class you use depends on your microcontroller board. For example, if you're using an Arduino Nano or similar, you can use the Arduino_HWSPI class for hardware SPI communication.
Here's how to set it up:
cpp
#include <Arduino_GFX_Library.h>
// Define your custom pin assignments
#define CUSTOM_CS 10 // Chip Select
#define CUSTOM_DC 9 // Data/Command
#define CUSTOM_RST 8 // Reset
#define CUSTOM_BL 7 // Backlight
#define CUSTOM_SCK 13 // Serial Clock
#define CUSTOM_MOSI 11 // Master Out Slave In
#define CUSTOM_MISO 12 // Master In Slave Out (if used)
// Define the backlight pin (if applicable)
#define GFX_BL CUSTOM_BL
void setup(void) {
Serial.begin(115200);
Serial.println("Arduino_GFX Clock example with custom pins");
// Initialize Display with Custom Pins
Arduino_DataBus *bus = new Arduino_HWSPI(
CUSTOM_DC, // DC pin
CUSTOM_CS, // CS pin
CUSTOM_SCK, // SCK pin
CUSTOM_MOSI, // MOSI pin
CUSTOM_MISO // MISO pin (use -1 if not connected)
);
// Instantiate the Display Driver (e.g., ILI9341)
Arduino_GFX *gfx = new Arduino_ILI9341(
bus, // Data bus
CUSTOM_RST, // RST pin
0, // Rotation (0-3)
false // IPS (true/false)
);
// Initialize the graphics library
if (!gfx->begin()) {
Serial.println("gfx->begin() failed!");
while (1) {} // Stop execution if initialization fails
}
// Fill the screen with the background color
gfx->fillScreen(BACKGROUND);
// Initialize Backlight (if used)
#ifdef GFX_BL
pinMode(GFX_BL, OUTPUT);
digitalWrite(GFX_BL, HIGH); // Turn on the backlight
#endif
// Continue with the rest of your setup...
}
3. Modify the Conditional Compilation Section
Ensure that the custom pin configuration is used only when the DISPLAY_DEV_KIT is not defined. This avoids conflicts with predefined settings for specific development kits.
cpp
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX *gfx = create_default_Arduino_GFX();
#else
// Custom Data Bus and Display Initialization with defined pins
Arduino_DataBus *bus = new Arduino_HWSPI(
CUSTOM_DC, // DC pin
CUSTOM_CS, // CS pin
CUSTOM_SCK, // SCK pin
CUSTOM_MOSI, // MOSI pin
CUSTOM_MISO // MISO pin (use -1 if not connected)
);
Arduino_GFX *gfx = new Arduino_ILI9341(
bus, // Data bus
CUSTOM_RST, // RST pin
0, // Rotation
false // IPS
);
#endif
4. Complete the Setup and Loop Functions
Ensure that the rest of your setup and loop functions utilize the gfx object initialized with your custom pins.
cpp
void setup(void) {
// [Initialization code as shown above]
// Example: Draw a welcome message
gfx->setTextSize(2);
gfx->setTextColor(MARK_COLOR);
gfx->setCursor(10, 10);
gfx->println("Watch Initialized");
}
void loop(void) {
// Your main code to update the watch display
}
5. Additional Considerations
Backlight Control: If your display doesn't require backlight control or uses a different method, you can omit or adjust the GFX_BL section accordingly.
Rotation and IPS: Adjust the rotation and IPS parameters based on your specific display requirements.
Memory Management: Ensure that you have enough memory for dynamic allocations, especially if you're using large buffers or multiple displays.
Error Handling: Incorporate proper error handling to manage cases where the display might fail to initialize.
6. Complete Modified Code Example
Here's how the complete setup function might look with custom pin assignments:
cpp
#include <Arduino_GFX_Library.h>
// Define your custom pin assignments
#define CUSTOM_CS 10 // Chip Select
#define CUSTOM_DC 9 // Data/Command
#define CUSTOM_RST 8 // Reset
#define CUSTOM_BL 7 // Backlight
#define CUSTOM_SCK 13 // Serial Clock
#define CUSTOM_MOSI 11 // Master Out Slave In
#define CUSTOM_MISO 12 // Master In Slave Out (if used)
#define GFX_BL CUSTOM_BL
#define BACKGROUND BLACK
#define MARK_COLOR WHITE
#define SUBMARK_COLOR DARKGREY // LIGHTGREY
#define HOUR_COLOR WHITE
#define MINUTE_COLOR BLUE // LIGHTGREY
#define SECOND_COLOR RED
// ... [Other definitions and global variables]
void setup(void)
{
Serial.begin(115200);
Serial.println("Arduino_GFX Clock example with custom pins");
// Initialize Display with Custom Pins
Arduino_DataBus *bus = new Arduino_HWSPI(
CUSTOM_DC, // DC pin
CUSTOM_CS, // CS pin
CUSTOM_SCK, // SCK pin
CUSTOM_MOSI, // MOSI pin
CUSTOM_MISO // MISO pin (use -1 if not connected)
);
Arduino_GFX *gfx = new Arduino_ILI9341(
bus, // Data bus
CUSTOM_RST, // RST pin
0, // Rotation (0-3)
false // IPS (true/false)
);
if (!gfx->begin())
{
Serial.println("gfx->begin() failed!");
while (1) {} // Halt if initialization fails
}
gfx->fillScreen(BACKGROUND);
// Initialize Backlight
#ifdef GFX_BL
pinMode(GFX_BL, OUTPUT);
digitalWrite(GFX_BL, HIGH); // Turn on the backlight
#endif
// Initialize LCD constants
w = gfx->width();
h = gfx->height();
if (w < h)
{
center = w / 2;
}
else
{
center = h / 2;
}
hHandLen = center * 3 / 8;
mHandLen = center * 2 / 3;
sHandLen = center * 5 / 6;
markLen = sHandLen / 6;
cached_points = (int16_t *)malloc((hHandLen + 1 + mHandLen + 1 + sHandLen + 1) * 2 * 2);
// [Additional setup code...]
}
void loop(void)
{
// Your loop code to update the watch display
}
7. Final Tips
Library Documentation: Refer to the Arduino_GFX Library Documentation for more detailed information on different DataBus and Display classes.
Board Compatibility: Ensure that the DataBus class you choose is compatible with your microcontroller board.
Testing: After configuring the pins, test each connection individually to ensure that the display communicates correctly with the microcontroller.
By following these steps, you can successfully integrate your custom pin assignments into the Arduino Watch Lite project, allowing for greater flexibility and compatibility with your specific hardware setup.
If you have any further questions or encounter issues, feel free to ask!