First Commit

This commit is contained in:
MindCreeper03
2025-02-27 19:31:50 +01:00
parent bcbb6aff9a
commit e490df1715
2470 changed files with 1479965 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
=== Digispark compatibility list ===
arkanoid [ * ] Compatible only with Digispark PRO. For Digispark based on Attiny compile using Damellis attiny package instead of Digispark: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
buffers_demo [ OK ]
snowflakes [ OK ]
draw_bitmap [ OK ]
draw_text [ OK ]
lode_runner [ OK ]
menu_demo [ OK ]
move_sprite [ OK ]
pcd8544_spi [ OK ]
sprite_pool [ OK ]
ssd1306_demo [ * ] Too big for Digispark Attiny85 version (6KiB is not enough). Digispark PRO is OK. Comment out some items.

View File

@@ -0,0 +1,14 @@
=== ESP8266/ESP32 compatibility list ===
arkanoid [ OK ] Can be built and run
buffers_demo [ OK ]
snowflakes [ OK ]
draw_bitmap [ OK ]
draw_text [ OK ]
lode_runner [ OK ]
menu_demo [ OK ]
move_sprite [ OK ]
pcd8544_spi [ OK ]
sprite_pool [ OK ]
ssd1306_demo [ OK ]

View File

@@ -0,0 +1,61 @@
# MIT License
#
# Copyright (c) 2018, Alexey Dynda
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#################################################################
# Makefile to build ssd1306 examples for AVR controllers
#
# Accept the following parameters:
# CC
# CXX
# STRIP
# AR
# MCU
# FREQUENCY
default: all
CC = avr-gcc
CXX = avr-g++
STRIP = avr-strip
AR = avr-ar
MCU ?= atmega328p
FREQUENCY ?= 16000000
platform=avr
CCFLAGS += -g -Os -w -ffreestanding -mmcu=$(MCU) -DF_CPU=$(FREQUENCY)
ifeq ($(ADAFRUIT),y)
INCLUDES += -I../src/ssd1306_hal/avr/arduino
endif
include Makefile.common
all: $(BLD)/$(PROJECT).bin $(BLD)/$(PROJECT).hex
$(BLD)/$(PROJECT).bin: $(OUTFILE)
avr-objcopy -O binary $< $@
$(BLD)/$(PROJECT).hex: $(OUTFILE)
avr-objcopy -O ihex $< $@
flash: $(BLD)/$(PROJECT).hex
avrdude -p m328p -c arduino -P /dev/ttyUSB0 -b 57600 -Uflash:w:$<:i

View File

@@ -0,0 +1,122 @@
# MIT License
#
# Copyright (c) 2018, Alexey Dynda
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#################################################################
# Makefile to build ssd1306 examples for different platforms
#
# Accept the following parameters:
# CC
# CXX
# STRIP
# AR
# MCU
# FREQUENCY
#
# ADAFRUIT=y - compile Adafruit GFX module
# ADAFRUIT_DIR=path_to_adafruit_gfx_library
default: all
DESTDIR ?=
BLD ?= ../bld
PROJECT ?= ssd1306_demo
PROJECTS = $(subst /,,$(wildcard */))
BACKSLASH?=/
OUTFILE?=$(BLD)/$(PROJECT).out
MKDIR?=mkdir -p
convert=$(subst /,$(BACKSLASH),$1)
.SUFFIXES: .bin .out .hex .srec
$(BLD)/%.o: %.c
-$(MKDIR) $(call convert,$(dir $@))
$(CC) -std=gnu11 $(CCFLAGS) $(CCFLAGS-$@) $(CCFLAGS-$(basename $(notdir $@))) -c $< -o $@
$(BLD)/%.o: %.ino
-$(MKDIR) $(call convert,$(dir $@))
$(CXX) -std=c++11 $(CCFLAGS) $(CXXFLAGS) -x c++ -c $< -o $@
$(BLD)/%.o: %.cpp
-$(MKDIR) $(call convert,$(dir $@))
$(CXX) -std=c++11 $(CCFLAGS) $(CXXFLAGS) $(CCFLAGS-$(basename $(notdir $@))) -c $< -o $@
############### OPTIONS #######################
ifeq ($(ADAFRUIT),y)
ADAFRUIT_DIR ?= $(shell readlink -f ~)/Arduino/libraries/Adafruit_GFX_Library
INCLUDES += -I$(ADAFRUIT_DIR)
CCFLAGS-Adafruit_GFX= -DARDUINO=100
SRCS += \
$(ADAFRUIT_DIR)/Adafruit_GFX.cpp
endif
# ************* Common defines ********************
INCLUDES += \
-I./$(PROJECT) \
-I../src
CXXFLAGS += -fno-rtti
CCFLAGS += -MD -g -Os -w -ffreestanding $(INCLUDES) -Wall -Werror \
-Wl,--gc-sections -ffunction-sections -fdata-sections \
$(EXTRA_CCFLAGS)
.PHONY: clean ssd1306 all help
SRCS += main.cpp \
$(wildcard $(PROJECT)/*.cpp) \
$(wildcard $(PROJECT)/*.ino)
OBJS = $(addprefix $(BLD)/, $(addsuffix .o, $(basename $(SRCS))))
LDFLAGS += -L$(BLD) -lssd1306
####################### Compiling library #########################
ssd1306:
$(MAKE) -C ../src -f Makefile.$(platform) MCU=$(MCU) SDL_EMULATION=$(SDL_EMULATION) \
ADAFRUIT=$(ADAFRUIT)
all: $(OUTFILE)
$(OUTFILE): $(OBJS) ssd1306
-$(MKDIR) $(call convert,$(dir $@))
$(CC) -o $(OUTFILE) $(CCFLAGS) $(OBJS) $(LDFLAGS)
clean:
rm -rf $(BLD)
rm -f *~ *.out *.bin *.hex *.srec *.s *.o *.pdf *core
help:
@echo "Makefile accepts the following options:"
@echo " ADAFRUIT=y/n Enables compilation of Adafruit GFX library"
@echo " ADAFRUIT_DIR=path Path to Adafruit GFX library"
@echo " SDL_EMULATION=y/n Enables SDL emulator in the library"
@echo " FREQUENCY=N Frequency in Hz"
@echo " MCU=mcu_code Specifies MCU to compile for (valid for AVR)"
-include $(OBJS:%.o=%.d)

View File

@@ -0,0 +1,71 @@
# MIT License
#
# Copyright (c) 2018, Alexey Dynda
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#################################################################
# Makefile to build ssd1306 examples for AVR controllers
#
# Accept the following parameters:
# CC
# CXX
# STRIP
# AR
# MCU
# FREQUENCY
default: all
ifndef IDF_PATH
$(error If building for ESP32, you must supply the IDF_PATH variable.)
endif
BLD ?= ../bld
PROJECT ?= demos/ssd1306_demo
prepare_esp32_library:
mkdir -p $(BLD)/esp32/components/ssd1306
cp -a ../src $(BLD)/esp32/components/ssd1306/
cp -a ../component.mk $(BLD)/esp32/components/ssd1306/
prepare_esp32_sketch:
mkdir -p $(BLD)/esp32/components/sketch
cp -a $(PROJECT)/* $(BLD)/esp32/components/sketch/
mv $(BLD)/esp32/components/sketch/$(notdir $(PROJECT)).ino $(BLD)/esp32/components/sketch/$(notdir $(PROJECT)).cpp
echo "COMPONENT_ADD_INCLUDEDIRS := ." > $(BLD)/esp32/components/sketch/component.mk
prepare_esp32_project:
mkdir -p $(BLD)/esp32/main
cp -a ./esp32_main.cpp $(BLD)/esp32/main/
echo "" > $(BLD)/esp32/main/component.mk
echo "#" > $(BLD)/esp32/sdkconfig.defaults
echo "PROJECT_NAME:=$(notdir $(PROJECT))" > $(BLD)/esp32/Makefile
# echo "COMPONENTS:=main sketch ssd1306" >> $(BLD)/esp32/Makefile
echo "include \$$(IDF_PATH)/make/project.mk" >> $(BLD)/esp32/Makefile
.PHONY: build
build: prepare_esp32_project prepare_esp32_library prepare_esp32_sketch
$(MAKE) -C $(BLD)/esp32
all: build
flash: build
$(MAKE) -C $(BLD)/esp32 flash

View File

@@ -0,0 +1,58 @@
# MIT License
#
# Copyright (c) 2018, Alexey Dynda
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#################################################################
# Makefile to build ssd1306 examples for Linux
#
# Accept the following parameters:
# CC
# CXX
# STRIP
# AR
# MCU
# FREQUENCY
default: all
platform?=linux
CCFLAGS += -g -Os -w -ffreestanding
ifeq ($(ADAFRUIT),y)
INCLUDES += -I../src/ssd1306_hal/linux/arduino
endif
include Makefile.common
ifeq ($(SDL_EMULATION),y)
CCFLAGS += -I../tools/sdl -DSDL_EMULATION
LDFLAGS += -L/mingw/lib -lssd1306_sdl $(shell sdl2-config --libs)
endif
flash: $(OUTFILE)
$(OUTFILE)
ifeq ($(SDL_EMULATION),y)
$(OUTFILE): ssd1306_sdl
ssd1306_sdl:
$(MAKE) -C ../tools/sdl -f Makefile.$(platform) EXTRA_CPPFLAGS="$(EXTRA_CCFLAGS)"
endif

View File

@@ -0,0 +1,51 @@
# MIT License
#
# Copyright (c) 2018, 2021, Alexey Dynda
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#################################################################
# Makefile to build ssd1306 examples for Linux
#
# Accept the following parameters:
# CC
# CXX
# STRIP
# AR
# MCU
# FREQUENCY
default: all
CC=gcc
platform?=mingw32
BACKSLASH=\\
MKDIR=mkdir
ifeq ($(ADAFRUIT),y)
# Get path to Adafruit GFX library, and remove drive letter C:
ADAFRUIT_DIR?=$(subst C:,,$(shell echo %UserProfile%\Documents)\Arduino\libraries\Adafruit_GFX_Library)
endif
include Makefile.linux
OUTFILE:=$(BLD)/$(PROJECT).exe
# No support for sdl2-config tool in MINGW32
#$(shell sdl2-config --libs)
LDFLAGS += -L/mingw/lib -lSDL2 -lstdc++

View File

@@ -0,0 +1,62 @@
# MIT License
#
# Copyright (c) 2018, Alexey Dynda
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
#################################################################
# Makefile to build ssd1306 examples for AVR controllers
#
# Accept the following parameters:
# CC
# CXX
# STRIP
# AR
# MCU
# FREQUENCY
default: all
CC = arm-none-eabi-gcc
CXX = arm-none-eabi-g++
STRIP = arm-none-eabi-strip
AR = arm-none-eabi-ar
CORE ?= cortex-m3
MCU ?= stm32f4x
FREQUENCY ?= 16000000
platform=stm32
CCFLAGS += -DSTM32F4
CCFLAGS += -mlittle-endian -mthumb -mthumb-interwork -g -Os -w -ffreestanding -mcpu=$(CORE) -DF_CPU=$(FREQUENCY)
LDFLAGS += -specs=nosys.specs
ifeq ($(ADAFRUIT),y)
INCLUDES += -I../src/ssd1306_hal/avr/arduino
endif
include Makefile.common
all: $(BLD)/$(PROJECT).bin $(BLD)/$(PROJECT).hex
$(BLD)/$(PROJECT).bin: $(OUTFILE)
arm-none-eabi-objcopy -O binary $< $@
$(BLD)/$(PROJECT).hex: $(OUTFILE)
arm-none-eabi-objcopy -O ihex $< $@

View File

@@ -0,0 +1,264 @@
/*
MIT License
Copyright (c) 2016-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#define SSD1306_DIRECT_TEST(X) X
#define SSD1306_GFX_TEST(X) 0
#define SSD1306_ENGINE_TEST(X) 0
#define ADAFRUIT_TEST(X) 0
#define U8G2_TEST(X) 0
#define TEST_I2C 0
#define TEST_SPI 1
#define OLED_SSD1306 0
#define OLED_SSD1351 1
#define TEST_INTERFACE TEST_SPI
#define TEST_OLED OLED_SSD1306
#if SSD1306_DIRECT_TEST(1) || SSD1306_ENGINE_TEST(1) || SSD1306_GFX_TEST(1)
#include "ssd1306.h"
#if SSD1306_GFX_TEST(1)
#include "nano_gfx.h"
#if TEST_OLED == OLED_SSD1306
uint8_t data[1024];
NanoCanvas display(128,64,data);
#endif
#if TEST_OLED == OLED_SSD1351
uint8_t data[128*128/8];
NanoCanvas display(128,128,data);
#endif
#endif
#if SSD1306_ENGINE_TEST(1)
#include "nano_engine.h"
#if TEST_OLED == OLED_SSD1306
uint8_t data[1024];
NanoCanvas1 display(128,64,data);
#endif
#if TEST_OLED == OLED_SSD1351
uint8_t data[128*128*16/8];
NanoCanvas16 display(128,128,data);
#endif
#endif
#elif ADAFRUIT_TEST(1)
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#if TEST_INTERFACE == TEST_SPI
Adafruit_SSD1306 display(5,3,4);
#elif TEST_INTERFACE == TEST_I2C
Adafruit_SSD1306 display(4);
#endif
#elif U8G2_TEST(1)
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#if TEST_INTERFACE == TEST_SPI
U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 4, /* dc=*/ 5, /* reset=*/ 3);
#elif TEST_INTERFACE == TEST_I2C
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
#endif
#endif
typedef struct
{
const char *name;
void (*run)(void);
uint32_t result;
} TestInfo;
void benchmark(TestInfo *test)
{
uint32_t start = micros();
uint32_t end;
for (uint8_t i=0; i<8; i++)
{
test->run();
}
end = micros();
test->result = ((uint32_t)(end - start))/8;
}
const char clearScreen[] PROGMEM = "clearScreen";
const char drawRect[] PROGMEM = "drawRect";
const char sendBuffer[] PROGMEM = "sendBuffer";
const char drawText[] PROGMEM = "drawText";
const char drawText2x[] PROGMEM = "drawText 2x";
void doClearScreen()
{
SSD1306_DIRECT_TEST (ssd1306_clearScreen());
SSD1306_GFX_TEST (display.clear());
SSD1306_ENGINE_TEST (display.clear());
ADAFRUIT_TEST (display.clearDisplay());
U8G2_TEST (u8g2.clearBuffer());
}
void doSendBuffer()
{
SSD1306_DIRECT_TEST (); // not applicable
SSD1306_GFX_TEST (display.blt(0,0));
#if TEST_OLED == OLED_SSD1351
SSD1306_ENGINE_TEST (ssd1306_setMode( LCD_MODE_NORMAL ));
#endif
SSD1306_ENGINE_TEST (display.blt());
ADAFRUIT_TEST (display.display());
U8G2_TEST (u8g2.sendBuffer());
}
void drawRect32x32()
{
SSD1306_DIRECT_TEST (ssd1306_drawRect(16,16,48,48));
SSD1306_GFX_TEST (display.drawRect(16,16,48,48));
SSD1306_ENGINE_TEST (display.drawRect(16,16,48,48));
ADAFRUIT_TEST (display.drawRect(16,16,32,32,WHITE));
U8G2_TEST (u8g2.drawFrame(16,16,32,32));
}
void drawTextHello()
{
SSD1306_DIRECT_TEST (ssd1306_printFixed(0,0,"Hello, world!", STYLE_NORMAL));
SSD1306_GFX_TEST (display.printFixed(0,0,"Hello, world!"));
SSD1306_ENGINE_TEST (display.printFixed(0,0,"Hello, world!"));
ADAFRUIT_TEST (display.setCursor(0,0);
display.print("Hello, world!"));
U8G2_TEST (u8g2.setFont(u8g2_font_5x8_tr);
u8g2.drawStr(0,10,"Hello, world!"));
}
void drawTextHello2x()
{
SSD1306_DIRECT_TEST (ssd1306_printFixedN(0,0,"Hello, world!", STYLE_NORMAL, FONT_SIZE_2X));
SSD1306_GFX_TEST (display.printFixed2x(0,0,"Hello, world!"));
SSD1306_ENGINE_TEST ();// not supported
ADAFRUIT_TEST (display.setTextSize(2);
display.setCursor(0,0);
display.print("Hello, world!"));
U8G2_TEST ();// not supported
}
TestInfo tests[] =
{
{
.name = clearScreen,
.run = doClearScreen,
},
{
.name = sendBuffer,
.run = doSendBuffer,
},
{
.name = drawRect,
.run = drawRect32x32,
},
{
.name = drawText2x,
.run = drawTextHello2x,
},
{
.name = drawText,
.run = drawTextHello,
},
};
void initLcd()
{
#if (SSD1306_DIRECT_TEST(1)) || (SSD1306_ENGINE_TEST(1)) || (SSD1306_GFX_TEST(1))
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
#if (TEST_INTERFACE == TEST_SPI)
#if TEST_OLED == OLED_SSD1306
ssd1306_128x64_spi_init(3,4,5);
#endif
#if TEST_OLED == OLED_SSD1351
ssd1351_128x128_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
// ssd1351_128x128_spi_init(3,4,5); // Use this line for Atmega328p
#endif
#elif (TEST_INTERFACE == TEST_I2C)
ssd1306_128x64_i2c_init();
#endif
ssd1306_setFixedFont(ssd1306xled_font6x8);
#endif
ADAFRUIT_TEST (display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE));
U8G2_TEST (u8g2.begin();
u8g2.setFont(u8g2_font_5x8_tr));
}
void setup()
{
#ifdef __linux__
#else
Serial.begin(115200);
#endif
initLcd();
for (uint8_t i=0; i<sizeof(tests)/sizeof(TestInfo); i++)
{
SSD1306_DIRECT_TEST (ssd1306_clearScreen());
SSD1306_GFX_TEST (ssd1306_clearScreen();
display.clear());
SSD1306_ENGINE_TEST (ssd1306_clearScreen();
display.clear());
ADAFRUIT_TEST (display.clearDisplay());
U8G2_TEST (u8g2.clearBuffer());
benchmark(&tests[i]);
const char *p = tests[i].name;
while (pgm_read_byte(p))
{
#ifdef __linux__
printf("%c", (char)pgm_read_byte(p++));
#else
Serial.print((char)pgm_read_byte(p++));
#endif
}
#ifdef __linux__
printf(": %u us\n", tests[i].result);
#else
Serial.print(": ");
Serial.print(tests[i].result);
Serial.println("us");
#endif
doSendBuffer();
delay(2000);
}
doSendBuffer();
}
void loop()
{
}

