#include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "driver/adc.h" #include "ssd1306.h" #include "font8x8_basic.h" #include "driver/i2c.h" /* You have to set this config value with menuconfig CONFIG_INTERFACE for i2c CONFIG_MODEL CONFIG_SDA_GPIO CONFIG_SCL_GPIO CONFIG_RESET_GPIO for SPI CONFIG_CS_GPIO CONFIG_DC_GPIO CONFIG_RESET_GPIO */ /* ADC vars */ esp_err_t ret; int adc1_reading[1] = {0xcc}; int adc2_reading[1] = {0xcc}; const char TAG_CH[][9] = {"ADC1_CH0", "ADC2_CH0"}; void init_adc() { adc1_config_width(ADC_WIDTH_BIT_DEFAULT); adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0); adc2_config_channel_atten(ADC2_CHANNEL_0, ADC_ATTEN_DB_0); } #define tag "SSD1306" void app_main(void) { SSD1306_t dev; int center, top, bottom; char lineChar[20]; #if CONFIG_I2C_INTERFACE ESP_LOGI(tag, "INTERFACE is i2c"); ESP_LOGI(tag, "CONFIG_SDA_GPIO=%d",CONFIG_SDA_GPIO); ESP_LOGI(tag, "CONFIG_SCL_GPIO=%d",CONFIG_SCL_GPIO); ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); i2c_master_init(&dev, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO, CONFIG_RESET_GPIO); #endif // CONFIG_I2C_INTERFACE #if CONFIG_SPI_INTERFACE ESP_LOGI(tag, "INTERFACE is SPI"); ESP_LOGI(tag, "CONFIG_MOSI_GPIO=%d",CONFIG_MOSI_GPIO); ESP_LOGI(tag, "CONFIG_SCLK_GPIO=%d",CONFIG_SCLK_GPIO); ESP_LOGI(tag, "CONFIG_CS_GPIO=%d",CONFIG_CS_GPIO); ESP_LOGI(tag, "CONFIG_DC_GPIO=%d",CONFIG_DC_GPIO); ESP_LOGI(tag, "CONFIG_RESET_GPIO=%d",CONFIG_RESET_GPIO); spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO); #endif // CONFIG_SPI_INTERFACE #if CONFIG_FLIP dev._flip = true; ESP_LOGW(tag, "Flip upside down"); #endif #if CONFIG_SSD1306_128x64 ESP_LOGI(tag, "Panel is 128x64"); ssd1306_init(&dev, 128, 64); #endif // CONFIG_SSD1306_128x64 #if CONFIG_SSD1306_128x32 ESP_LOGI(tag, "Panel is 128x32"); ssd1306_init(&dev, 128, 32); #endif // CONFIG_SSD1306_128x32 ssd1306_clear_screen(&dev, false); //ssd1306_contrast(&dev, 0xff); //ssd1306_contrast(&dev, 0x00); #if CONFIG_SSD1306_128x64 top = 2; center = 3; bottom = 8; int n=200; int pos=0; while(n) { adc1_reading[0] = adc1_get_raw(ADC1_CHANNEL_0); printf("chan[%d] 0x%x = %d\n", 0, adc1_reading[0],adc1_reading[0]); //adc2_reading[0] = adc2_get_raw(ADC2_CHANNEL_0); pos=adc1_reading[0]/375; // 20~2920 => need to calibrate 3000/8=375 printf("pos=%d\n",pos); for (int i=0;i<8;i++) { if ( i != pos) { ssd1306_clear_line(&dev, i,false); } } ssd1306_display_text(&dev, pos, " 2022!!", 11, false); vTaskDelay(50 / portTICK_PERIOD_MS); } #endif // CONFIG_SSD1306_128x64 // Fade Out ssd1306_fadeout(&dev); #if 0 // Fade Out for(int contrast=0xff;contrast>0;contrast=contrast-0x20) { ssd1306_contrast(&dev, contrast); vTaskDelay(40); } #endif // Restart module esp_restart(); }