mirror of
https://github.com/nopnop2002/esp-idf-ssd1306.git
synced 2024-10-03 18:18:47 -04:00
Add Display Count Down
This commit is contained in:
parent
218b1b8c28
commit
3e96f2021b
@ -38,7 +38,7 @@
|
||||
}
|
||||
*/
|
||||
|
||||
uint8_t font8x8_basic_tr[128][8] = {
|
||||
static uint8_t font8x8_basic_tr[128][8] = {
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0000 (nul)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0001
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0002
|
||||
|
18
main/main.c
18
main/main.c
@ -3,6 +3,7 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "ssd1306.h"
|
||||
#include "font8x8_basic.h"
|
||||
|
||||
// You have to set this config value with menuconfig
|
||||
// CONFIG_MODEL
|
||||
@ -43,8 +44,21 @@ void app_main(void)
|
||||
ssd1306_display_text(dev, 2, "SSD1306 128x32", 14, true);
|
||||
ssd1306_display_text(dev, 3, "Hello World!!", 13, true);
|
||||
}
|
||||
vTaskDelay(10000 / portTICK_PERIOD_MS);
|
||||
//vTaskDelay(30000 / portTICK_PERIOD_MS);
|
||||
vTaskDelay(3000 / portTICK_PERIOD_MS);
|
||||
|
||||
// Display Count Down
|
||||
uint8_t image[24];
|
||||
memset(image, 0, sizeof(image));
|
||||
ssd1306_display_image(dev, 2, (6*8-1), image, sizeof(image));
|
||||
ssd1306_display_image(dev, 3, (6*8-1), image, sizeof(image));
|
||||
ssd1306_display_image(dev, 4, (6*8-1), image, sizeof(image));
|
||||
for(int font=0x39;font>0x30;font--) {
|
||||
memset(image, 0, sizeof(image));
|
||||
ssd1306_display_image(dev, 3, (7*8-1), image, 8);
|
||||
memcpy(image, font8x8_basic_tr[font], 8);
|
||||
ssd1306_display_image(dev, 3, (7*8-1), image, 8);
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
// Horizontal Scroll
|
||||
ssd1306_clear_screen(dev, false);
|
||||
|
@ -133,8 +133,7 @@ void ssd1306_display_text(SSD1306_t dev, int page, char * text, int text_len, bo
|
||||
}
|
||||
}
|
||||
|
||||
// images[32*4]
|
||||
void ssd1306_display_font(SSD1306_t dev, int page, int seg, uint8_t * images, int width, int height) {
|
||||
void ssd1306_display_image(SSD1306_t dev, int page, int seg, uint8_t * images, int width) {
|
||||
i2c_cmd_handle_t cmd;
|
||||
|
||||
if (page >= dev._pages) return;
|
||||
@ -142,38 +141,35 @@ void ssd1306_display_font(SSD1306_t dev, int page, int seg, uint8_t * images, in
|
||||
|
||||
uint8_t startLow = seg & 0x0F;
|
||||
uint8_t startHigh = (seg >> 4) & 0x0F;
|
||||
uint8_t numPages = height / 8;
|
||||
uint8_t index = 0;
|
||||
|
||||
for (uint8_t cur_page=0; cur_page < numPages; cur_page++) {
|
||||
index = cur_page * 32; // 0,32,64,96
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (dev._address << 1) | I2C_MASTER_WRITE, true);
|
||||
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||
// Set Lower Column Start Address for Page Addressing Mode
|
||||
i2c_master_write_byte(cmd, (0x00 + startLow), true);
|
||||
// Set Higher Column Start Address for Page Addressing Mode
|
||||
i2c_master_write_byte(cmd, (0x10 + startHigh), true);
|
||||
// Set Page Start Address for Page Addressing Mode
|
||||
i2c_master_write_byte(cmd, 0xB0 | (page + cur_page), true);
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (dev._address << 1) | I2C_MASTER_WRITE, true);
|
||||
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_CMD_STREAM, true);
|
||||
// Set Lower Column Start Address for Page Addressing Mode
|
||||
//i2c_master_write_byte(cmd, 0x00, true);
|
||||
i2c_master_write_byte(cmd, (0x00 + startLow), true);
|
||||
// Set Higher Column Start Address for Page Addressing Mode
|
||||
//i2c_master_write_byte(cmd, 0x10, true);
|
||||
i2c_master_write_byte(cmd, (0x10 + startHigh), true);
|
||||
// Set Page Start Address for Page Addressing Mode
|
||||
i2c_master_write_byte(cmd, 0xB0 | page, true);
|
||||
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (dev._address << 1) | I2C_MASTER_WRITE, true);
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);
|
||||
i2c_master_write(cmd, &images[index], width, true);
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (dev._address << 1) | I2C_MASTER_WRITE, true);
|
||||
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
}
|
||||
i2c_master_write_byte(cmd, OLED_CONTROL_BYTE_DATA_STREAM, true);
|
||||
i2c_master_write(cmd, images, width, true);
|
||||
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ typedef struct {
|
||||
void i2c_master_init(int sda, int scl, int reset);
|
||||
void ssd1306_init(SSD1306_t * dev, int width, int height, int I2CAddress);
|
||||
void ssd1306_display_text(SSD1306_t dev, int page, char * text, int text_len, bool invert);
|
||||
void ssd1306_display_font(SSD1306_t dev, int page, int seg, uint8_t * images, int width, int height);
|
||||
void ssd1306_display_image(SSD1306_t dev, int page, int seg, uint8_t * images, int width);
|
||||
void ssd1306_clear_screen(SSD1306_t dev, bool invert);
|
||||
void ssd1306_clear_line(SSD1306_t dev, int page, bool invert);
|
||||
void ssd1306_contrast(SSD1306_t dev, int contrast);
|
||||
|
Loading…
Reference in New Issue
Block a user