View File

@@ -0,0 +1,238 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in FULL COLOR MODE */
#include "ssd1306.h"
#include "nano_engine.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t heartImage8[ 8 * 8 ] =
{
0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE5, 0xE5, 0x00,
0xE0, 0xC0, 0xE0, 0xE0, 0xE0, 0xEC, 0xEC, 0xE5,
0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xEC, 0xE5,
0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xE0,
0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00,
0x00, 0x00, 0x80, 0xE0, 0xE0, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"nano canvas",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR8(64,64,255));
ssd1306_drawMonoBitmap8(0, 0, 128, 64, Sova);
ssd1306_drawBitmap8(0, 0, 8, 8, heartImage8);
ssd1306_setColor(RGB_COLOR8(255,64,64));
ssd1306_drawMonoBitmap8(0, 16, 8, 8, heartImage);
delay(3000);
}
/* Sprites are not implemented for color modes.
* But there is NanoEngine support
* To make example clear, we use lambda as function pointer. Since lambda can be
* passed to function only if it doesn't capture, all variables should be global.
* Refer to C++ documentation.
*/
NanoPoint sprite;
NanoEngine8 engine;
static void spriteDemo()
{
// We not need to clear screen, engine will do it for us
engine.begin();
// Force engine to refresh the screen
engine.refresh();
// Set function to draw our sprite
engine.drawCallback( []()->bool {
engine.canvas.clear();
engine.canvas.setColor( RGB_COLOR8(255, 32, 32) );
engine.canvas.drawBitmap1( sprite.x, sprite.y, 8, 8, heartImage );
return true;
} );
sprite.x = 0;
sprite.y = 0;
for (int i=0; i<250; i++)
{
delay(15);
// Tell the engine to refresh screen at old sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
// Tell the engine to refresh screen at new sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
// Do refresh required parts of screen
engine.display();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_printFixed8(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_printFixed8(0, 16, "bold text?", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR8(0,255,255));
ssd1306_printFixed8(0, 24, "Italic text?", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_printFixed8(0, 32, "Inverted bold?", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas1_8 canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
canvas.clear();
canvas.fillRect(10, 3, 80, 5);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,0,0));
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine8(0,0, ssd1306_displayWidth() -1, y);
}
ssd1306_setColor(RGB_COLOR8(0,255,0));
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine8(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
il9163_128x128_spi_init(3, 4, 5);
// il9163_128x128_spi_init(3, -1, 4); // Use this line for ATTINY
// il9163_128x128_spi_init(22, 5, 21); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
// RGB functions do not work in default SSD1306 compatible mode
ssd1306_setMode( LCD_MODE_NORMAL );
ssd1306_clearScreen8( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu8( &menu );
}
uint8_t rotation = 0;
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
if ((menu.count - 1) == ssd1306_menuSelection(&menu))
{
il9163_setRotation((++rotation) & 0x03);
}
ssd1306_clearScreen8( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu8(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu8(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,208 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in SSD1306 COMPATIBLE MODE */
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR16(64,64,255));
ssd1306_drawBitmap(0, 0, 128, 64, Sova);
delay(3000);
}
static void spriteDemo()
{
ssd1306_setColor(RGB_COLOR16(255,32,32));
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_setColor(RGB_COLOR16(255,255,0));
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR16(0,255,255));
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
il9163_128x128_spi_init(3, 4, 5);
// il9163_128x128_spi_init(3, -1, 4); // Use this line for ATTINY
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
uint8_t rotation = 0;
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
if ((menu.count - 1) == ssd1306_menuSelection(&menu))
{
il9163_setRotation((++rotation) & 0x03);
}
ssd1306_clearScreen( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,73 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,238 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in FULL COLOR MODE */
#include "ssd1306.h"
#include "nano_engine.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t heartImage8[ 8 * 8 ] =
{
0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE5, 0xE5, 0x00,
0xE0, 0xC0, 0xE0, 0xE0, 0xE0, 0xEC, 0xEC, 0xE5,
0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xEC, 0xE5,
0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xE0,
0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00,
0x00, 0x00, 0x80, 0xE0, 0xE0, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"nano canvas",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR8(64,64,255));
ssd1306_drawMonoBitmap8(0, 0, 128, 64, Sova);
ssd1306_drawBitmap8(0, 0, 8, 8, heartImage8);
ssd1306_setColor(RGB_COLOR8(255,64,64));
ssd1306_drawMonoBitmap8(0, 16, 8, 8, heartImage);
delay(3000);
}
/* Sprites are not implemented for color modes.
* But there is NanoEngine support
* To make example clear, we use lambda as function pointer. Since lambda can be
* passed to function only if it doesn't capture, all variables should be global.
* Refer to C++ documentation.
*/
NanoPoint sprite;
NanoEngine8 engine;
static void spriteDemo()
{
// We not need to clear screen, engine will do it for us
engine.begin();
// Force engine to refresh the screen
engine.refresh();
// Set function to draw our sprite
engine.drawCallback( []()->bool {
engine.canvas.clear();
engine.canvas.setColor( RGB_COLOR8(255, 32, 32) );
engine.canvas.drawBitmap1( sprite.x, sprite.y, 8, 8, heartImage );
return true;
} );
sprite.x = 0;
sprite.y = 0;
for (int i=0; i<250; i++)
{
delay(15);
// Tell the engine to refresh screen at old sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
// Tell the engine to refresh screen at new sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
// Do refresh required parts of screen
engine.display();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_printFixed8(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_printFixed8(0, 16, "bold text?", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR8(0,255,255));
ssd1306_printFixed8(0, 24, "Italic text?", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_printFixed8(0, 32, "Inverted bold?", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas1_8 canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
canvas.clear();
canvas.fillRect(10, 3, 80, 5);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,0,0));
for (uint16_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine8(0,0, ssd1306_displayWidth() -1, y);
}
ssd1306_setColor(RGB_COLOR8(0,255,0));
for (uint16_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine8(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ili9341_240x320_spi_init(3, 4, 5);
// ili9341_240x320_spi_init(3, -1, 4); // Use this line for ATTINY
// ili9341_240x320_spi_init(22, 5, 21); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
// RGB functions do not work in default SSD1306 compatible mode
ssd1306_setMode( LCD_MODE_NORMAL );
ssd1306_clearScreen8( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu8( &menu );
}
uint8_t rotation = 0;
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
if ((menu.count - 1) == ssd1306_menuSelection(&menu))
{
ili9341_setRotation((++rotation) & 0x03);
}
ssd1306_clearScreen8( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu8(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu8(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,208 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in SSD1306 COMPATIBLE MODE */
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR16(64,64,255));
ssd1306_drawBitmap(0, 0, 128, 64, Sova);
delay(3000);
}
static void spriteDemo()
{
ssd1306_setColor(RGB_COLOR16(255,32,32));
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_setColor(RGB_COLOR16(255,255,0));
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR16(0,255,255));
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint16_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
for (uint16_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ili9341_240x320_spi_init(3, 4, 5);
// ili9341_240x320_spi_init(3, -1, 4); // Use this line for ATTINY
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
uint8_t rotation = 0;
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
if ((menu.count - 1) == ssd1306_menuSelection(&menu))
{
ili9341_setRotation((++rotation) & 0x03);
}
ssd1306_clearScreen( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,73 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,206 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS (i2c)
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
*
* Nano/Atmega328 PINS: connect LCD to A4/A5 (i2c)
* ESP8266: GPIO4(SDA) / GPIO5( SCL )
*/
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_drawBitmap(0, 0, 128, 64, Sova);
delay(1000);
ssd1306_invertMode();
delay(2000);
ssd1306_normalMode();
}
static void spriteDemo()
{
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
/* Select the font to use with menu and all font functions */
ssd1306_setFixedFont(ssd1306xled_font6x8);
pcd8544_84x48_spi_init(3, 4, 5); // FOR ATMEGA
// pcd8544_84x48_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
// pcd8544_84x48_spi_init(3, -1, 4); // FOR ATTINY
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen( );
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,34 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
// ----------------------------------------------------------------------------
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,207 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS (i2c)
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
*
* Nano/Atmega328 PINS: connect LCD to A4/A5 (i2c)
* ESP8266: GPIO4(SDA) / GPIO5( SCL )
* STM32: B7(SDA), B6(SCL)
*/
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_drawBitmap(0, 0, 128, 64, Sova);
delay(1000);
ssd1306_invertMode();
delay(2000);
ssd1306_normalMode();
}
static void spriteDemo()
{
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
/* Select the font to use with menu and all font functions */
ssd1306_setFixedFont(ssd1306xled_font6x8);
sh1106_128x64_i2c_init();
// sh1106_128x64_spi_init(3,4,5); // Use this line for Atmega328p (3=RST, 4=CE, 5=D/C)
// sh1106_128x64_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen( );
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,34 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
// ----------------------------------------------------------------------------
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,34 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
// ----------------------------------------------------------------------------
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,210 @@
/*
MIT License
Copyright (c) 2017-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS (i2c)
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
*
* Nano/Atmega328 PINS: connect LCD to A4/A5 (i2c)
* ESP8266: GPIO4(SDA) / GPIO5( SCL )
* STM32: B7(SDA), B6(SCL)
*/
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_drawBitmap(0, 0, 128, 64, Sova);
delay(1000);
ssd1306_invertMode();
delay(2000);
ssd1306_normalMode();
}
static void spriteDemo()
{
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
/* Select the font to use with menu and all font functions */
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_128x64_i2c_init();
// ssd1306_128x64_spi_init(-1, 0, 1); // Use this line for nano pi (RST not used, 0=CE, gpio1=D/C)
// ssd1306_128x64_spi_init(3,4,5); // Use this line for Atmega328p (3=RST, 4=CE, 5=D/C)
// ssd1306_128x64_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
// ssd1306_128x64_spi_init(22, 5, 21); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
// composite_video_128x64_mono_init(); // Use this line for ESP32 with Composite video support
ssd1306_clearScreen();
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen( );
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,64 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,208 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in SSD1306 COMPATIBLE MODE */
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
#define GRAY_COLOR4(x) (x/16)
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(GRAY_COLOR4(128));
ssd1306_drawBitmap(0, 0, 96, 64, Sova);
delay(3000);
}
static void spriteDemo()
{
ssd1306_setColor(GRAY_COLOR4(192));
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_setColor(GRAY_COLOR4(255));
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(GRAY_COLOR4(192));
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_setColor(GRAY_COLOR4(128));
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(GRAY_COLOR4(164));
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setColor(GRAY_COLOR4(192));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
ssd1306_setColor(GRAY_COLOR4(128));
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
ssd1306_setColor(GRAY_COLOR4(255));
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1325_128x64_spi_init(3, 4, 5); // Use this line for Atmega328p
// ssd1325_128x64_spi_init(3, -1, 4); // Use this line for ATTINY
// ssd1325_128x64_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_setColor(GRAY_COLOR4(255));
ssd1306_showMenu( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen( );
ssd1306_setColor(GRAY_COLOR4(255));
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,64 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,226 @@
/*
MIT License
Copyright (c) 2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in SSD1306 COMPATIBLE MODE */
#include "ssd1306.h"
#include "nano_engine.h"
#include "sova.h"
#define GRAY_COLOR4(x) (x/16)
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t heartImage4[4 * 8] =
{
0xF0, 0x0F, 0xF0, 0x0F,
0xFF, 0xFF, 0x7F, 0xF2,
0xFF, 0xFF, 0xCF, 0xF7,
0xFF, 0xFF, 0xFF, 0xF9,
0xF0, 0xFF, 0xFF, 0x3F,
0x00, 0xFF, 0xFF, 0x03,
0x00, 0xF0, 0x3F, 0x00,
0x00, 0x00, 0x00, 0x00,
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_clearScreen();
ssd1306_setColor(GRAY_COLOR4(128));
ssd1306_drawBitmap(0, 0, 96, 64, Sova);
ssd1306_drawBitmap1_4(8, 72, 8, 8, heartImage4);
ssd1306_drawBitmap1_4(18, 74, 8, 8, heartImage4);
ssd1306_drawBitmap1_4(11, 82, 8, 8, heartImage4);
delay(3000);
}
static void spriteDemo()
{
ssd1306_setColor(GRAY_COLOR4(192));
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_setColor(GRAY_COLOR4(255));
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(GRAY_COLOR4(192));
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_setColor(GRAY_COLOR4(128));
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(GRAY_COLOR4(164));
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[32*16/2];
NanoCanvas1_4 canvas(32,16, buffer);
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.setColor(GRAY_COLOR4(127));
canvas.fillRect(10, 3, 80, 5);
canvas.blt((ssd1306_displayWidth()-32)/2, 1);
delay(500);
canvas.setColor(GRAY_COLOR4(255));
canvas.fillRect(16, 1, 20, 15);
canvas.blt((ssd1306_displayWidth()-32)/2, 1);
delay(1500);
canvas.setColor(GRAY_COLOR4(64));
canvas.printFixed(3, 1, "DEMO", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-32)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
ssd1306_setColor(GRAY_COLOR4(128));
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
ssd1306_setColor(GRAY_COLOR4(255));
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1327_128x128_spi_init(3, 4, 5); // Use this line for Atmega328p
// ssd1327_128x128_spi_init(3, -1, 4); // Use this line for ATTINY
// ssd1327_128x128_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_setColor(GRAY_COLOR4(255));
ssd1306_showMenu( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen( );
ssd1306_setColor(GRAY_COLOR4(255));
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,107 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Owl [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
};
const uint8_t Owl_64x64 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
};

View File

@@ -0,0 +1,35 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _OWL_H_
#define _OWL_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Owl [] PROGMEM;
extern const uint8_t Owl_64x64 [] PROGMEM;
#endif

View File

@@ -0,0 +1,251 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in FULL COLOR MODE */
#include "ssd1306.h"
#include "nano_engine.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t heartImage8[ 8 * 8 ] =
{
0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE5, 0xE5, 0x00,
0xE0, 0xC0, 0xE0, 0xE0, 0xE0, 0xEC, 0xEC, 0xE5,
0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xEC, 0xE5,
0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xE0,
0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00,
0x00, 0x00, 0x80, 0xE0, 0xE0, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"nano canvas",
"draw lines",
};
uint8_t rotation = 0;
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR8(64,64,255));
if ( rotation & 1 )
ssd1306_drawMonoBitmap8(0, 0, 64, 64, Owl_64x64);
else
ssd1306_drawMonoBitmap8(0, 0, 96, 64, Owl);
ssd1306_drawBitmap8(0, 0, 8, 8, heartImage8);
ssd1306_setColor(RGB_COLOR8(255,64,64));
ssd1306_drawMonoBitmap8(0, 16, 8, 8, heartImage);
delay(3000);
}
/* Sprites are not implemented for color modes.
* But there is NanoEngine support
* To make example clear, we use lambda as function pointer. Since lambda can be
* passed to function only if it doesn't capture, all variables should be global.
* Refer to C++ documentation.
*/
NanoPoint sprite;
NanoEngine8 engine;
static void spriteDemo()
{
// We not need to clear screen, engine will do it for us
engine.begin();
// Force engine to refresh the screen
engine.refresh();
// Set function to draw our sprite
engine.drawCallback( []()->bool {
engine.canvas.clear();
engine.canvas.setColor( RGB_COLOR8(255, 32, 32) );
engine.canvas.drawBitmap1( sprite.x, sprite.y, 8, 8, heartImage );
return true;
} );
sprite.x = 0;
sprite.y = 0;
for (int i=0; i<250; i++)
{
delay(15);
// Tell the engine to refresh screen at old sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
// Tell the engine to refresh screen at new sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
// Do refresh required parts of screen
engine.display();
}
}
static void textDemo()
{
ssd1306_clearScreen8();
ssd1306_setFixedFont(digital_font5x7);
ssd1306_setColor(RGB_COLOR8(0,64,255));
ssd1306_printFixed8(0, 0, "0123456789", STYLE_NORMAL);
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_printFixed8(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_printFixed8(0, 16, "Bold text?", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR8(0,255,255));
ssd1306_printFixed8(0, 24, "Italic text?", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_printFixed8(0, 32, "Inverted bold?", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas1_8 canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
canvas.clear();
canvas.fillRect(10, 3, 80, 5);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
/* SSD1331 controller has hardware acceleration, thus *
* use hw ssd1331_drawLine() instead of software ssd1331_drawLine8() */
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1331_drawLine(0,0, ssd1306_displayWidth() -1, y, RGB_COLOR8(0,255,0));
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1331_drawLine(0,0, x, ssd1306_displayHeight() - 1, RGB_COLOR8(0,0,255));
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1331_96x64_spi_init(3, 4, 5); // Use this line for Atmega328p
// ssd1331_96x64_spi_init(3, -1, 4); // Use this line for ATTINY
// ssd1331_96x64_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
// ssd1331_96x64_spi_init(22, 5, 21); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
// RGB functions do not work in default SSD1306 compatible mode
ssd1306_setMode( LCD_MODE_NORMAL );
ssd1306_clearScreen8( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu8( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
if ((menu.count - 1) == ssd1306_menuSelection(&menu))
{
ssd1331_setRotation((++rotation) & 0x03);
}
ssd1306_clearScreen8( );
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_showMenu8(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu8(&menu);
}

View File

@@ -0,0 +1,64 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,203 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in SSD1306 COMPATIBLE MODE */
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR8(64,64,255));
ssd1306_drawBitmap(0, 0, 96, 64, Sova);
delay(3000);
}
static void spriteDemo()
{
ssd1306_setColor(RGB_COLOR8(255,32,32));
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR8(0,255,255));
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1331_drawLine(0,0, ssd1306_displayWidth() -1, y, RGB_COLOR8(0,255,0));
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1331_drawLine(0,0, x, ssd1306_displayHeight() - 1, RGB_COLOR8(0,0,255));
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1331_96x64_spi_init(3, 4, 5); // Use this line for Atmega328p
// ssd1331_96x64_spi_init(3, -1, 4); // Use this line for ATTINY
// ssd1331_96x64_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen( );
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,233 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in FULL COLOR MODE */
#include "ssd1306.h"
#include "nano_engine.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t heartImage8[ 8 * 8 ] =
{
0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE5, 0xE5, 0x00,
0xE0, 0xC0, 0xE0, 0xE0, 0xE0, 0xEC, 0xEC, 0xE5,
0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xEC, 0xE5,
0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xE0,
0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00,
0x00, 0x00, 0x80, 0xE0, 0xE0, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"nano canvas",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR8(64,64,255));
ssd1306_drawMonoBitmap8(0, 0, 128, 64, Sova);
ssd1306_drawBitmap8(0, 0, 8, 8, heartImage8);
ssd1306_setColor(RGB_COLOR8(255,64,64));
ssd1306_drawMonoBitmap8(0, 16, 8, 8, heartImage);
delay(3000);
}
/* Sprites are not implemented for color modes.
* But there is NanoEngine support
* To make example clear, we use lambda as function pointer. Since lambda can be
* passed to function only if it doesn't capture, all variables should be global.
* Refer to C++ documentation.
*/
NanoPoint sprite;
NanoEngine8 engine;
static void spriteDemo()
{
// We not need to clear screen, engine will do it for us
engine.begin();
// Force engine to refresh the screen
engine.refresh();
// Set function to draw our sprite
engine.drawCallback( []()->bool {
engine.canvas.clear();
engine.canvas.setColor( RGB_COLOR8(255, 32, 32) );
engine.canvas.drawBitmap1( sprite.x, sprite.y, 8, 8, heartImage );
return true;
} );
sprite.x = 0;
sprite.y = 0;
for (int i=0; i<250; i++)
{
delay(15);
// Tell the engine to refresh screen at old sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
// Tell the engine to refresh screen at new sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
// Do refresh required parts of screen
engine.display();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_printFixed8(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_printFixed8(0, 16, "bold text?", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR8(0,255,255));
ssd1306_printFixed8(0, 24, "Italic text?", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_printFixed8(0, 32, "Inverted bold?", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas1_8 canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
canvas.clear();
canvas.fillRect(10, 3, 80, 5);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,0,0));
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine8(0,0, ssd1306_displayWidth() -1, y);
}
ssd1306_setColor(RGB_COLOR8(0,255,0));
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine8(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1351_128x128_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
// ssd1351_128x128_spi_init(3, -1, 4); // Use this line for ATTINY
// ssd1351_128x128_spi_init(22, 5, 21); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
// RGB functions do not work in default SSD1306 compatible mode
ssd1306_setMode( LCD_MODE_NORMAL );
ssd1306_clearScreen8( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu8( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen8( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu8(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu8(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,233 @@
/*
MIT License
Copyright (c) 2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in FULL COLOR MODE */
#include "ssd1306.h"
#include "nano_engine.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t heartImage8[ 8 * 8 ] =
{
0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE5, 0xE5, 0x00,
0xE0, 0xC0, 0xE0, 0xE0, 0xE0, 0xEC, 0xEC, 0xE5,
0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xEC, 0xE5,
0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xE0,
0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00,
0x00, 0x00, 0x80, 0xE0, 0xE0, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"nano canvas",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR16(64,64,255));
ssd1306_drawMonoBitmap16(0, 0, 128, 64, Sova);
ssd1306_drawBitmap8(0, 0, 8, 8, heartImage8);
ssd1306_setColor(RGB_COLOR16(255,64,64));
ssd1306_drawMonoBitmap16(0, 16, 8, 8, heartImage);
delay(3000);
}
/* Sprites are not implemented for color modes.
* But there is NanoEngine support
* To make example clear, we use lambda as function pointer. Since lambda can be
* passed to function only if it doesn't capture, all variables should be global.
* Refer to C++ documentation.
*/
NanoPoint sprite;
NanoEngine16 engine;
static void spriteDemo()
{
// We not need to clear screen, engine will do it for us
engine.begin();
// Force engine to refresh the screen
engine.refresh();
// Set function to draw our sprite
engine.drawCallback( []()->bool {
engine.canvas.clear();
engine.canvas.setColor( RGB_COLOR16(255, 32, 32) );
engine.canvas.drawBitmap1( sprite.x, sprite.y, 8, 8, heartImage );
return true;
} );
sprite.x = 0;
sprite.y = 0;
for (int i=0; i<250; i++)
{
delay(15);
// Tell the engine to refresh screen at old sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
// Tell the engine to refresh screen at new sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
// Do refresh required parts of screen
engine.display();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen16();
ssd1306_setColor(RGB_COLOR16(255,255,0));
ssd1306_printFixed16(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_printFixed16(0, 16, "bold text?", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR16(0,255,255));
ssd1306_printFixed16(0, 24, "Italic text?", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_printFixed16(0, 32, "Inverted bold?", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas1_16 canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen16();
canvas.clear();
canvas.fillRect(10, 3, 80, 5);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen16();
ssd1306_setColor(RGB_COLOR16(255,0,0));
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine16(0,0, ssd1306_displayWidth() -1, y);
}
ssd1306_setColor(RGB_COLOR16(0,255,0));
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine16(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1351_128x128_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
// ssd1351_128x128_spi_init(3, -1, 4); // Use this line for ATTINY
// ssd1351_128x128_spi_init(22, 5, 21); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
// RGB functions do not work in default SSD1306 compatible mode
ssd1306_setMode( LCD_MODE_NORMAL );
ssd1306_clearScreen16( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu16( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen16( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu16(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu16(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,203 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in SSD1306 COMPATIBLE MODE */
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR16(64,64,255));
ssd1306_drawBitmap(0, 0, 128, 64, Sova);
delay(3000);
}
static void spriteDemo()
{
ssd1306_setColor(RGB_COLOR16(255,32,32));
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_setColor(RGB_COLOR16(255,255,0));
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR16(0,255,255));
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1351_128x128_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(24, 0, 23); // Use this line for Raspberry (gpio24=RST, 0=CE, gpio23=D/C)
// ssd1351_128x128_spi_init(3, -1, 4); // Use this line for ATTINY
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
ssd1306_clearScreen( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,80 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,238 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in FULL COLOR MODE */
#include "ssd1306.h"
#include "nano_engine.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t heartImage8[ 8 * 8 ] =
{
0x00, 0xE0, 0xE0, 0x00, 0x00, 0xE5, 0xE5, 0x00,
0xE0, 0xC0, 0xE0, 0xE0, 0xE0, 0xEC, 0xEC, 0xE5,
0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xEC, 0xE5,
0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE5, 0xE0,
0x00, 0x80, 0xC0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00,
0x00, 0x00, 0x80, 0xE0, 0xE0, 0xE0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xE0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"nano canvas",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR8(64,64,255));
ssd1306_drawMonoBitmap8(0, 0, 128, 64, Sova);
ssd1306_drawBitmap8(0, 0, 8, 8, heartImage8);
ssd1306_setColor(RGB_COLOR8(255,64,64));
ssd1306_drawMonoBitmap8(0, 16, 8, 8, heartImage);
delay(3000);
}
/* Sprites are not implemented for color modes.
* But there is NanoEngine support
* To make example clear, we use lambda as function pointer. Since lambda can be
* passed to function only if it doesn't capture, all variables should be global.
* Refer to C++ documentation.
*/
NanoPoint sprite;
NanoEngine8 engine;
static void spriteDemo()
{
// We not need to clear screen, engine will do it for us
engine.begin();
// Force engine to refresh the screen
engine.refresh();
// Set function to draw our sprite
engine.drawCallback( []()->bool {
engine.canvas.clear();
engine.canvas.setColor( RGB_COLOR8(255, 32, 32) );
engine.canvas.drawBitmap1( sprite.x, sprite.y, 8, 8, heartImage );
return true;
} );
sprite.x = 0;
sprite.y = 0;
for (int i=0; i<250; i++)
{
delay(15);
// Tell the engine to refresh screen at old sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
// Tell the engine to refresh screen at new sprite position
engine.refresh( sprite.x, sprite.y, sprite.x + 8 - 1, sprite.y + 8 - 1 );
// Do refresh required parts of screen
engine.display();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_printFixed8(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_printFixed8(0, 16, "bold text?", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR8(0,255,255));
ssd1306_printFixed8(0, 24, "Italic text?", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_printFixed8(0, 32, "Inverted bold?", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas1_8 canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR8(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen8();
canvas.clear();
canvas.fillRect(10, 3, 80, 5);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen8();
ssd1306_setColor(RGB_COLOR8(255,0,0));
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine8(0,0, ssd1306_displayWidth() -1, y);
}
ssd1306_setColor(RGB_COLOR8(0,255,0));
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine8(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
st7735_128x160_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, -1, 4); // Use this line for ATTINY
// st7735_128x160_spi_init(22, 5, 21); // Use this line for ESP32 (VSPI) (gpio22=RST, gpio5=CE for VSPI, gpio21=D/C)
// RGB functions do not work in default SSD1306 compatible mode
ssd1306_setMode( LCD_MODE_NORMAL );
ssd1306_clearScreen8( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu8( &menu );
}
uint8_t rotation = 0;
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
if ((menu.count - 1) == ssd1306_menuSelection(&menu))
{
st7735_setRotation((++rotation) & 0x03);
}
ssd1306_clearScreen8( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu8(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu8(&menu);
}

View File

@@ -0,0 +1,73 @@
#include "sova.h"
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const uint8_t Sova [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

View File

@@ -0,0 +1,33 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _SOVA_H_
#define _SOVA_H_
#include "ssd1306_hal/io.h"
#include <stdint.h>
extern const uint8_t Sova [] PROGMEM;
#endif

View File

@@ -0,0 +1,208 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
/* !!! THIS DEMO RUNS in SSD1306 COMPATIBLE MODE */
#include "ssd1306.h"
#include "nano_gfx.h"
#include "sova.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
SAppMenu menu;
const char *menuItems[] =
{
"draw bitmap",
"sprites",
"fonts",
"canvas gfx",
"draw lines",
};
static void bitmapDemo()
{
ssd1306_setColor(RGB_COLOR16(64,64,255));
ssd1306_drawBitmap(0, 0, 128, 64, Sova);
delay(3000);
}
static void spriteDemo()
{
ssd1306_setColor(RGB_COLOR16(255,32,32));
ssd1306_clearScreen();
/* Declare variable that represents our sprite */
SPRITE sprite;
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
for (int i=0; i<250; i++)
{
delay(15);
sprite.x++;
if (sprite.x >= ssd1306_displayWidth())
{
sprite.x = 0;
}
sprite.y++;
if (sprite.y >= ssd1306_displayHeight())
{
sprite.y = 0;
}
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}
}
static void textDemo()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
ssd1306_setColor(RGB_COLOR16(255,255,0));
ssd1306_printFixed(0, 8, "Normal text", STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_printFixed(0, 16, "Bold text", STYLE_BOLD);
ssd1306_setColor(RGB_COLOR16(0,255,255));
ssd1306_printFixed(0, 24, "Italic text", STYLE_ITALIC);
ssd1306_negativeMode();
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_printFixed(0, 32, "Inverted bold", STYLE_BOLD);
ssd1306_positiveMode();
delay(3000);
}
static void canvasDemo()
{
uint8_t buffer[64*16/8];
NanoCanvas canvas(64,16, buffer);
ssd1306_setColor(RGB_COLOR16(0,255,0));
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_clearScreen();
canvas.clear();
canvas.fillRect(10, 3, 80, 5, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(500);
canvas.fillRect(50, 1, 60, 15, 0xFF);
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(1500);
canvas.printFixed(20, 1, " DEMO ", STYLE_BOLD );
canvas.blt((ssd1306_displayWidth()-64)/2, 1);
delay(3000);
}
static void drawLinesDemo()
{
ssd1306_clearScreen();
for (uint8_t y = 0; y < ssd1306_displayHeight(); y += 8)
{
ssd1306_drawLine(0,0, ssd1306_displayWidth() -1, y);
}
for (uint8_t x = ssd1306_displayWidth() - 1; x > 7; x -= 8)
{
ssd1306_drawLine(0,0, x, ssd1306_displayHeight() - 1);
}
delay(3000);
}
void setup()
{
ssd1306_setFixedFont(ssd1306xled_font6x8);
st7735_128x160_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, -1, 4); // Use this line for ATTINY
ssd1306_clearScreen( );
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
ssd1306_showMenu( &menu );
}
uint8_t rotation = 0;
void loop()
{
delay(1000);
switch (ssd1306_menuSelection(&menu))
{
case 0:
bitmapDemo();
break;
case 1:
spriteDemo();
break;
case 2:
textDemo();
break;
case 3:
canvasDemo();
break;
case 4:
drawLinesDemo();
break;
default:
break;
}
if ((menu.count - 1) == ssd1306_menuSelection(&menu))
{
st7735_setRotation((++rotation) & 0x03);
}
ssd1306_clearScreen( );
ssd1306_setColor(RGB_COLOR16(255,255,255));
ssd1306_showMenu(&menu);
delay(500);
ssd1306_menuDown(&menu);
ssd1306_updateMenu(&menu);
}

View File

@@ -0,0 +1,105 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
uint32_t lastMillis;
uint8_t hours = 10;
uint8_t minutes = 35;
uint8_t seconds = 0;
void printSeconds()
{
if (seconds & 1)
{
ssd1306_printFixed(54, 8, ":", STYLE_NORMAL);
}
else
{
ssd1306_printFixed(54, 8, " ", STYLE_NORMAL);
}
}
void printMinutes()
{
char minutesStr[3] = "00";
minutesStr[0] = '0' + minutes / 10;
minutesStr[1] = '0' + minutes % 10;
ssd1306_printFixed(78, 8, minutesStr, STYLE_NORMAL);
}
void printHours()
{
char hoursStr[3] = "00";
hoursStr[0] = '0' + hours / 10;
hoursStr[1] = '0' + hours % 10;
ssd1306_printFixed(6, 8, hoursStr, STYLE_NORMAL);
}
void setup() {
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
ssd1306_fillScreen(0x00);
ssd1306_setFixedFont(comic_sans_font24x32_123);
lastMillis = millis();
printHours();
printMinutes();
}
void loop()
{
if ((uint32_t)(millis() - lastMillis) >= 1000)
{
lastMillis += 1000;
if (++seconds > 59)
{
seconds = 0;
if (++minutes > 59)
{
minutes = 0;
if (++hours > 23)
{
hours = 0;
}
printHours();
}
printMinutes();
}
printSeconds();
}
}

View File

@@ -0,0 +1,77 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
const uint8_t g_customFont_5x8[] PROGMEM =
{
0x00, // 0x00 means fixed font type - the only supported by the library
0x05, // 0x05 = 5 - font width in pixels
0x08, // 0x08 = 8 - font height in pixels
0x30, // 0x30 = 48 - first ascii character number in the font ('0' = ascii code 48)
// '0'
0b00000000,
0b00111110,
0b01000001,
0b01000001,
0b00111110,
// '1'
0b00000000,
0b01000010,
0b01111111,
0b01000000,
0b00000000,
0x00, // End of font
};
void setup()
{
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
// ssd1306_128x64_spi_init(3, 4, 5);
ssd1306_fillScreen(0x00);
ssd1306_setFixedFont( g_customFont_5x8 );
ssd1306_printFixed (0, 8, "01100011", STYLE_NORMAL );
ssd1306_printFixedN (0, 16, "1001", STYLE_ITALIC, FONT_SIZE_2X);
}
void loop()
{
}

View File

@@ -0,0 +1,97 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
#ifndef CONFIG_SSD1306_UNICODE_ENABLE
#error "This sketch requires CONFIG_SSD1306_UNICODE_ENABLE to be enabled in UserSettings.h"
#endif
const uint8_t g_customUnicodeFont_6x8[] PROGMEM =
{
0x01, // 0x01 means fixed font type with unicode support
0x06, // 0x05 = 6 - font width in pixels
0x08, // 0x08 = 8 - font height in pixels
0x00, // This byte has no meaning for unicode fonts
// Start of unicode table
0x00, // First unicode char in block (LSB)
0xE4, // First unicode char in block (MSB) = 0x00E4
0x01, // number of chars encoded in the block
// 'ä'
0B00111000,
0B01000101,
0B01000100,
0B00111001,
0B01000100,
0B00000000,
0x00, // First unicode char in block (LSB)
0xC4, // First unicode char in block (MSB) = 0x00C4
0x01, // number of chars encoded in the block
// 'Ä'
0B00000000,
0B11110000,
0B00101001,
0B00100100,
0B00101001,
0B11110000,
0x00, 0x00, 0x00, // End of unicode tables
};
void setup()
{
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
// ssd1306_128x64_spi_init(3, 4, 5);
ssd1306_fillScreen(0x00);
// First variant of usage: using unicodes with standard ascii font
ssd1306_setFixedFont( ssd1306xled_font6x8 );
ssd1306_setSecondaryFont( g_customUnicodeFont_6x8 );
ssd1306_printFixed (0, 8, "Ascii + Ää", STYLE_NORMAL );
// Second variant of usage: without standard ascii font
ssd1306_setFixedFont( g_customUnicodeFont_6x8 );
ssd1306_printFixed (0, 16, "ÄäÄäÄä", STYLE_NORMAL );
}
void loop()
{
}

View File

@@ -0,0 +1,149 @@
/*
MIT License
Copyright (c) 2016-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
const uint8_t Owl [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x0A, 0x05, 0x0D, 0x01, 0x01, 0x03, 0x87, 0xFE, 0xFE, 0xFC, 0xF8, 0xF0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0E,
0x08, 0x0C, 0x0C, 0x0C, 0x0E, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, 0x30,
0x98, 0xDE, 0xE6, 0xE7, 0xF7, 0xD7, 0xD6, 0x56, 0x56, 0xD7, 0xD7, 0x5F, 0xDF, 0x3F, 0x3F, 0x2F,
0x9F, 0xD7, 0xDF, 0x6F, 0x6B, 0x6B, 0x7F, 0xF7, 0xF3, 0xF3, 0xE0, 0xEC, 0x98, 0x30, 0xE0, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x60, 0x70, 0x70, 0x60,
0x40, 0x60, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xC0, 0xC0, 0xE0, 0xF0, 0xE0, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xFB, 0xE0,
0xDF, 0xB1, 0xEF, 0x5F, 0xB9, 0xB0, 0xA0, 0xE6, 0x6E, 0x2E, 0xB6, 0xB9, 0x9F, 0xAF, 0xA0, 0xA7,
0xBF, 0x99, 0xB6, 0xB6, 0xA6, 0xA6, 0xB0, 0xB0, 0xA9, 0xDF, 0xCF, 0xF0, 0x7F, 0x77, 0xFD, 0x01,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0xEE, 0xB3, 0x7D, 0xBE, 0x7F, 0xC7, 0x87, 0xB7,
0xB7, 0xB7, 0xCD, 0x7D, 0x83, 0x93, 0xFB, 0xCD, 0xB5, 0x35, 0xA5, 0x87, 0xCE, 0xFE, 0x1C, 0xF9,
0xC3, 0x1C, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x3F, 0x3C, 0x73,
0xEF, 0x9E, 0x7E, 0xFD, 0xFD, 0xED, 0xAD, 0xFD, 0xDD, 0xFF, 0xBF, 0xFF, 0x5F, 0xDF, 0xEF, 0xFF,
0xFF, 0xFF, 0x6F, 0xFF, 0xDF, 0xEF, 0xFD, 0xDD, 0xFD, 0xBC, 0xFE, 0x7E, 0xBF, 0xEF, 0x7B, 0x3E,
0x1F, 0x0F, 0x07, 0x00, 0x00, 0x0E, 0x1F, 0x3C, 0x77, 0x5F, 0x3D, 0x7D, 0xFB, 0xFB, 0x7A, 0xFA,
0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0x7E, 0xFE, 0xBF, 0xFD, 0xF5, 0xF5, 0xF6, 0xFA, 0xFB, 0xDF,
0x67, 0x78, 0x3C, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00,
0x60, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xC0, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x10, 0x38, 0x80, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x00, 0x81, 0x83, 0x83, 0x87, 0xE7, 0xEF, 0xEF, 0xEB, 0xFF, 0xF7, 0xDF,
0xFA, 0xFE, 0xFF, 0xEB, 0xEE, 0xEE, 0xE7, 0x67, 0x63, 0x61, 0x60, 0x60, 0x60, 0xE0, 0xE0, 0xE0,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x71, 0x73, 0x7B,
0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7E, 0x7F, 0x77, 0x76, 0x73, 0x73, 0x71, 0x71, 0x70, 0x71, 0x70,
0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF1, 0xF1, 0xF1, 0xE0, 0xE0,
0xE8, 0xEC, 0xEE, 0xE7, 0xE2, 0xE4, 0xE8, 0xD0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0,
0x10, 0x10, 0x10, 0x10, 0x1F, 0x13, 0xA1, 0xAD, 0xC8, 0x49, 0x47, 0x42, 0x40, 0xC0, 0xDC, 0x78,
0x60, 0x60, 0x20, 0x21, 0x31, 0x30, 0x11, 0x1A, 0x1B, 0x0B, 0x0D, 0x0C, 0x04, 0x06, 0x06, 0x06,
0x03, 0x03, 0x03, 0x13, 0x31, 0x71, 0x71, 0x61, 0x81, 0x81, 0x41, 0x20, 0x26, 0x0C, 0x1C, 0x30,
0x78, 0x00, 0x00, 0x84, 0xC4, 0x84, 0x84, 0x0C, 0x04, 0x02, 0x02, 0x01, 0x01, 0x07, 0x0E, 0x0E,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xE0, 0xC0, 0xC0, 0x00, 0x00, 0x81, 0x81, 0x81, 0x41, 0x41,
0x21, 0x21, 0x13, 0x13, 0x13, 0x03, 0x0B, 0x0B, 0x0B, 0x0F, 0x0F, 0x07, 0x07, 0x07, 0x07, 0x07,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x00, 0x06, 0x07, 0x03, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x40, 0xEE, 0x79,
0x35, 0x02, 0x08, 0x08, 0x04, 0x04, 0x02, 0x1F, 0x3D, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
0x04, 0x24, 0x00, 0x0D, 0x30, 0x31, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0xC6, 0xC6, 0x36, 0x68, 0x44,
0xB4, 0xA0, 0x52, 0x62, 0x02, 0x02, 0x02, 0x00, 0x01, 0x03, 0x32, 0x7A, 0x3E, 0x1A, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x1D, 0x3D, 0x1D, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/**
* Soba bitmap source is generated via script from https://github.com/robertgallup/bmp2hex
* MIT license
*/
const uint8_t Soba [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80,
0x09, 0x00, 0x00, 0x00, 0xc0, 0x0c, 0x00, 0x00,
0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x30, 0x03,
0x00, 0x00, 0x00, 0x98, 0x01, 0x00, 0xf8, 0x00,
0xcc, 0x00, 0x00, 0xde, 0x03, 0x66, 0x00, 0x80,
0x07, 0x0f, 0x33, 0x00, 0xc0, 0x01, 0x9c, 0x19,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff,
0xff, 0xff, 0x07, 0xe0, 0xff, 0xff, 0xff, 0x07,
0xe0, 0xff, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff,
0xff, 0x07, 0xe0, 0xff, 0xff, 0xff, 0x07, 0xc0,
0xff, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0xff,
0x03, 0x80, 0xff, 0xff, 0xff, 0x01, 0x80, 0xff,
0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0x00,
0x00, 0xfe, 0xff, 0x7f, 0x00, 0x00, 0xfc, 0xff,
0x3f, 0x00, 0x00, 0xf8, 0xff, 0x1f, 0x00, 0x00,
0xf0, 0xff, 0x0f, 0x00, 0x00, 0xc0, 0xff, 0x03,
0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup()
{
ssd1306_128x64_i2c_init();
}
void loop()
{
ssd1306_clearScreen( );
ssd1306_drawBitmap(0, 0, 128, 64, Owl);
delay(3000);
ssd1306_clearScreen( );
ssd1306_drawXBitmap(0, 0, 40, 32, Soba);
delay(3000);
}

View File

@@ -0,0 +1,64 @@
/*
MIT License
Copyright (c) 2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
void setup()
{
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
ssd1306_fillScreen(0x00);
ssd1306_setFixedFont(ssd1306xled_font6x8);
}
int progress = 0;
void loop()
{
ssd1306_drawProgressBar( progress );
progress++;
if ( progress > 100 )
{
progress = 0;
delay( 2000 );
}
else
{
delay( 50 );
}
}

View File

@@ -0,0 +1,56 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
void setup()
{
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
ssd1306_fillScreen(0x00);
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_printFixed (0, 8, "Line 1. Normal text", STYLE_NORMAL);
ssd1306_printFixed (0, 16, "Line 2. Bold text", STYLE_BOLD);
ssd1306_printFixed (0, 24, "Line 3. Italic text", STYLE_ITALIC);
ssd1306_printFixedN (0, 32, "Line 4. Double size", STYLE_BOLD, FONT_SIZE_2X);
}
void loop()
{
}

View File

@@ -0,0 +1,58 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
void setup()
{
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
ssd1306_fillScreen(0x00);
ssd1306_setFreeFont(free_calibri11x12);
ssd1306_setSecondaryFont(free_calibri11x12_cyrillic);
ssd1306_printFixed(0, 8, u8"This is Русский", STYLE_NORMAL);
ssd1306_setSecondaryFont(free_calibri11x12_latin);
ssd1306_printFixed(0, 24, u8"This is Deutsch Länder", STYLE_NORMAL);
}
void loop()
{
}

View File

@@ -0,0 +1,89 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
const uint8_t g_customFont_5x16[] PROGMEM =
{
0x00, // 0x00 means fixed font type - the only supported by the library
0x05, // 0x05 = 5 - font width in pixels
0x10, // 0x10 = 16 - font height in pixels
0x30, // 0x30 = 48 - first ascii character number in the font ('0' = ascii code 48)
// '0'
0b00000000, // upper 8 pixels of character
0b11111100,
0b00000011,
0b00000011,
0b11111100,
0b00000000, // lower 8 pixels of character
0b00011111,
0b01100000,
0b01100000,
0b00011111,
// '1'
0b00000000, // upper 8 pixels of character
0b00001100,
0b11111111,
0b00000000,
0b00000000,
0b00000000, // lower 8 pixels of character
0b01100000,
0b01111111,
0b01100000,
0b00000000,
0x00, // End of font
};
void setup()
{
/* Replace the line below with ssd1306_128x32_i2c_init() if you need to use 128x32 display */
ssd1306_128x64_i2c_init();
// ssd1306_128x64_spi_init(3, 4, 5);
ssd1306_fillScreen(0x00);
ssd1306_setFixedFont( g_customFont_5x16 );
ssd1306_printFixed (0, 0, "01100011", STYLE_NORMAL );
ssd1306_printFixedN (0, 16, "1001", STYLE_NORMAL, FONT_SIZE_2X);
}
void loop()
{
}

View File

@@ -0,0 +1,63 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
#include "ssd1306_console.h"
Ssd1306Console console;
void setup()
{
/* Replace the line below with the display initialization function, you want to use */
ssd1306_128x64_i2c_init();
ssd1306_clearScreen();
/* Set font to use with console */
ssd1306_setFixedFont(ssd1306xled_font6x8);
}
void loop()
{
static uint8_t i = 0;
/* Here use any methods, provided by Arduino Print class */
console.print("Line ");
console.print( i );
i++;
delay(500);
console.println("");
}

View File

@@ -0,0 +1,57 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
#include "ssd1306_console.h"
void setup()
{
/* Replace the line below with the display initialization function, you want to use */
ssd1306_128x64_i2c_init();
ssd1306_clearScreen();
/* Set font to use with console */
ssd1306_setFixedFont(ssd1306xled_font6x8);
}
void loop()
{
ssd1306_print( "This is console output: " );
ssd1306_print( "go to the next line\n" );
delay(500);
}

View File

@@ -0,0 +1,47 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "buttons.h"
#include "ssd1306.h"
uint8_t getPressedButton(uint8_t analogPin)
{
int buttonValue = analogRead(analogPin);
if (buttonValue < 100) {
return BUTTON_RIGHT;
}
else if (buttonValue < 200) {
return BUTTON_UP;
}
else if (buttonValue < 400){
return BUTTON_DOWN;
}
else if (buttonValue < 600){
return BUTTON_LEFT;
}
else if (buttonValue < 800){
return BUTTON_SELECT;
}
return BUTTON_NONE;
}

View File

@@ -0,0 +1,37 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <stdint.h>
const uint8_t BUTTON_NONE = 0;
const uint8_t BUTTON_RIGHT = 1;
const uint8_t BUTTON_UP = 2;
const uint8_t BUTTON_DOWN = 3;
const uint8_t BUTTON_LEFT = 4;
const uint8_t BUTTON_SELECT = 5;
uint8_t getPressedButton(uint8_t analogPin);

View File

@@ -0,0 +1,105 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0) - BUTTONS module
*
* Atmega328 PINS: connect LCD to A4/A5,
* Z-keypad ADC module on A0 pin.
*/
#include "ssd1306.h"
#include "buttons.h"
#ifndef A0
#define A0 0
#endif
#define BUTTON_PIN A0
/* Define menu items of the menu box */
const char *menuItems[] =
{
"menu item 1",
"menu item 2",
"menu item 3",
"menu item 4",
"menu item 5",
"menu item 6",
"menu item 7",
"menu item 8",
};
/* This variable will hold menu state, processed by SSD1306 API functions */
SAppMenu menu;
static uint8_t button;
void setup()
{
ssd1306_128x64_i2c_init();
ssd1306_setFixedFont(ssd1306xled_font6x8);
ssd1306_fillScreen( 0x00 );
/* Initialize main menu state */
ssd1306_createMenu( &menu, menuItems, sizeof(menuItems) / sizeof(char *) );
/* show menu on the display */
ssd1306_showMenu( &menu );
button = getPressedButton(BUTTON_PIN);
}
void loop()
{
uint8_t newButton = getPressedButton(BUTTON_PIN);
if (newButton == button)
{
return;
}
button = newButton;
switch (button)
{
case BUTTON_UP:
/* move menu cursor up and refresh menu on the display */
ssd1306_menuUp( &menu );
ssd1306_updateMenu( &menu );
break;
case BUTTON_DOWN:
/* move menu cursor down and refresh menu on the display */
ssd1306_menuDown( &menu );
ssd1306_updateMenu( &menu );
break;
case BUTTON_SELECT:
/* You always can request current position of menu cursor, by calling ssd1306_menuSelection() */
break;
default:
break;
}
}

View File

@@ -0,0 +1,100 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is defined from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
/* Declare variable that represents our sprite */
SPRITE sprite;
int speedX = 1;
int speedY = 1;
void setup()
{
ssd1306_128x64_i2c_init();
ssd1306_fillScreen(0x00);
/* Create sprite at 0,0 position. The function initializes sprite structure. */
sprite = ssd1306_createSprite( 0, 0, spriteWidth, heartImage );
/* Draw sprite on the display */
sprite.draw();
}
void loop()
{
/* Move sprite every 40 milliseconds */
delay(40);
sprite.x += speedX;
sprite.y += speedY;
/* If right boundary is reached, reverse X direction */
if (sprite.x == (128 - spriteWidth)) speedX = -speedX;
/* If left boundary is reached, reverse X direction */
if (sprite.x == 0) speedX = -speedX;
/* Sprite height is always 8 pixels. Reverse Y direction if bottom boundary is reached. */
if (sprite.y == (64 - 8)) speedY = -speedY;
/* If top boundary is reached, reverse Y direction */
if (sprite.y == 0) speedY = -speedY;
/* Erase sprite on old place. The library knows old position of the sprite. */
sprite.eraseTrace();
/* Draw sprite on new place */
sprite.draw();
}

View File

@@ -0,0 +1,82 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
#include "nano_engine.h"
/*
* Each pixel in SSD1306 display takes 1 bit of the memory. So, full resolution
* of 128x64 LCD display will require 128*64/8 = 1024 bytes of SRAM for the buffer.
* To let this example to run on Attiny devices (they have 256/512 byte SRAM), we
* will use small canvas buffer: 32x32 (requires 128 bytes of SRAM), so the example
* would run even on Attiny45.
*/
const int canvasWidth = 32; // Width must be power of 2, i.e. 16, 32, 64, 128...
const int canvasHeight = 32; // Height must be divided on 8, i.e. 8, 16, 24, 32...
uint8_t canvasData[canvasWidth*(canvasHeight/8)];
/* Create canvas object */
NanoCanvas1 canvas(canvasWidth, canvasHeight, canvasData);
void setup()
{
/* Initialize and clear display */
ssd1306_128x64_i2c_init();
// ssd1306_128x64_i2c_init();
// pcd8544_84x48_spi_init(3, 4, 5); // 3 RST, 4 CES, 5 DS
// ssd1331_96x64_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(3, 4, 5);
// il9163_128x128_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, 4, 5);
ssd1306_clearScreen();
/* Set font to use with canvas in console mode */
ssd1306_setFixedFont(ssd1306xled_font6x8);
/* Make text to wrap to new line automatically at the end of buffer */
canvas.setMode( CANVAS_TEXT_WRAP_LOCAL );
}
void loop()
{
/* Here use any methods, provided by Arduino Print class */
canvas.print( "Start: " );
canvas.println( "<LF>" );
delay(500);
canvas.blt();
}

View File

@@ -0,0 +1,146 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
// Define this before including library header, this will give Adafruit GFX support
// !!! Don't forget to install AdafruitGFX library to your Arduino IDE !!!
#define CONFIG_ADAFRUIT_GFX_ENABLE
#include "ssd1306.h"
#include "nano_engine.h"
// No need to include this for Arduino sketch
#ifndef ARDUINO
extern "C" void __cxa_pure_virtual() { while (1); }
#endif
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is define from left to rigth (bits), from top to
* bottom (bytes). Unlike NanoCanvas1 of ssd1306 library, Adafruit
* GFX implementation uses different aproach for images, stored in Flash.
*/
const PROGMEM uint8_t heartImage[8] =
{
0B01100110,
0B11111001,
0B11111101,
0B11111111,
0B01111110,
0B00111100,
0B00011000,
0B00000000
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
/* Lets show 4 hearts on the display */
const int spritesCount = 4;
/* Declare variable that represents our 4 objects */
struct
{
NanoPoint pos;
NanoPoint speed;
} objects[ spritesCount ];
/*
* Each pixel in SSD1306 display takes 1 bit of the memory. So, full resolution
* of 128x64 LCD display will require 128*64/8 = 1024 bytes of SRAM for the buffer.
* To let this example to run on Attiny devices (they have 256/512 byte SRAM), we
* will use small canvas buffer: 32x32 (requires 128 bytes of SRAM), so the example
* would run even on Attiny45.
*/
const int canvasWidth = 64; // Width must be power of 2, i.e. 16, 32, 64, 128...
const int canvasHeight = 32; // Height must be divided on 8, i.e. 8, 16, 24, 32...
uint8_t canvasData[canvasWidth*(canvasHeight/8)];
AdafruitCanvas1 canvas(canvasWidth, canvasHeight, canvasData);
void setup()
{
/* Initialize and clear display */
ssd1306_128x64_i2c_init();
// ssd1306_128x64_spi_init(3, 4, 5);
// pcd8544_84x48_spi_init(3, 4, 5); // 3 RST, 4 CES, 5 DS
// ssd1331_96x64_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(3, 4, 5);
// il9163_128x128_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, 4, 5);
ssd1306_fillScreen(0x00);
/* Create 4 "hearts", and place them at different positions and give different movement direction */
for(uint8_t i = 0; i < spritesCount; i++)
{
objects[i].speed = { .x = (i & 1) ? -1: 1, .y = (i & 2) ? -1: 1 };
objects[i].pos = { .x = i*4, .y = i*4 + 2 };
}
}
void loop()
{
delay(40);
/* Recalculate position and movement direction of all 4 "hearts" */
for (uint8_t i = 0; i < spritesCount; i++)
{
objects[i].pos += objects[i].speed;
/* If left or right boundary is reached, reverse X direction */
if ((objects[i].pos.x == (canvasWidth - 8)) || (objects[i].pos.x == 0))
objects[i].speed.x = -objects[i].speed.x;
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
if ((objects[i].pos.y == (canvasHeight - 8)) || (objects[i].pos.y == 0))
objects[i].speed.y = -objects[i].speed.y;
}
/* Clear canvas surface */
canvas.fillScreen(0);
/* Draw line */
canvas.drawLine( 0, 0, canvasWidth*2 - 1, canvasHeight-1, 1);
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
canvas.drawRect(0, 0, canvasWidth, canvasHeight, 1);
/* Draw all 4 sprites on the canvas */
for (uint8_t i = 0; i < spritesCount; i++)
{
canvas.drawBitmap( objects[i].pos.x, objects[i].pos.y, heartImage, 8, 8, 1 );
}
/* Now, draw canvas on the display. You will find, that *
* using AdafruitCanvas1 is similar to NanoCanvas1 */
canvas.blt(0, 0);
}

View File

@@ -0,0 +1,137 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
#include "nano_engine.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is define from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
/* Lets show 4 hearts on the display */
const int spritesCount = 4;
/* Declare variable that represents our 4 objects */
struct
{
NanoPoint pos;
NanoPoint speed;
} objects[ spritesCount ];
/*
* Each pixel in SSD1306 display takes 1 bit of the memory. So, full resolution
* of 128x64 LCD display will require 128*64/8 = 1024 bytes of SRAM for the buffer.
* To let this example to run on Attiny devices (they have 256/512 byte SRAM), we
* will use small canvas buffer: 32x32 (requires 128 bytes of SRAM), so the example
* would run even on Attiny45.
*/
const int canvasWidth = 32; // Width must be power of 2, i.e. 16, 32, 64, 128...
const int canvasHeight = 32; // Height must be divided on 8, i.e. 8, 16, 24, 32...
uint8_t canvasData[canvasWidth*(canvasHeight/8)];
/* Create canvas object */
NanoCanvas1 canvas(canvasWidth, canvasHeight, canvasData);
void setup()
{
/* Initialize and clear display */
ssd1306_128x64_i2c_init();
// ssd1306_128x64_spi_init(3, 4, 5);
// pcd8544_84x48_spi_init(3, 4, 5); // 3 RST, 4 CES, 5 DS
// ssd1331_96x64_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(3, 4, 5);
// il9163_128x128_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, 4, 5);
ssd1306_fillScreen(0x00);
/* Create 4 "hearts", and place them at different positions and give different movement direction */
for(uint8_t i = 0; i < spritesCount; i++)
{
objects[i].speed = { .x = (i & 1) ? -1: 1, .y = (i & 2) ? -1: 1 };
objects[i].pos = { .x = i*4, .y = i*4 + 2 };
}
canvas.setMode( CANVAS_MODE_TRANSPARENT );
}
void loop()
{
delay(40);
/* Recalculate position and movement direction of all 4 "hearts" */
for (uint8_t i = 0; i < spritesCount; i++)
{
objects[i].pos += objects[i].speed;
/* If left or right boundary is reached, reverse X direction */
if ((objects[i].pos.x == (canvasWidth - 8)) || (objects[i].pos.x == 0))
objects[i].speed.x = -objects[i].speed.x;
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
if ((objects[i].pos.y == (canvasHeight - 8)) || (objects[i].pos.y == 0))
objects[i].speed.y = -objects[i].speed.y;
}
/* Clear canvas surface */
canvas.clear();
/* Draw line */
canvas.drawLine( 0, 0, canvasWidth*2 - 1, canvasHeight-1);
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
canvas.drawRect(0, 0, canvasWidth-1, canvasHeight-1);
/* Draw all 4 sprites on the canvas */
for (uint8_t i = 0; i < spritesCount; i++)
{
canvas.drawBitmap1( objects[i].pos.x, objects[i].pos.y, 8, 8, heartImage );
}
/* Now, draw canvas on the display */
canvas.blt(48, 0);
}

View File

@@ -0,0 +1,154 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
// Define this before including library header, this will give Adafruit GFX support
// !!! Don't forget to install AdafruitGFX library to your Arduino IDE !!!
#define CONFIG_ADAFRUIT_GFX_ENABLE
#include "ssd1306.h"
#include "nano_engine.h"
// No need to include this for Arduino sketch
#ifndef ARDUINO
extern "C" void __cxa_pure_virtual() { while (1); }
#endif
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is define from left to rigth (bits), from top to
* bottom (bytes). Unlike NanoCanvas1 of ssd1306 library, Adafruit
* GFX implementation uses different aproach for images, stored in Flash.
*/
const PROGMEM uint8_t heartImage[8] =
{
0B01100110,
0B11111001,
0B11111101,
0B11111111,
0B01111110,
0B00111100,
0B00011000,
0B00000000
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
/* Lets show 4 hearts on the display */
const int spritesCount = 4;
/* Declare variable that represents our 4 objects */
struct
{
NanoPoint pos;
NanoPoint speed;
} objects[ spritesCount ];
/*
* Each pixel in rgb16 mode needs 16 bit of the memory. So, full resolution
* of 128x128 LCD display will require 128*128*2 = 32768 bytes of SRAM for the buffer.
* To let this example to run on Atmega328p devices (they have 2048 byte SRAM), we
* will use small canvas buffer: 32x16 (requires 1024 bytes of SRAM).
*/
const int canvasWidth = 32; // Width
const int canvasHeight = 16; // Height
uint8_t canvasData[canvasWidth*canvasHeight*2];
/* Create canvas object */
AdafruitCanvas16 canvas(canvasWidth, canvasHeight, canvasData);
void setup()
{
/* Initialize and clear display: 3 RST, 4 CES, 5 DS */
il9163_128x128_spi_init(3, 4, 5);
// ssd1331_96x64_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, 4, 5);
// -- ssd1306_128x64_i2c_init(); // RGB canvas does not support monochrome displays
// -- pcd8544_84x48_spi_init(3, 4, 5);
/* The library should be switched to normal mode for RGB displays */
ssd1306_setMode(LCD_MODE_NORMAL);
ssd1306_fillScreen(0x00);
/* Create 4 "hearts", and place them at different positions and give different movement direction */
for(uint8_t i = 0; i < spritesCount; i++)
{
objects[i].speed = { .x = (i & 2) ? -1: 1, .y = (i & 1) ? -1: 1 };
objects[i].pos = { .x = i*4, .y = i*2 + 2 };
}
}
static uint16_t s_colors[spritesCount] =
{
RGB_COLOR16(255,0,0),
RGB_COLOR16(0,255,0),
RGB_COLOR16(0,0,255),
RGB_COLOR16(255,255,0),
};
void loop()
{
delay(40);
/* Recalculate position and movement direction of all 4 "hearts" */
for (uint8_t i = 0; i < spritesCount; i++)
{
objects[i].pos += objects[i].speed;
/* If left or right boundary is reached, reverse X direction */
if ((objects[i].pos.x == (canvasWidth - 8)) || (objects[i].pos.x == 0))
objects[i].speed.x = -objects[i].speed.x;
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
if ((objects[i].pos.y == (canvasHeight - 8)) || (objects[i].pos.y == 0))
objects[i].speed.y = -objects[i].speed.y;
}
/* Clear canvas surface */
canvas.fillScreen(0);
/* Draw line */
canvas.drawLine( 0, 0, canvasWidth*2 - 1, canvasHeight-1, RGB_COLOR16(128,128,128));
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
canvas.drawRect(0, 0, canvasWidth, canvasHeight, RGB_COLOR16(0,255,255));
/* Draw all 4 sprites on the canvas */
for (uint8_t i = 0; i < spritesCount; i++)
{
canvas.drawBitmap( objects[i].pos.x, objects[i].pos.y, heartImage, 8, 8, s_colors[i] );
}
/* Now, draw canvas on the display */
canvas.blt(48, 0);
}

View File

@@ -0,0 +1,154 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
// Define this before including library header, this will give Adafruit GFX support
// !!! Don't forget to install AdafruitGFX library to your Arduino IDE !!!
#define CONFIG_ADAFRUIT_GFX_ENABLE
#include "ssd1306.h"
#include "nano_engine.h"
// No need to include this for Arduino sketch
#ifndef ARDUINO
extern "C" void __cxa_pure_virtual() { while (1); }
#endif
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is define from left to rigth (bits), from top to
* bottom (bytes). Unlike NanoCanvas1 of ssd1306 library, Adafruit
* GFX implementation uses different aproach for images, stored in Flash.
*/
const PROGMEM uint8_t heartImage[8] =
{
0B01100110,
0B11111001,
0B11111101,
0B11111111,
0B01111110,
0B00111100,
0B00011000,
0B00000000
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
/* Lets show 4 hearts on the display */
const int spritesCount = 4;
/* Declare variable that represents our 4 objects */
struct
{
NanoPoint pos;
NanoPoint speed;
} objects[ spritesCount ];
/*
* Each pixel in rgb8 mode needs 8 bit of the memory. So, full resolution
* of 128x128 LCD display will require 128*128 = 16384 bytes of SRAM for the buffer.
* To let this example to run on Atmega328p devices (they have 2048 byte SRAM), we
* will use small canvas buffer: 32x32 (requires 1024 bytes of SRAM).
*/
const int canvasWidth = 32; // Width
const int canvasHeight = 32; // Height
uint8_t canvasData[canvasWidth*canvasHeight];
/* Create canvas object */
AdafruitCanvas8 canvas(canvasWidth, canvasHeight, canvasData);
void setup()
{
/* Initialize and clear display: 3 RST, 4 CES, 5 DS */
il9163_128x128_spi_init(3, 4, 5);
// ssd1331_96x64_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, 4, 5);
// -- ssd1306_128x64_i2c_init(); // RGB canvas does not support monochrome displays
// -- pcd8544_84x48_spi_init(3, 4, 5);
/* The library should be switched to normal mode for RGB displays */
ssd1306_setMode(LCD_MODE_NORMAL);
ssd1306_fillScreen(0x00);
/* Create 4 "hearts", and place them at different positions and give different movement direction */
for(uint8_t i = 0; i < spritesCount; i++)
{
objects[i].speed = { .x = (i & 2) ? -1: 1, .y = (i & 1) ? -1: 1 };
objects[i].pos = { .x = i*4, .y = i*4 + 2 };
}
}
static uint8_t s_colors[spritesCount] =
{
RGB_COLOR8(255,0,0),
RGB_COLOR8(0,255,0),
RGB_COLOR8(0,0,255),
RGB_COLOR8(255,255,0),
};
void loop()
{
delay(40);
/* Recalculate position and movement direction of all 4 "hearts" */
for (uint8_t i = 0; i < spritesCount; i++)
{
objects[i].pos += objects[i].speed;
/* If left or right boundary is reached, reverse X direction */
if ((objects[i].pos.x == (canvasWidth - 8)) || (objects[i].pos.x == 0))
objects[i].speed.x = -objects[i].speed.x;
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
if ((objects[i].pos.y == (canvasHeight - 8)) || (objects[i].pos.y == 0))
objects[i].speed.y = -objects[i].speed.y;
}
/* Clear canvas surface */
canvas.fillScreen( 0 );
/* Draw line */
canvas.drawLine( 0, 0, canvasWidth*2 - 1, canvasHeight-1, RGB_COLOR8(128,128,128));
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
canvas.drawRect(0, 0, canvasWidth, canvasHeight, RGB_COLOR8(0,255,255));
/* Draw all 4 sprites on the canvas */
for (uint8_t i = 0; i < spritesCount; i++)
{
canvas.drawBitmap( objects[i].pos.x, objects[i].pos.y, heartImage, 8, 8, s_colors[i] );
}
/* Now, draw canvas on the display */
canvas.blt(48, 0);
}

View File

@@ -0,0 +1,148 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
#include "nano_engine.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is define from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
/* Lets show 4 hearts on the display */
const int spritesCount = 4;
/* Declare variable that represents our 4 objects */
struct
{
NanoPoint pos;
NanoPoint speed;
} objects[ spritesCount ];
/*
* Each pixel in rgb16 mode needs 16 bit of the memory. So, full resolution
* of 128x128 LCD display will require 128*128*2 = 32768 bytes of SRAM for the buffer.
* To let this example to run on Atmega328p devices (they have 2048 byte SRAM), we
* will use small canvas buffer: 32x16 (requires 1024 bytes of SRAM).
*/
const int canvasWidth = 32; // Width
const int canvasHeight = 16; // Height
uint8_t canvasData[canvasWidth*canvasHeight*2];
/* Create canvas object */
NanoCanvas16 canvas(canvasWidth, canvasHeight, canvasData);
void setup()
{
/* Initialize and clear display: 3 RST, 4 CES, 5 DS */
il9163_128x128_spi_init(3, 4, 5);
// ssd1331_96x64_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, 4, 5);
// -- ssd1306_128x64_i2c_init(); // RGB canvas does not support monochrome displays
// -- pcd8544_84x48_spi_init(3, 4, 5);
/* The library should be switched to normal mode for RGB displays */
ssd1306_setMode(LCD_MODE_NORMAL);
ssd1306_fillScreen(0x00);
/* Create 4 "hearts", and place them at different positions and give different movement direction */
for(uint8_t i = 0; i < spritesCount; i++)
{
objects[i].speed = { .x = (i & 2) ? -1: 1, .y = (i & 1) ? -1: 1 };
objects[i].pos = { .x = i*4, .y = i*2 + 2 };
}
canvas.setMode( CANVAS_MODE_TRANSPARENT );
}
static uint16_t s_colors[spritesCount] =
{
RGB_COLOR16(255,0,0),
RGB_COLOR16(0,255,0),
RGB_COLOR16(0,0,255),
RGB_COLOR16(255,255,0),
};
void loop()
{
delay(40);
/* Recalculate position and movement direction of all 4 "hearts" */
for (uint8_t i = 0; i < spritesCount; i++)
{
objects[i].pos += objects[i].speed;
/* If left or right boundary is reached, reverse X direction */
if ((objects[i].pos.x == (canvasWidth - 8)) || (objects[i].pos.x == 0))
objects[i].speed.x = -objects[i].speed.x;
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
if ((objects[i].pos.y == (canvasHeight - 8)) || (objects[i].pos.y == 0))
objects[i].speed.y = -objects[i].speed.y;
}
/* Clear canvas surface */
canvas.clear();
/* Draw line */
canvas.setColor( RGB_COLOR16(128,128,128) );
canvas.drawLine( 0, 0, canvasWidth*2 - 1, canvasHeight-1);
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
canvas.setColor( RGB_COLOR16(0,255,255) );
canvas.drawRect(0, 0, canvasWidth-1, canvasHeight-1);
/* Draw all 4 sprites on the canvas */
for (uint8_t i = 0; i < spritesCount; i++)
{
canvas.setColor( s_colors[i] );
canvas.drawBitmap1( objects[i].pos.x, objects[i].pos.y, 8, 8, heartImage );
}
/* Now, draw canvas on the display */
canvas.blt(48, 0);
}

View File

@@ -0,0 +1,148 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2)
* SDA (4) -| |- (1)
* GND -|____|- (0)
*
* Atmega328 PINS: connect LCD to A4/A5
*/
#include "ssd1306.h"
#include "nano_engine.h"
/*
* Heart image below is defined directly in flash memory.
* This reduces SRAM consumption.
* The image is define from bottom to top (bits), from left to
* right (bytes).
*/
const PROGMEM uint8_t heartImage[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
/*
* Define sprite width. The width can be of any size.
* But sprite height is always assumed to be 8 pixels
* (number of bits in single byte).
*/
const int spriteWidth = sizeof(heartImage);
/* Lets show 4 hearts on the display */
const int spritesCount = 4;
/* Declare variable that represents our 4 objects */
struct
{
NanoPoint pos;
NanoPoint speed;
} objects[ spritesCount ];
/*
* Each pixel in rgb8 mode needs 8 bit of the memory. So, full resolution
* of 128x128 LCD display will require 128*128 = 16384 bytes of SRAM for the buffer.
* To let this example to run on Atmega328p devices (they have 2048 byte SRAM), we
* will use small canvas buffer: 32x32 (requires 1024 bytes of SRAM).
*/
const int canvasWidth = 32; // Width
const int canvasHeight = 32; // Height
uint8_t canvasData[canvasWidth*canvasHeight];
/* Create canvas object */
NanoCanvas8 canvas(canvasWidth, canvasHeight, canvasData);
void setup()
{
/* Initialize and clear display: 3 RST, 4 CES, 5 DS */
il9163_128x128_spi_init(3, 4, 5);
// ssd1331_96x64_spi_init(3, 4, 5);
// ssd1351_128x128_spi_init(3, 4, 5);
// st7735_128x160_spi_init(3, 4, 5);
// -- ssd1306_128x64_i2c_init(); // RGB canvas does not support monochrome displays
// -- pcd8544_84x48_spi_init(3, 4, 5);
/* The library should be switched to normal mode for RGB displays */
ssd1306_setMode(LCD_MODE_NORMAL);
ssd1306_fillScreen(0x00);
/* Create 4 "hearts", and place them at different positions and give different movement direction */
for(uint8_t i = 0; i < spritesCount; i++)
{
objects[i].speed = { .x = (i & 2) ? -1: 1, .y = (i & 1) ? -1: 1 };
objects[i].pos = { .x = i*4, .y = i*4 + 2 };
}
canvas.setMode( CANVAS_MODE_TRANSPARENT );
}
static uint8_t s_colors[spritesCount] =
{
RGB_COLOR8(255,0,0),
RGB_COLOR8(0,255,0),
RGB_COLOR8(0,0,255),
RGB_COLOR8(255,255,0),
};
void loop()
{
delay(40);
/* Recalculate position and movement direction of all 4 "hearts" */
for (uint8_t i = 0; i < spritesCount; i++)
{
objects[i].pos += objects[i].speed;
/* If left or right boundary is reached, reverse X direction */
if ((objects[i].pos.x == (canvasWidth - 8)) || (objects[i].pos.x == 0))
objects[i].speed.x = -objects[i].speed.x;
/* Sprite height is always 8 pixels. Reverse Y direction if bottom or top boundary is reached. */
if ((objects[i].pos.y == (canvasHeight - 8)) || (objects[i].pos.y == 0))
objects[i].speed.y = -objects[i].speed.y;
}
/* Clear canvas surface */
canvas.clear();
/* Draw line */
canvas.setColor( RGB_COLOR8(128,128,128) );
canvas.drawLine( 0, 0, canvasWidth*2 - 1, canvasHeight-1);
/* Draw rectangle around our canvas. It will show the range of the canvas on the display */
canvas.setColor( RGB_COLOR8(0,255,255) );
canvas.drawRect(0, 0, canvasWidth-1, canvasHeight-1);
/* Draw all 4 sprites on the canvas */
for (uint8_t i = 0; i < spritesCount; i++)
{
canvas.setColor( s_colors[i] );
canvas.drawBitmap1( objects[i].pos.x, objects[i].pos.y, 8, 8, heartImage );
}
/* Now, draw canvas on the display */
canvas.blt(48, 0);
}

View File

@@ -0,0 +1,55 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#ifdef SDL_EMULATION
#include "sdl_core.h"
#endif
extern void setup(void);
extern void loop(void);
#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
void main_task(void *args)
{
setup();
for(;;) {
loop();
#ifdef SDL_EMULATION
sdl_read_analog(0);
#endif
}
}
extern "C" void app_main(void)
{
xTaskCreatePinnedToCore(main_task, "mainTask", 8192, NULL, 1, NULL, ARDUINO_RUNNING_CORE);
}

View File

@@ -0,0 +1,27 @@
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const unsigned char arkanoid_2 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0xFC, 0x00, 0xFC, 0x04, 0xE4,
0x28, 0xA4, 0x4C, 0x18, 0xB0, 0xE0, 0x40, 0x00, 0xFC, 0x04, 0xFC, 0x00, 0x00, 0x80, 0xC0, 0x60,
0xB0, 0xE0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0xFC, 0x00, 0xFC,
0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x04, 0xFC, 0x00, 0x80, 0xE0, 0x30,
0xD0, 0x78, 0x28, 0x38, 0x1C, 0x14, 0x14, 0x1C, 0x38, 0x28, 0x78, 0xD0, 0x30, 0xE0, 0x80, 0x00,
0xFC, 0x04, 0xFC, 0x00, 0xFC, 0x04, 0xFC, 0x04, 0x0E, 0x9B, 0xF6, 0x0C, 0x98, 0xF0, 0x60, 0x00,
0x00, 0x30, 0x78, 0xFC, 0xFE, 0xFF, 0xCD, 0x84, 0x02, 0xFC, 0xFE, 0xFF, 0x00, 0xFF, 0x7C, 0x3F,
0x1D, 0x1C, 0x3E, 0x7B, 0xF1, 0xE0, 0x40, 0x00, 0xFF, 0x7C, 0x3F, 0x1E, 0x1F, 0x3F, 0x7E, 0xFB,
0xF1, 0xE0, 0x40, 0x30, 0x78, 0xFC, 0xFE, 0xFF, 0xCD, 0x84, 0x02, 0xFC, 0xFE, 0xFF, 0x00, 0xFF,
0xFC, 0xFE, 0x02, 0x06, 0x0D, 0x1F, 0x3E, 0x7C, 0xF8, 0xFF, 0xFC, 0x7F, 0x00, 0x0F, 0x3C, 0x7F,
0x78, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0x78, 0x7F, 0x3C, 0x0F, 0x00,
0xFF, 0xFC, 0x7F, 0x00, 0xFF, 0xFC, 0x7F, 0x3E, 0x1F, 0x0D, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

View File

@@ -0,0 +1,800 @@
/*
MIT License
Copyright (c) 2016-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
* This game is based on original game, developed by Ilya Titov in 2014.
* It can be still flashed to http://webboggles.com/attiny85-breakout-keychain-game/ HW.
*/
/*
* Attiny85 PINS
* ____
* RESET -|_| |- 3V
* SCL (3) -| |- (2) LEFT
* SDA (4) -| |- (1) BUZZER
* GND -|____|- (0) RIGHT
*
*
* ATMEL ATMEGA8 & 168 & 328 / ARDUINO NANO
*
* ____
* 10kOm PC6 1|_| |28 PC5
* PD0 2| |27 PC4
* PD1 3| |26 PC3
* RIGHT(D 2) PD2 4| |25 PC2
* BUZZ (D 3) PD3 5| |24 PC1
* LEFT (D 4) PD4 6| |23 PC0 Z-KEYPAD (A 0) if USE_Z_KEYPAD is defined (refer to buttons.h)
* VCC 7| |22 GND
* GND 8| |21 AREF
* BUZZ (D 6) PB6 9| |20 AVCC
* PB7 10| |19 PB5
* PD5 11| |18 PB4
* PD6 12| |17 PB3
* PD7 13| |16 PB2
* PB0 14|____|15 PB1
*
* IMPORTANT!!! D6 is used instead of D3 with SSD1331 display mode
*/
#include "ssd1306.h"
#include "intf/ssd1306_interface.h"
#include "intf/i2c/ssd1306_i2c.h"
#include "lcd/lcd_common.h"
#include <stdlib.h>
//#define ARKANOID_SSD1331
#if defined(ESP32) || defined(ESP8266) || (defined(__linux__)) || defined(__MINGW32__)
#define DEEP_SLEEP_NOT_SUPPORTED
#endif
#include "levels.h"
#include "blocks.h"
#include "sprites.h"
#include "arkanoid.h"
#include "buttons.h"
typedef struct
{
SPRITE sprite;
uint8_t type;
uint8_t extra;
} GameObject;
uint16_t *EEPROM_ADDR = (uint16_t*)0;
#if defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__)
# define BUZZER 1
#else // For Arduino Nano/Atmega328 we use different pins
# ifdef ARKANOID_SSD1331
# define BUZZER 6
# else
# define BUZZER 3
# endif
#endif
const int LEFT_EDGE = 0;
#ifdef ARKANOID_SSD1331
const int RIGHT_EDGE = (96 - 14);
const int SCREEN_WIDTH = (96 - 16);
const uint8_t OUTPUT_OFFSET = 16;
#else
const int RIGHT_EDGE = (128 - 14);
const int SCREEN_WIDTH = (128 - 16);
const uint8_t OUTPUT_OFFSET = 0;
#endif
const int SCREEN_HEIGHT = 64;
const int BLOCK_WIDTH = 16;
const int PLATFORM_HEIGHT = 10;
const int INITIAL_PLATFORM_WIDTH = 16;
const int INITIAL_H_SPEED = -1;
const int INITIAL_V_SPEED = -4;
const int PLATFORM_SPEED = 1;
const int MAX_GAME_OBJECTS = 4;
const int PLATFORM_ROW = 7;
const uint8_t SPEED_SHIFT = 2;
uint8_t platformPos; // platform position
bool updateStatusPanel; // Set to true if status panel update is required
static const int platformWidth = INITIAL_PLATFORM_WIDTH;
int ballx;
int bally;
int8_t vSpeed;
int8_t hSpeed;
uint8_t hearts;
uint16_t lastDrawTimestamp;
uint8_t gameField[BLOCK_NUM_ROWS][MAX_BLOCKS_PER_ROW];
GameObject objects[MAX_GAME_OBJECTS];
uint16_t score;
uint8_t level = 1;
uint8_t blocksLeft = 0;
uint8_t platformPower;
void nextLevel();
void beep(int bCount,int bDelay);
void movePlatform();
bool moveObjects();
void drawBall(uint8_t lastx, uint8_t lasty);
bool moveBall();
void drawObjects();
void system_sleep();
void onKill();
static char tempStr[4] = {0};
void arkanoidUtoa(uint16_t b)
{
utoa(b,tempStr,10);
}
void drawIntro()
{
#ifdef ARKANOID_SSD1331
ssd1331_96x64_spi_init(3,4,5);
#elif defined(__AVR_ATtiny85__)
ssd1306_i2cInitEx(-1,-1,0);
#elif defined(CONFIG_SOFTWARE_I2C_AVAILABLE)
ssd1306_i2cInit_Embedded(-1,-1,0);
#elif defined(CONFIG_PLATFORM_I2C_AVAILABLE)
ssd1306_platform_i2cInit(-1,0,-1);
#elif defined(CONFIG_TWI_I2C_AVAILABLE)
ssd1306_i2cInit_Twi(0);
#else
#error "Not supported microcontroller or board"
#endif
#ifndef ARKANOID_SSD1331
ssd1306_128x64_init();
#endif
ssd1306_clearScreen( );
ssd1306_setColor(RGB_COLOR8(255,0,0));
for (int8_t y=-24; y<16; y++)
{
gfx_drawMonoBitmap(16 - OUTPUT_OFFSET, y, 96, 24, arkanoid_2);
delay(20);
}
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_printFixed_oldStyle(40 - OUTPUT_OFFSET, 40, "BREAKOUT", STYLE_NORMAL);
beep(200,600);
beep(300,200);
beep(400,300);
}
void drawStatusPanel()
{
ssd1306_setColor(RGB_COLOR8(255,0,0));
for(uint8_t i=0; i<min(hearts,3); i++)
{
SPRITE heart = ssd1306_createSprite( RIGHT_EDGE + 4, 16 + (i<<3), 8, heartSprite );
heart.draw();
}
ssd1306_setColor(RGB_COLOR8(255,255,0));
arkanoidUtoa(score);
tempStr[2] = '\0';
ssd1306_printFixed_oldStyle(RIGHT_EDGE + 1, 8, tempStr, STYLE_NORMAL);
ssd1306_setColor(RGB_COLOR8(0,255,255));
SPRITE power = ssd1306_createSprite( RIGHT_EDGE + 4, 40, 8, powerSprite );
if (platformPower)
power.draw();
else
power.erase();
}
/* Draws and clears platform */
void drawPlatform()
{
uint8_t pos = (platformPos < PLATFORM_SPEED) ? 0: (platformPos - PLATFORM_SPEED);
ssd1306_setColor(RGB_COLOR8(255,255,0));
ssd1306_lcd.set_block( pos + LEFT_EDGE + 1, PLATFORM_ROW, platformWidth + PLATFORM_SPEED * 2 );
while (pos < platformPos)
{
ssd1306_lcd.send_pixels1(0B00000000);
pos++;
}
ssd1306_lcd.send_pixels1(0B00001110);
pos++;
while (pos < platformPos + platformWidth - 1)
{
ssd1306_lcd.send_pixels1(0B00000111);
pos++;
}
ssd1306_lcd.send_pixels1(0B00001110);
while (pos < platformPos + platformWidth + PLATFORM_SPEED - 1)
{
if (pos >= (RIGHT_EDGE - LEFT_EDGE - 2))
{
break;
}
ssd1306_lcd.send_pixels1(0B00000000);
pos++;
}
ssd1306_intf.stop();
}
void drawFieldEdges()
{
uint8_t i=8;
ssd1306_setColor(RGB_COLOR8(255,0,0));
while (i)
{
i--;
ssd1306_lcd.set_block(LEFT_EDGE, i, 1);
ssd1306_lcd.send_pixels1( 0B01010101 );
ssd1306_intf.stop();
ssd1306_lcd.set_block(RIGHT_EDGE, i, 1);
ssd1306_lcd.send_pixels1( 0B01010101 );
ssd1306_intf.stop();
}
}
void drawBlock(uint8_t x, uint8_t y)
{
uint8_t block = gameField[y][x];
switch(block)
{
case 1: ssd1306_setColor(RGB_COLOR8(64,64,255)); break;
case 2: ssd1306_setColor(RGB_COLOR8(64,255,255)); break;
case 3: ssd1306_setColor(RGB_COLOR8(64,255,64)); break;
default: ssd1306_setColor(RGB_COLOR8(64,64,255)); break;
}
ssd1306_drawSpriteEx(LEFT_EDGE + 1 + (x << 4), y, 16, &blockImages[block][0]);
}
void resetBlocks()
{
if (level > MAX_LEVELS)
{
level = MAX_LEVELS;
}
blocksLeft = 0;
for (uint8_t i =0; i<BLOCKS_PER_ROW; i++)
{
for (uint8_t j=0; j<BLOCK_NUM_ROWS; j++)
{
gameField[j][i] = pgm_read_byte( &levels[level-1][j][i] );
if ((gameField[j][i]) && (gameField[j][i] != BLOCK_STRONG))
{
blocksLeft++;
}
}
}
}
void drawBlocks()
{
for (uint8_t r=0; r<BLOCK_NUM_ROWS; r++)
{
for (uint8_t bl = 0; bl<BLOCKS_PER_ROW; bl++)
{
drawBlock(bl, r);
}
}
}
void drawStartScreen()
{
ssd1306_clearScreen( );
drawBlocks();
drawFieldEdges();
updateStatusPanel = true;
}
void startLevel()
{
ssd1306_setColor(RGB_COLOR8(255,128,0));
arkanoidUtoa(level);
ssd1306_clearScreen();
ssd1306_printFixed_oldStyle(40 - OUTPUT_OFFSET, 24, "LEVEL ", STYLE_BOLD);
ssd1306_printFixed_oldStyle(76 - OUTPUT_OFFSET, 24, tempStr, STYLE_BOLD);
delay(2000);
resetBlocks();
hSpeed = INITIAL_H_SPEED;
vSpeed = INITIAL_V_SPEED;
platformPos = random(0, (RIGHT_EDGE - LEFT_EDGE - 1 - platformWidth));
ballx = ( platformPos + ( platformWidth >> 1 ) ) << SPEED_SHIFT;
bally = ( SCREEN_HEIGHT - PLATFORM_HEIGHT ) << SPEED_SHIFT;
memset(&objects[0], 0, sizeof(objects));
drawStartScreen();
lastDrawTimestamp = millis();
}
void resetGame()
{
score = 0;
// platformWidth = INITIAL_PLATFORM_WIDTH;
platformPower = 0;
hearts = 2;
drawIntro();
delay(3000);
startLevel();
}
void setup()
{
ssd1306_setFixedFont_oldStyle(ssd1306xled_font6x8_AB);
randomSeed(analogRead(0));
#if defined(CONFIG_PLATFORM_I2C_AVAILABLE)
// no need to do anything here
#elif defined(ARKANOID_SSD1331)
#ifndef USE_Z_KEYPAD
pinMode(LEFT_BTN, INPUT);
pinMode(RIGHT_BTN, INPUT);
#endif
pinMode(BUZZER, OUTPUT);
sei(); // enable all interrupts
#elif defined(__AVR_ATtiny85__)
DDRB |= 0b00011010; // set PB1 as output (for the speaker), PB0 and PB2 as input
sei(); // enable all interrupts
#elif defined(CONFIG_ARDUINO_WIRE_LIBRARY_AVAILABLE)
Wire.begin();
#ifdef SSD1306_WIRE_CLOCK_CONFIGURABLE
Wire.setClock( 400000 );
#endif
#ifndef USE_Z_KEYPAD
pinMode(LEFT_BTN, INPUT);
pinMode(RIGHT_BTN, INPUT);
#endif
pinMode(BUZZER, OUTPUT);
sei(); // enable all interrupts
#elif defined(CONFIG_SOFTWARE_I2C_AVAILABLE)
#ifndef USE_Z_KEYPAD
pinMode(LEFT_BTN, INPUT);
pinMode(RIGHT_BTN, INPUT);
#endif
pinMode(BUZZER, OUTPUT);
sei(); // enable all interrupts
#else
#error "Not supported microcontroller or board"
#endif
resetGame();
}
void loop()
{
if ( (uint16_t)(((uint16_t)millis()) - lastDrawTimestamp) > 28 )
{
uint8_t lastx = (ballx >> SPEED_SHIFT);
uint8_t lasty = (bally >> SPEED_SHIFT);
lastDrawTimestamp += 28;
// continue moving after the interrupt
movePlatform();
// bounce off the sides of the screen
if (moveBall())
{
if (moveObjects())
{
// update whats on the screen
drawPlatform();
drawBall(lastx, lasty);
drawObjects();
}
}
if (updateStatusPanel)
{
updateStatusPanel = false;
drawStatusPanel();
}
}
}
void drawBall(uint8_t lastx, uint8_t lasty)
{
uint8_t newx = ballx >> SPEED_SHIFT;
uint8_t newy = bally >> SPEED_SHIFT;
uint8_t temp;
temp = 0B00000001 << (newy & 0x07);
ssd1306_setColor(RGB_COLOR8(255,255,255));
ssd1306_lcd.set_block(LEFT_EDGE + 1 + newx, newy >> 3, 1);
ssd1306_lcd.send_pixels1( temp );
ssd1306_intf.stop();
if ((newx != lastx) || ((newy >> 3) != (lasty >> 3)))
{
ssd1306_lcd.set_block(LEFT_EDGE + 1 + lastx, lasty >> 3, 1);
ssd1306_lcd.send_pixels1( 0B00000000 );
ssd1306_intf.stop();
}
}
void drawObjects()
{
ssd1306_setColor(RGB_COLOR8(255,0,192));
for(uint8_t i=0; i<MAX_GAME_OBJECTS; i++)
{
if (objects[i].type == 0)
{
}
else if (objects[i].type == 1)
{
objects[i].sprite.erase();
objects[i].type = 0;
}
else
{
objects[i].sprite.eraseTrace();
objects[i].sprite.draw();
}
}
}
uint8_t freeObject()
{
for(uint8_t i=0; i<MAX_GAME_OBJECTS; i++)
{
if (objects[i].type == 0) return i;
}
return 0xFF;
}
bool platformHit(uint8_t x, uint8_t y)
{
if (y >= (SCREEN_HEIGHT - PLATFORM_HEIGHT))
{
if ((x >= platformPos) && (x <= platformPos + platformWidth))
{
return true;
}
}
return false;
}
enum
{
BLOCK_HIT_NONE,
BLOCK_HIT_UNBREAKABLE,
BLOCK_HIT_BREAKABLE,
BLOCK_HIT_LEVEL_DONE,
};
uint8_t blockHit(uint8_t x, uint8_t y)
{
uint8_t ball_row = y>>3;
if (ball_row < BLOCK_NUM_ROWS)
{
uint8_t ball_col = x >> 4;
uint8_t blockType = gameField[ball_row][ball_col];
if ( blockType > 0 )
{
if (blockType != BLOCK_STRONG)
{
gameField[ball_row][ball_col] = 0;
score++;
blocksLeft--;
drawBlock(ball_col, ball_row);
updateStatusPanel = true;
if (blockType >= BLOCK_BONUS)
{
uint8_t i = freeObject();
if (i != 0xFF)
{
objects[i].sprite = ssd1306_createSprite( (ball_col << 4) + 6,
(ball_row << 3),
5,
&bonusSprites[blockType - BLOCK_BONUS][0] );
objects[i].extra = 0;
objects[i].type = blockType;
}
}
}
// reset blocks if all have been hit
if (blocksLeft == 0)
{
level++;
startLevel();
return BLOCK_HIT_LEVEL_DONE;
}
return (blockType == BLOCK_STRONG ? BLOCK_HIT_UNBREAKABLE : BLOCK_HIT_BREAKABLE);
}
}
return BLOCK_HIT_NONE;
}
bool moveObjects()
{
for(uint8_t i=0; i<MAX_GAME_OBJECTS; i++)
{
if (objects[i].type <= 1)
{
}
else if (objects[i].type < BLOCKS_MAX)
{
if (objects[i].sprite.y >= (SCREEN_HEIGHT - PLATFORM_HEIGHT - 4))
{
objects[i].type = 1;
}
else
{
if (objects[i].extra-- == 0)
{
objects[i].extra = 1;
if (platformHit(objects[i].sprite.x + 3, objects[i].sprite.y + 8))
{
if (objects[i].type == BLOCK_BOMB)
{
onKill();
return false;
}
else if (objects[i].type == BLOCK_HEART)
{
hearts++;
updateStatusPanel = true;
}
else if (objects[i].type == BLOCK_POWER)
{
platformPower = 255;
updateStatusPanel = true;
}
objects[i].type = 1;
}
objects[i].sprite.y++;
}
}
}
else if (objects[i].type == 0xFF)
{
if (objects[i].sprite.y <= 1)
{
objects[i].type = 1;
}
else
{
uint8_t hitType = blockHit( objects[i].sprite.x, objects[i].sprite.y - 1 );
if (hitType != BLOCK_HIT_NONE)
{
if (hitType == BLOCK_HIT_LEVEL_DONE)
{
return false;
}
objects[i].type = 1;
}
else
{
objects[i].sprite.y -= 1;
}
}
}
}
return true;
}
// continues moving after interrupt
void movePlatform()
{
// Use A0 ADC input (channel 0) if Z_KEYPAD is attached
uint8_t buttonCode = getPressedButton(0);
if (buttonCode == BUTTON_RIGHT)
{
platformPos = min(RIGHT_EDGE - LEFT_EDGE - 1 - platformWidth, platformPos + PLATFORM_SPEED);
}
if (buttonCode == BUTTON_LEFT)
{
platformPos = max(0, platformPos - PLATFORM_SPEED);
}
if (platformPower != 0)
{
platformPower--;
if (!(platformPower & 0x1F))
{
uint8_t i = freeObject();
if (i != 0xFF)
{
objects[i].sprite = ssd1306_createSprite( platformPos + (platformWidth >> 1),
SCREEN_HEIGHT - PLATFORM_HEIGHT - 8,
1,
shootSprite );
objects[i].extra = 0;
objects[i].type = 0xFF;
}
}
if (platformPower == 0) updateStatusPanel = true;
}
}
void gameOver()
{
ssd1306_setColor(RGB_COLOR8(255,255,255));
#if defined(ESP32) || defined(ESP8266)
uint16_t topScore = score;
#else
uint16_t topScore = eeprom_read_word(EEPROM_ADDR);
if (topScore == 0xFFFF)
{
eeprom_write_word(EEPROM_ADDR, 0);
topScore = 0;
}
if (score>topScore)
{
topScore = score;
eeprom_write_word(EEPROM_ADDR, topScore);
}
#endif
ssd1306_clearScreen( );
ssd1306_printFixed_oldStyle(32 - OUTPUT_OFFSET, 16, "GAME OVER", STYLE_NORMAL);
ssd1306_printFixed_oldStyle(32 - OUTPUT_OFFSET, 32, "SCORE ", STYLE_NORMAL);
arkanoidUtoa(score);
ssd1306_printFixed_oldStyle(70 - OUTPUT_OFFSET, 32, tempStr, STYLE_NORMAL);
ssd1306_printFixed_oldStyle(32 - OUTPUT_OFFSET, 40, "TOP SCORE ", STYLE_NORMAL);
arkanoidUtoa(topScore);
ssd1306_printFixed_oldStyle(90 - OUTPUT_OFFSET, 40, tempStr, STYLE_NORMAL);
for (int i = 0; i<1000; i++)
{
beep(1,random(0,i*2));
}
delay(2000);
}
void platformCrashAnimation()
{
for (uint8_t j = 4; j > 0; j--)
{
for ( uint8_t i = 0; i < platformWidth >> 2; i++ )
{
ssd1306_lcd.set_block( platformPos + ((j & 0x01)<<1) + ((j & 0x02)>>1) + (i<<2) + LEFT_EDGE + 1, PLATFORM_ROW, platformWidth );
ssd1306_lcd.send_pixels1( 0B00000000 );
ssd1306_intf.stop();
}
delay(150);
}
}
void onKill()
{
platformCrashAnimation();
if (hearts == 0)
{
// game over if the ball misses the platform
gameOver();
system_sleep();
level = 1;
resetGame();
}
else
{
hearts--;
startLevel();
}
}
// the collsision check is actually done before this is called, this code works
// out where the ball will bounce
void collision(uint8_t partx, uint8_t party)
{
/* botton / top collision */
if ((party <= 0) || (party >= 7))
{
vSpeed = -vSpeed;
}
else if ((partx <= 0) || (partx >= 15))
{
hSpeed = -hSpeed;
}
beep(30,300);
}
// move and bounce the ball when reaches the screen limits
bool moveBall()
{
uint8_t nextx = (ballx + hSpeed) >> SPEED_SHIFT;
uint8_t nexty = (bally + vSpeed) >> SPEED_SHIFT;
/* checkplatform Hit */
if (platformHit(nextx, nexty))
{
int middle = platformPos + (platformWidth >> 1);
hSpeed = (nextx - middle) / (platformWidth >> (SPEED_SHIFT + 1));
vSpeed = -max(4 - abs(hSpeed), 2);
beep(20,600);
}
/* Check screen hit */
nextx = (ballx + hSpeed) >> SPEED_SHIFT;
nexty = (bally + vSpeed) >> SPEED_SHIFT;
if ((nextx <= 0) || (nextx >= RIGHT_EDGE - LEFT_EDGE - 1))
{
hSpeed = -hSpeed;
}
if (nexty <= 0)
{
vSpeed = -vSpeed;
}
/* Check game over */
if (nexty >=(SCREEN_HEIGHT - PLATFORM_HEIGHT + 2))
{
onKill();
return false;
}
ballx += hSpeed;
bally += vSpeed;
/* Check bar hit */
uint8_t hitType = blockHit( ballx >> SPEED_SHIFT, bally >> SPEED_SHIFT );
if (hitType != BLOCK_HIT_NONE)
{
if (hitType == BLOCK_HIT_LEVEL_DONE)
{
return false;
}
if (hitType == BLOCK_HIT_UNBREAKABLE)
{
ballx -= hSpeed;
bally -= vSpeed;
}
uint8_t partx = (ballx >> SPEED_SHIFT) & 0x0F;
uint8_t party = (bally >> SPEED_SHIFT) & 0x07;
collision(partx, party);
}
return true;
}
void beep(int bCount,int bDelay)
{
for (int i = bCount*2; i>0; i--)
{
digitalWrite(BUZZER, i & 1);
for(int i2 = 0; i2 < bDelay; i2++)
{
__asm__("nop\n\t");
#if F_CPU > 8000000
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
__asm__("nop\n\t");
#endif
}
}
digitalWrite(BUZZER,LOW);
}
#ifdef DEEP_SLEEP_NOT_SUPPORTED
void system_sleep()
{
}
#else
void system_sleep()
{
ssd1306_clearScreen( );
ssd1306_displayOff();
ADCSRA &= ~(1<<ADEN);
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable();
sleep_mode(); // System actually sleeps here
sleep_disable(); // System continues execution here when watchdog timed out
ADCSRA |= (1<<ADEN);
ssd1306_displayOn();
}
#endif

View File

@@ -0,0 +1,171 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
enum
{
NO_BLOCK, // 0
BLOCK_SIMPLE, // 1
BLOCK_DASHED, // 2
BLOCK_STRONG, // 3
BLOCK_BOMB, // 4
BLOCK_HEART, // 5
BLOCK_POWER, // 6
BLOCKS_MAX,
BLOCK_BONUS = BLOCK_BOMB,
};
const PROGMEM uint8_t blockImages[BLOCKS_MAX][16] =
{
{ /* EMPTY */
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000,
0B00000000
},
{ /* SIMPLE 1 */
0B00000000,
0B00111100,
0B01111110,
0B01100110,
0B01100110,
0B01100110,
0B01100110,
0B01100110,
0B01100110,
0B01100110,
0B01100110,
0B01100110,
0B01100110,
0B01111110,
0B00111100,
0B00000000
},
{ /* DASHED 2 */
0B00000000,
0B00111100,
0B01010010,
0B01001010,
0B01100110,
0B01010010,
0B01001010,
0B01100110,
0B01010010,
0B01001010,
0B01100110,
0B01010010,
0B01001010,
0B01100110,
0B00111100,
0B00000000
},
{ /* STRONG 3 */
0B00000000,
0B00111100,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B00111100,
0B00000000
},
{ /* BOMB 4 */
0B00000000,
0B00111100,
0B01111110,
0B01111110,
0B01011010,
0B01011010,
0B01100110,
0B01100110,
0B01011010,
0B01011010,
0B01111110,
0B01111110,
0B01111010,
0B01110110,
0B00111100,
0B00000000
},
{ /* HEART 5 */
0B00000000,
0B00111100,
0B01111110,
0B01111110,
0B01111110,
0B01110110,
0B01100010,
0B01000110,
0B01100010,
0B01110110,
0B01111110,
0B01111110,
0B01111110,
0B01111110,
0B00111100,
0B00000000
},
{ /* POWER 6 */
0B00000000,
0B00111100,
0B01111110,
0B01111110,
0B01000010,
0B01101010,
0B01101010,
0B01101010,
0B01101010,
0B01110110,
0B01111110,
0B01111110,
0B01111010,
0B01110110,
0B00111100,
0B00000000
},
};

View File

@@ -0,0 +1,43 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "buttons.h"
#include "ssd1306.h"
uint8_t getPressedButton(uint8_t analogPin)
{
#ifdef USE_Z_KEYPAD
int buttonValue = analogRead(analogPin);
if (buttonValue < 100) return BUTTON_RIGHT;
if (buttonValue < 200) return BUTTON_UP;
if (buttonValue < 400) return BUTTON_DOWN;
if (buttonValue < 600) return BUTTON_LEFT;
if (buttonValue < 800) return BUTTON_SELECT;
#else
if (digitalRead(RIGHT_BTN) != LOW) return BUTTON_RIGHT;
if (digitalRead(LEFT_BTN) != LOW) return BUTTON_LEFT;
#endif
return BUTTON_NONE;
}

View File

@@ -0,0 +1,48 @@
/*
MIT License
Copyright (c) 2017-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <stdint.h>
#if defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__)
# define LEFT_BTN 2
# define RIGHT_BTN 0
#else // For Arduino Nano/Atmega328 we use different pins
# define USE_Z_KEYPAD // use analog Z-keypad ADC module on A0 pin.
# ifndef USE_Z_KEYPAD
# define LEFT_BTN 4
# define RIGHT_BTN 2
# endif
#endif
const uint8_t BUTTON_NONE = 0;
const uint8_t BUTTON_RIGHT = 1;
const uint8_t BUTTON_UP = 2;
const uint8_t BUTTON_DOWN = 3;
const uint8_t BUTTON_LEFT = 4;
const uint8_t BUTTON_SELECT = 5;
uint8_t getPressedButton(uint8_t analogPin);

View File

@@ -0,0 +1,82 @@
/*
MIT License
Copyright (c) 2017-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
const int MAX_LEVELS = 5;
#ifdef ARKANOID_SSD1331
const int BLOCKS_PER_ROW = 5;
#else
const int BLOCKS_PER_ROW = 7;
#endif
const int MAX_BLOCKS_PER_ROW = 8;
const int BLOCK_NUM_ROWS = 3;
const PROGMEM uint8_t levels[MAX_LEVELS][BLOCK_NUM_ROWS][MAX_BLOCKS_PER_ROW] =
{
{
{ 1,1,1,1,1,1,1,0 },
{ 0,2,2,2,2,2,0,0 },
{ 0,0,0,0,0,0,0,0 }
},
{
{ 0,3,3,3,3,3,0,0 },
{ 0,1,2,2,2,1,0,0 },
{ 0,0,1,1,1,0,0,0 }
},
{
{ 2,1,3,1,3,1,2,0 },
{ 0,2,2,5,2,2,0,0 },
{ 2,1,1,1,1,1,2,0 }
},
{
{ 2,1,4,3,3,4,2,0 },
{ 1,2,2,2,2,2,1,0 },
{ 0,3,3,3,3,3,0,0 }
},
{
{ 0,0,1,0,1,0,0,0 },
{ 0,1,2,6,2,1,0,0 },
{ 0,0,1,5,1,0,0,0 }
},
#if 0
{
{ 0,4,0,4,0,4,0,0 },
{ 4,5,4,5,4,5,4,0 },
{ 0,4,0,4,0,4,0,0 }
},
{
{ 2,1,1,5,1,1,2,0 },
{ 2,6,4,1,4,6,2,0 },
{ 2,3,0,0,0,3,2,0 }
},
{
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0 }
},
#endif
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View File

@@ -0,0 +1,83 @@
/*
MIT License
Copyright (c) 2016-2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
const PROGMEM uint8_t heartSprite[8] =
{
0B00001110,
0B00011111,
0B00111111,
0B01111110,
0B01111110,
0B00111101,
0B00011001,
0B00001110
};
const PROGMEM uint8_t powerSprite[8] =
{
0B11001110,
0B11111110,
0B00111110,
0B00010110,
0B00001110,
0B00001110,
0B00001111,
0B00001110
};
const PROGMEM uint8_t shootSprite[1] =
{
0B00111100,
};
const PROGMEM uint8_t bonusSprites[][5] =
{
{ /* BLOCK_BOMB */
0B01111001,
0B11111110,
0B11101110,
0B01111001,
0B00000000,
},
{ /* BLOCK_HEART */
0B00011100,
0B00111110,
0B01111100,
0B00111010,
0B00011100,
},
{ /* BLOCK_POWER */
0B00000000,
0B01111110,
0B00010010,
0B00010010,
0B00001100,
},
};

View File

@@ -0,0 +1,27 @@
//------------------------------------------------------------------------------
// File generated by LCD Assistant
// http://en.radzio.dxp.pl/bitmap_converter/
//------------------------------------------------------------------------------
const unsigned char arkanoid_2 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0xFC, 0x00, 0xFC, 0x04, 0xE4,
0x28, 0xA4, 0x4C, 0x18, 0xB0, 0xE0, 0x40, 0x00, 0xFC, 0x04, 0xFC, 0x00, 0x00, 0x80, 0xC0, 0x60,
0xB0, 0xE0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0xFC, 0x00, 0xFC,
0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x04, 0xFC, 0x00, 0x80, 0xE0, 0x30,
0xD0, 0x78, 0x28, 0x38, 0x1C, 0x14, 0x14, 0x1C, 0x38, 0x28, 0x78, 0xD0, 0x30, 0xE0, 0x80, 0x00,
0xFC, 0x04, 0xFC, 0x00, 0xFC, 0x04, 0xFC, 0x04, 0x0E, 0x9B, 0xF6, 0x0C, 0x98, 0xF0, 0x60, 0x00,
0x00, 0x30, 0x78, 0xFC, 0xFE, 0xFF, 0xCD, 0x84, 0x02, 0xFC, 0xFE, 0xFF, 0x00, 0xFF, 0x7C, 0x3F,
0x1D, 0x1C, 0x3E, 0x7B, 0xF1, 0xE0, 0x40, 0x00, 0xFF, 0x7C, 0x3F, 0x1E, 0x1F, 0x3F, 0x7E, 0xFB,
0xF1, 0xE0, 0x40, 0x30, 0x78, 0xFC, 0xFE, 0xFF, 0xCD, 0x84, 0x02, 0xFC, 0xFE, 0xFF, 0x00, 0xFF,
0xFC, 0xFE, 0x02, 0x06, 0x0D, 0x1F, 0x3E, 0x7C, 0xF8, 0xFF, 0xFC, 0x7F, 0x00, 0x0F, 0x3C, 0x7F,
0x78, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0x78, 0x7F, 0x3C, 0x0F, 0x00,
0xFF, 0xFC, 0x7F, 0x00, 0xFF, 0xFC, 0x7F, 0x3E, 0x1F, 0x0D, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

View File

@@ -0,0 +1,375 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* Nano/Atmega328 PINS: connect LCD to D5 (D/C), D4 (CS), D3 (RES), D11(DIN), D13(CLK)
* Attiny SPI PINS: connect LCD to D4 (D/C), GND (CS), D3 (RES), D1(DIN), D2(CLK)
* ESP8266: connect LCD to D1(D/C), D2(CS), RX(RES), D7(DIN), D5(CLK)
*/
#include "ssd1306.h"
#include "nano_engine.h"
#include "arkanoid.h"
#include "levels.h"
#define PIX_BITS 2
NanoEngine8 engine;
static uint8_t g_level = 0;
static uint8_t g_score = 0;
static const NanoRect gameArea = { {16, 0}, {79, 63} };
static const NanoRect blockArea = { {0, 8},
{BLOCKS_PER_ROW*8 - 1, 8 + BLOCK_NUM_ROWS*4 - 1} };
union
{
struct
{
lcdint_t intro_y;
lcdint_t pauseFrames;
} intro;
struct
{
lcdint_t intro_y;
lcdint_t pauseFrames;
} info;
struct
{
NanoRect platform; // platform position on the screen
NanoPoint ball; // ball position on the screen
NanoPoint ballScaled;// ball position in ^PIX_BITS coordinates
NanoPoint ballSpeed; // ball speed in *2 coordinates
uint8_t blocks[BLOCK_NUM_ROWS][MAX_BLOCKS_PER_ROW];
uint8_t blocksLeft;
uint8_t frames;
} battleField;
} gameState;
void startBattleField(bool reload);
bool drawIntro(void)
{
engine.canvas.clear();
engine.canvas.setColor(RGB_COLOR8(255,0,0));
engine.canvas.drawBitmap1(0, gameState.intro.intro_y, 96, 24, arkanoid_2);
return true;
}
void introLoop(void)
{
if (gameState.intro.intro_y < 16)
{
engine.refresh( 0, gameState.intro.intro_y, 95, gameState.intro.intro_y + 24 );
gameState.intro.intro_y++;
}
else
{
gameState.intro.pauseFrames++;
if (gameState.intro.pauseFrames > engine.getFrameRate() * 3 )
{
startBattleField( true );
}
}
}
void startIntro(void)
{
engine.refresh();
g_level = 0;
g_score = 0;
gameState.intro.intro_y = -24;
gameState.intro.pauseFrames = 0;
engine.drawCallback( drawIntro );
engine.loopCallback( introLoop );
}
bool drawBattleField(void)
{
/* If engine requests to redraw main game field */
if (gameArea.contains(engine.canvas.rect()))
{
/* Set non-transparent mode */
engine.canvas.setMode(CANVAS_MODE_BASIC);
engine.canvas.setColor(RGB_COLOR8(0,0,64));
NanoRect tileBlocks = engine.canvas.rect() >> 3;
tileBlocks.crop(gameArea >> 3);
for (uint8_t row = tileBlocks.p1.y; row <= tileBlocks.p2.y; row++)
for (uint8_t col = tileBlocks.p1.x; col <= tileBlocks.p2.x; col++)
engine.canvas.drawBitmap1(col << 3, row << 3, 8, 8, bgTile);
engine.canvas.setColor(RGB_COLOR8(255,255,255));
engine.canvas.drawHLine(gameArea.p1.x,gameArea.p1.y,gameArea.p2.x);
/* Now draw everything in game coordinates */
engine.worldCoordinates();
engine.canvas.setColor(RGB_COLOR8(0,128,255));
engine.canvas.drawRect(gameState.battleField.platform);
engine.canvas.setColor(RGB_COLOR8(0,0,0));
engine.canvas.putPixel(gameState.battleField.platform.p1);
engine.canvas.putPixel(gameState.battleField.platform.p2.x,
gameState.battleField.platform.p1.y);
for (uint8_t r = 0; r<BLOCK_NUM_ROWS; r++)
{
for (uint8_t bl = 0; bl<BLOCKS_PER_ROW; bl++)
{
uint8_t block = gameState.battleField.blocks[r][bl];
if (block)
{
NanoRect rect = {{bl*8, r*4}, {bl*8 + 8, r*4+4}};
rect += blockArea.p1;
engine.canvas.setColor(blockColors[block]);
engine.canvas.fillRect(rect);
engine.canvas.setColor(0);
engine.canvas.drawRect(rect);
}
}
}
engine.canvas.setColor(RGB_COLOR8(255,255,255));
engine.canvas.putPixel(gameState.battleField.ball);
}
else
{
char str[8] = {0};
engine.canvas.clear();
engine.canvas.setColor(RGB_COLOR8(255,255,255));
engine.canvas.drawVLine(gameArea.p1.x-1,0,64);
engine.canvas.drawVLine(gameArea.p2.x+1,0,64);
utoa(g_score, str, 10);
engine.canvas.setColor(RGB_COLOR8(192,192,192));
engine.canvas.printFixed(gameArea.p2.x+3, 16, str );
}
return true;
}
/* Moves platform right or left according to pressed keys */
void movePlatform(void)
{
if (engine.pressed( BUTTON_LEFT ) && (gameState.battleField.platform.p1.x > 0))
{
engine.refreshWorld( gameState.battleField.platform );
gameState.battleField.platform.move(-1, 0);
engine.refreshWorld( gameState.battleField.platform );
}
if (engine.pressed( BUTTON_RIGHT ) && (gameState.battleField.platform.p2.x < gameArea.width() - 1))
{
engine.refreshWorld( gameState.battleField.platform );
gameState.battleField.platform.move(+1, 0);
engine.refreshWorld( gameState.battleField.platform );
}
}
bool checkBlockHit(void)
{
if (!blockArea.collision(gameState.battleField.ball))
{
return false;
}
NanoPoint p = gameState.battleField.ball - blockArea.p1;
uint8_t row = p.y >> 2;
uint8_t column = p.x >> 3;
if (!gameState.battleField.blocks[row][column])
{
return false;
}
gameState.battleField.blocks[row][column] = 0;
gameState.battleField.blocksLeft--;
g_score++;
engine.refreshWorld( gameArea.p2.x + 1, 0, 95, 63 );
if (((p.y & 3) == 2) || (p.y & 3) == 1)
{
gameState.battleField.ballSpeed.x = -gameState.battleField.ballSpeed.x;
}
else
{
gameState.battleField.ballSpeed.y = -gameState.battleField.ballSpeed.y;
}
engine.refreshWorld( gameState.battleField.ball );
return true;
}
bool checkPlatformHit()
{
if (gameState.battleField.platform.collisionX( gameState.battleField.ball.x ) &&
!gameState.battleField.platform.above( gameState.battleField.ball ) &&
!gameState.battleField.platform.below( gameState.battleField.ball ) )
{
if (gameState.battleField.ball.x < gameState.battleField.platform.p1.x + 3)
{
gameState.battleField.ballSpeed.x = -3;
gameState.battleField.ballSpeed.y = -gameState.battleField.ballSpeed.y;
}
else if (gameState.battleField.ball.x > gameState.battleField.platform.p2.x - 3)
{
gameState.battleField.ballSpeed.x = +3;
gameState.battleField.ballSpeed.y = -gameState.battleField.ballSpeed.y;
}
else
{
gameState.battleField.ballSpeed.x = gameState.battleField.ballSpeed.x > 0 ? 2: -2;
gameState.battleField.ballSpeed.y = -gameState.battleField.ballSpeed.y;
}
return true;
}
return false;
}
bool checkGameAreaHit(void)
{
bool hit = false;
if ((gameState.battleField.ball.x < 0) ||
(gameState.battleField.ball.x >= gameArea.width()))
{
hit = true;
gameState.battleField.ballSpeed.x = -gameState.battleField.ballSpeed.x;
}
if ((gameState.battleField.ball.y < 0) ||
(gameState.battleField.ball.y >= gameArea.height()))
{
hit = true;
gameState.battleField.ballSpeed.y = -gameState.battleField.ballSpeed.y;
if (gameState.battleField.ball.y >= gameArea.height())
{
startBattleField( false );
}
}
return hit;
}
void moveBall(void)
{
engine.refreshWorld( gameState.battleField.ball );
bool moveBall;
do
{
gameState.battleField.ballScaled += gameState.battleField.ballSpeed;
gameState.battleField.ball = gameState.battleField.ballScaled >> PIX_BITS;
moveBall = false;
if (checkGameAreaHit())
{
moveBall = true;
}
if (checkPlatformHit())
{
moveBall = true;
}
if (checkBlockHit())
{
moveBall = true;
}
}
while (moveBall);
engine.refreshWorld( gameState.battleField.ball );
}
void battleFieldLoop(void)
{
movePlatform();
moveBall();
/* Refresh debug information if we need it */
gameState.battleField.frames++;
if (gameState.battleField.blocksLeft == 0)
{
g_level++;
startBattleField( true );
}
}
void loadLevel(void)
{
/* Loading level */
if (g_level > MAX_LEVELS)
{
g_level = MAX_LEVELS;
}
gameState.battleField.blocksLeft = 0;
for (uint8_t i =0; i<BLOCKS_PER_ROW; i++)
{
for (uint8_t j=0; j<BLOCK_NUM_ROWS; j++)
{
uint8_t block = pgm_read_byte( &levels[g_level][j][i] );
gameState.battleField.blocks[j][i] = block;
if (block)
{
gameState.battleField.blocksLeft++;
}
}
}
gameState.battleField.frames = 0;
}
void startBattleField(bool reload)
{
engine.refresh();
gameState.battleField.platform.setRect( 4, 56, 15, 58 );
gameState.battleField.ball.setPoint( 9, 55);
gameState.battleField.ballScaled = gameState.battleField.ball << PIX_BITS;
gameState.battleField.ballSpeed.setPoint( 3, -(1<<PIX_BITS) );
engine.drawCallback( drawBattleField );
engine.loopCallback( battleFieldLoop );
if ( reload )
{
loadLevel();
}
/* Show level info in popup message */
char levelInfo[8] = "LEVEL X";
levelInfo[6] = g_level + '0';
engine.notify(levelInfo);
}
void setup()
{
/* Set font to use in the game. The font has only capital letters and digits */
ssd1306_setFixedFont(ssd1306xled_font6x8_AB);
/* Init SPI oled display. 3 - RESET, 4 - CS (can be omitted, oled CS must be pulled down), 5 - D/C */
/* ssd1351 must be initialized in Horizontal addressing mode */
// ssd1351_128x128_spi_init(3, 4, 5);
/* il9163 must be initialized in Horizontal addressing mode */
// il9163_128x128_spi_init(3, 4, 5);
/* ssd1331 must be initialized in Horizontal addressing mode */
ssd1331_96x64_spi_init(3, 4, 5);
/* Configure engine to use ZKeypand on A0 as control board. */
engine.connectZKeypad(0);
/* Start engine */
engine.begin();
/* Set frame rate. 30 fps is too slow */
engine.setFrameRate(45);
engine.moveTo({ -gameArea.p1.x, -gameArea.p1.y });
startIntro();
}
void loop()
{
if (!engine.nextFrame()) return;
engine.display();
}

View File

@@ -0,0 +1,79 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "ssd1306.h"
#include "levels.h"
const uint8_t blockColors[]=
{
0,
RGB_COLOR8(128,128,128), // Grey 1
RGB_COLOR8(255,64,64), // Red 2
RGB_COLOR8(255,255,64), // Yellow 3
RGB_COLOR8(64,64,255), // Blue 4
RGB_COLOR8(255,64,255), // Cyan 5
RGB_COLOR8(64,255,64), // Green 6
RGB_COLOR8(255,255,255), // White 7
RGB_COLOR8(255,192,64), // Orange 8
RGB_COLOR8(128,255,192), // Light-blue 9
};
const PROGMEM uint8_t bgTile[] =
{
0B00000001,
0B11000010,
0B00101100,
0B00010000,
0B00101100,
0B01000010,
0B10000001,
0B00000001,
};
const PROGMEM uint8_t levels[MAX_LEVELS][BLOCK_NUM_ROWS][MAX_BLOCKS_PER_ROW] =
{
{ // LEVEL 1
{ 1,1,1,1,1,1,1,1, },
{ 2,2,2,2,2,2,2,2, },
{ 3,3,3,3,3,3,3,3, },
{ 4,4,4,4,4,4,4,4, },
{ 5,5,5,5,5,5,5,5, },
},
{ // LEVEL 2
{ 7,8,0,0,0,0,0,0, },
{ 7,8,9,6,0,0,0,0, },
{ 7,8,9,6,1,4,0,0, },
{ 7,8,9,6,1,4,5,3, },
{ 1,1,1,1,1,1,1,2, },
},
{ // LEVEL 3
{ 0,0,1,1,1,1,0,0, },
{ 0,1,2,1,1,2,1,0, },
{ 1,1,1,1,1,1,1,1, },
{ 1,0,1,1,1,1,0,1, },
{ 0,0,1,0,0,1,0,0, },
},
};

View File

@@ -0,0 +1,41 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
static const int MAX_LEVELS = 3;
#ifdef ARKANOID_SSD1331
static const int BLOCKS_PER_ROW = 8;
#else
static const int BLOCKS_PER_ROW = 8;
#endif
static const int MAX_BLOCKS_PER_ROW = 8;
static const int BLOCK_NUM_ROWS = 5;
extern const uint8_t blockColors[];
extern const PROGMEM uint8_t bgTile[];
extern const PROGMEM uint8_t levels[MAX_LEVELS][BLOCK_NUM_ROWS][MAX_BLOCKS_PER_ROW];

View File

@@ -0,0 +1,17 @@
# HOW to run Lode runner in emulator mode
Read [instructions](https://github.com/lexus2k/ssd1306/wiki/How-to-run-emulator-mode) and
install all required prerequisites.
## Compiling game and running emulation in Linux
> cd ssd1306/tools<br>
> ./build_and_run.sh -p linux -e -f games/lode_runner<br>
## Compiling game and running emulation in Windows
For MinGW32 use the script below:
> cd ssd1306\tools<br>
> build_and_run.bat "games/lode_runner"<br>

Some files were not shown because too many files have changed in this diff Show More