#include "commands.h"
// first init the I2C bus
static esp_err_t i2c_master_init();
void app_main(void)
{
ESP_ERROR_CHECK(i2c_master_init()); // if the I2C was initialized
ESP_LOGI(TAG, "I2C initialized successfully");
gpio_reset_pin(LED); // reset the led Pin for good practice
gpio_reset_pin(SW1); // reset the led Pin for good practice
gpio_set_direction(LED, GPIO_MODE_OUTPUT); // Set the direction LED to output
gpio_set_direction(SW1, GPIO_MODE_INPUT); // Set the direction LED to output
lcd_init(); // Init the LCD
ESP_LOGI(TAG, "LCD initialized successfully");
while (true) {
if (gpio_get_level(SW1)) {
lcd_send_cmd(LCD_CLEARDISPLAY);
lcd_setCursor(0, 0);
lcd_print("LED: ");
lcd_setCursor(0, 4);
lcd_print("ON");
vTaskDelay(50 / portTICK_PERIOD_MS);
gpio_set_level(LED, 1);
ESP_LOGI(TAG, "Message printed on LCD");
}
else {
lcd_send_cmd(LCD_CLEARDISPLAY);
lcd_setCursor(0, 0);
lcd_print("LED: ");
lcd_setCursor(0, 4);
lcd_print("OFF");
vTaskDelay(50 / portTICK_PERIOD_MS);
gpio_set_level(LED, 0);
ESP_LOGI(TAG, "Message printed on LCD");
}
}
}