mirror of
https://github.com/nopnop2002/esp-idf-ssd1306.git
synced 2024-10-03 18:18:47 -04:00
added RebundDemo project
This commit is contained in:
parent
9d45b006a8
commit
b6620907da
8
RebundDemo/CMakeLists.txt
Normal file
8
RebundDemo/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS ../components/ssd1306)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(ssd1306)
|
2
RebundDemo/README.md
Normal file
2
RebundDemo/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# ReboundDemo for SSD1306
|
||||
|
4
RebundDemo/main/CMakeLists.txt
Normal file
4
RebundDemo/main/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
set(COMPONENT_SRCS "main.c")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "")
|
||||
|
||||
register_component()
|
8
RebundDemo/main/component.mk
Normal file
8
RebundDemo/main/component.mk
Normal file
@ -0,0 +1,8 @@
|
||||
#
|
||||
# Main component makefile.
|
||||
#
|
||||
# This Makefile can be left empty. By default, it will take the sources in the
|
||||
# src/ directory, compile them and link them into lib(subdirectory_name).a
|
||||
# in the build directory. This behaviour is entirely configurable,
|
||||
# please read the ESP-IDF documents if you need to do this.
|
||||
#
|
101
RebundDemo/main/main.c
Normal file
101
RebundDemo/main/main.c
Normal file
@ -0,0 +1,101 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_random.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "ssd1306.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
|
||||
*/
|
||||
|
||||
#define tag "SSD1306"
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
SSD1306_t dev;
|
||||
|
||||
#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_SSD1306_128x64
|
||||
ESP_LOGI(tag, "Panel is 128x64");
|
||||
ssd1306_init(&dev, 128, 64);
|
||||
int xmax = 127;
|
||||
int ymax = 63;
|
||||
#endif // CONFIG_SSD1306_128x64
|
||||
#if CONFIG_SSD1306_128x32
|
||||
ESP_LOGI(tag, "Panel is 128x32");
|
||||
ssd1306_init(&dev, 128, 32);
|
||||
int xmax = 127;
|
||||
int ymax = 31;
|
||||
#endif // CONFIG_SSD1306_128x32
|
||||
|
||||
int radius = 4;
|
||||
uint32_t xrand = esp_random();
|
||||
uint32_t yrand = esp_random();
|
||||
ESP_LOGD(tag, "xrand=%"PRIu32" yrand=%"PRIu32, xrand, yrand);
|
||||
//int x_current = 10;
|
||||
//int y_current = 10;
|
||||
int x_current = xrand % xmax;
|
||||
int y_current = yrand % ymax;
|
||||
ESP_LOGD(tag, "x_current=%d", x_current);
|
||||
ESP_LOGD(tag, "y_current=%d", y_current);
|
||||
int x_previus = x_current;
|
||||
int y_previus = y_current;
|
||||
int x_direction = 1;
|
||||
int y_direction = 1;
|
||||
ssd1306_clear_screen(&dev, false);
|
||||
ssd1306_contrast(&dev, 0xff);
|
||||
|
||||
while(1) {
|
||||
_ssd1306_circle(&dev, x_previus, y_previus, radius, true);
|
||||
_ssd1306_circle(&dev, x_current, y_current, radius, false);
|
||||
ssd1306_show_buffer(&dev);
|
||||
x_previus = x_current;
|
||||
y_previus = y_current;
|
||||
x_current = x_current + x_direction;
|
||||
y_current = y_current + y_direction;
|
||||
if ( (x_current + radius) >= xmax) {
|
||||
x_direction = -1;
|
||||
} else if ( (x_current - radius) <= 0) {
|
||||
x_direction = 1;
|
||||
} else if ( (y_current + radius) >= ymax) {
|
||||
y_direction = -1;
|
||||
} else if ( (y_current - radius) <= 0) {
|
||||
y_direction = 1;
|
||||
}
|
||||
vTaskDelay(1);
|
||||
}
|
||||
}
|
18
RebundDemo/sdkconfig.defaults
Normal file
18
RebundDemo/sdkconfig.defaults
Normal file
@ -0,0 +1,18 @@
|
||||
#
|
||||
# ESP32-specific
|
||||
#
|
||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=240
|
||||
|
||||
#
|
||||
# ESP32S2-specific
|
||||
#
|
||||
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ=240
|
||||
|
||||
#
|
||||
# ESP32S3-specific
|
||||
#
|
||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
|
||||
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=240
|
||||
|
Loading…
Reference in New Issue
Block a user