2016-01-02 16:37:11 +08:00
/*
GraphicsTest . ino
2016-05-26 18:20:44 +08:00
Some graphics / text output for U8x8 API
2016-01-02 16:37:11 +08:00
2016-01-04 00:10:50 +08:00
Universal 8 bit Graphics Library ( https : //github.com/olikraus/u8g2/)
2016-01-02 16:37:11 +08:00
Copyright ( c ) 2016 , olikraus @ gmail . com
All rights reserved .
Redistribution and use in source and binary forms , with or without modification ,
are permitted provided that the following conditions are met :
2015-12-14 04:47:11 +08:00
2016-01-02 16:37:11 +08:00
* Redistributions of source code must retain the above copyright notice , this list
of conditions and the following disclaimer .
* Redistributions in binary form must reproduce the above copyright notice , this
list of conditions and the following disclaimer in the documentation and / or other
materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES ,
INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT
NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT ,
STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*/
# include <Arduino.h>
2015-12-14 04:47:11 +08:00
# include <U8x8lib.h>
2016-01-02 16:37:11 +08:00
# ifdef U8X8_HAVE_HW_SPI
# include <SPI.h>
# endif
2016-05-15 15:56:06 +08:00
# ifdef U8X8_HAVE_HW_I2C
# include <Wire.h>
# endif
2016-01-02 16:37:11 +08:00
2016-05-12 00:29:58 +08:00
// Please UNCOMMENT one of the contructor lines below
// U8x8 Contructor List
2016-05-12 02:25:14 +08:00
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8x8setupcpp
2016-05-26 14:31:29 +08:00
// Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected
2016-11-12 23:17:56 +08:00
//U8X8_SSD1306_128X64_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2016-06-16 01:08:06 +08:00
//U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 6, /* dc=*/ 4, /* reset=*/ 12); // Arduboy (DevKit)
//U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy 10 (Production, Kickstarter Edition)
2016-08-18 03:30:29 +08:00
//U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2015-12-24 02:02:06 +08:00
//U8X8_SSD1306_128X64_NONAME_3W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8);
2016-06-12 12:49:23 +08:00
//U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 2, /* data=*/ 0, /* reset=*/ U8X8_PIN_NONE); // Digispark ATTiny85
2016-05-15 15:56:06 +08:00
//U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display
2016-05-15 21:25:34 +08:00
//U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
//U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(/* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED
//U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED
2016-11-21 01:18:14 +08:00
//U8X8_SSD1306_64X48_ER_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // EastRising 0.66" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered
2015-12-24 02:02:06 +08:00
//U8X8_SSD1306_128X64_NONAME_6800 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
//U8X8_SSD1306_128X64_NONAME_8080 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8);
2016-09-29 05:23:07 +08:00
//U8X8_SSD1322_NHD_256X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2016-10-02 14:00:28 +08:00
//U8X8_SSD1322_NHD_256X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2016-09-29 05:23:07 +08:00
//U8X8_SSD1325_NHD_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8X8_SSD1325_NHD_128X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2016-12-08 01:50:00 +08:00
U8X8_KS0108_128X64 u8x8 ( 8 , 9 , 10 , 11 , 4 , 5 , 6 , 7 , /*enable=*/ 18 , /*dc=*/ 17 , /*cs0=*/ 14 , /*cs1=*/ 15 , /*cs2=*/ U8X8_PIN_NONE , /* reset=*/ U8X8_PIN_NONE ) ; // Set R/W to low!
2016-05-26 16:33:09 +08:00
//U8X8_UC1701_EA_DOGS102_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8X8_UC1701_EA_DOGS102_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8X8_ST7565_EA_DOGM128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
//U8X8_ST7565_EA_DOGM128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2016-06-12 12:49:23 +08:00
//U8X8_ST7565_NHD_C12832_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2016-05-26 16:33:09 +08:00
//U8X8_ST7565_NHD_C12832_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
2016-11-23 05:08:19 +08:00
//U8X8_UC1608_ERC24064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Due, SW SPI, ERC24064-1 Test Board
2016-12-07 05:51:15 +08:00
//U8X8_UC1608_240X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Due, SW SPI, ERC24064-1 Test Board
2016-10-15 23:08:04 +08:00
//U8X8_UC1610_EA_DOGXL160_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE);
//U8X8_UC1610_EA_DOGXL160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE);
2016-11-13 00:30:14 +08:00
//U8X8_UC1611_EA_DOGM240_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C, DOGM240 Test Board
2016-11-23 05:08:19 +08:00
//U8X8_UC1611_EA_DOGM240_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board
2016-11-13 03:28:27 +08:00
//U8X8_UC1611_EA_DOGXL240_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C, DOGXL240 Test Board
2016-11-23 05:08:19 +08:00
//U8X8_UC1611_EA_DOGXL240_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board
2016-05-26 16:33:09 +08:00
2015-12-14 04:47:11 +08:00
2016-05-12 00:29:58 +08:00
// End of constructor list
2015-12-14 04:47:11 +08:00
void setup ( void )
{
2016-12-07 04:16:20 +08:00
/* U8g2 Project: KS0108 Test Board */
pinMode ( 16 , OUTPUT ) ;
digitalWrite ( 16 , 0 ) ;
2015-12-14 04:47:11 +08:00
u8x8 . begin ( ) ;
}
void pre ( void )
{
2016-01-02 01:18:22 +08:00
u8x8 . setFont ( u8x8_font_amstrad_cpc_extended_f ) ;
2015-12-14 04:47:11 +08:00
u8x8 . clear ( ) ;
u8x8 . inverse ( ) ;
u8x8 . print ( " U8x8 Library " ) ;
u8x8 . setFont ( u8x8_font_chroma48medium8_r ) ;
u8x8 . noInverse ( ) ;
u8x8 . setCursor ( 0 , 1 ) ;
}
void draw_bar ( uint8_t c , uint8_t is_inverse )
{
uint8_t r ;
u8x8 . setInverseFont ( is_inverse ) ;
for ( r = 0 ; r < u8x8 . getRows ( ) ; r + + )
{
u8x8 . setCursor ( c , r ) ;
u8x8 . print ( " " ) ;
}
}
void draw_ascii_row ( uint8_t r , int start )
{
int a ;
uint8_t c ;
for ( c = 0 ; c < u8x8 . getCols ( ) ; c + + )
{
u8x8 . setCursor ( c , r ) ;
a = start + c ;
if ( a < = 255 )
u8x8 . write ( a ) ;
}
}
void loop ( void )
{
int i ;
uint8_t c , r , d ;
pre ( ) ;
u8x8 . print ( " github.com/ " ) ;
u8x8 . setCursor ( 0 , 2 ) ;
u8x8 . print ( " olikraus/u8g2 " ) ;
delay ( 2000 ) ;
u8x8 . setCursor ( 0 , 3 ) ;
u8x8 . print ( " Tile size: " ) ;
u8x8 . print ( ( int ) u8x8 . getCols ( ) ) ;
u8x8 . print ( " x " ) ;
u8x8 . print ( ( int ) u8x8 . getRows ( ) ) ;
delay ( 2000 ) ;
pre ( ) ;
for ( i = 19 ; i > 0 ; i - - )
{
u8x8 . setCursor ( 3 , 2 ) ;
u8x8 . print ( i ) ;
u8x8 . print ( " " ) ;
delay ( 200 ) ;
}
draw_bar ( 0 , 1 ) ;
for ( c = 1 ; c < u8x8 . getCols ( ) ; c + + )
{
draw_bar ( c , 1 ) ;
draw_bar ( c - 1 , 0 ) ;
delay ( 50 ) ;
}
draw_bar ( u8x8 . getCols ( ) - 1 , 0 ) ;
pre ( ) ;
2016-01-02 01:18:22 +08:00
u8x8 . setFont ( u8x8_font_amstrad_cpc_extended_f ) ;
2015-12-14 04:47:11 +08:00
for ( d = 0 ; d < 8 ; d + + )
{
for ( r = 1 ; r < u8x8 . getRows ( ) ; r + + )
{
draw_ascii_row ( r , ( r - 1 + d ) * u8x8 . getCols ( ) + 32 ) ;
}
delay ( 1000 ) ;
}
draw_bar ( u8x8 . getCols ( ) - 1 , 1 ) ;
for ( c = u8x8 . getCols ( ) - 1 ; c > 0 ; c - - )
{
draw_bar ( c - 1 , 1 ) ;
draw_bar ( c , 0 ) ;
delay ( 50 ) ;
}
draw_bar ( 0 , 0 ) ;
2016-08-18 03:24:38 +08:00
pre ( ) ;
u8x8 . drawString ( 0 , 2 , " Small " ) ;
u8x8 . draw2x2String ( 0 , 5 , " Big " ) ;
delay ( 3000 ) ;
2016-11-06 00:37:45 +08:00
pre ( ) ;
u8x8 . print ( " print \\ n \n " ) ;
delay ( 500 ) ;
u8x8 . println ( " println " ) ;
delay ( 500 ) ;
u8x8 . println ( " done " ) ;
delay ( 1500 ) ;
2015-12-14 04:47:11 +08:00
}