├── HX1230_FB.cpp ├── README.txt ├── library.properties ├── examples ├── HX1230_libfb_HelloWorld │ └── HX1230_libfb_HelloWorld.ino ├── HX1230_libfb_Graphics │ └── HX1230_libfb_Graphics.ino ├── HX1230_libfb_HariChord │ └── HX1230_libfb_HariChord.ino ├── HX1230_libfb_Dithering │ └── HX1230_libfb_Dithering.ino ├── HX1230_libfb_Bitmap │ └── HX1230_libfb_Bitmap.ino ├── HX1230_libfb_Bitmap2 │ └── HX1230_libfb_Bitmap2.ino ├── HX1230_libfb_Demo │ └── HX1230_libfb_Demo.ino ├── HX1230_libfb_Clock │ └── HX1230_libfb_Clock.ino ├── HX1230_libfb_Clock_3LCD │ └── HX1230_libfb_Clock_3LCD.ino └── HX1230_libfb_Gauges │ └── HX1230_libfb_Gauges.ino ├── README.md ├── keywords.txt ├── HX1230_FB.h └── LICENSE /HX1230_FB.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cbm80amiga/HX1230_FB/HEAD/HX1230_FB.cpp -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This is fast 9-bit SPI library for HX1230 96x68 display. 2 | 3 | Supports only hardware 9-bit SPI 4 | Uses 96*9 bytes of RAM as frame buffer memory, most common graphics primitives implemented with dithering 5 | Some examples require PropFonts library 6 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=HX1230 FrameBuffer 2 | version=1.0.2 3 | author=Pawel A. Hernik 4 | maintainer=Pawel A. Hernik 5 | sentence=Fast 9-bit SPI graphics library for HX1230 96x68 LCD 6 | paragraph=Fast 9-bit SPI graphics library for HX1230 96x68 LCD 7 | category=Display 8 | url=https://github.com/cbm80amiga/HX1230_FB 9 | architectures=* 10 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_HelloWorld/HX1230_libfb_HelloWorld.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // (c) 2019 Pawel A. Hernik 3 | 4 | /* 5 | HX1230 96x68 LCD connections (header on bottom, from left): 6 | #1 RST - D6 or any digital 7 | #2 CE - D7 or any digital 8 | #3 N/C 9 | #4 DIN - D11/MOSI 10 | #5 CLK - D13/SCK 11 | #6 VCC - 3V3 12 | #7 BL - 3V3 or any digital 13 | #8 GND - GND 14 | */ 15 | 16 | #define LCD_RST 6 17 | #define LCD_CS 7 18 | #define LCD_BL 8 19 | 20 | #include "HX1230_FB.h" 21 | #include 22 | HX1230_FB lcd(LCD_RST, LCD_CS); 23 | 24 | // from PropFonts library 25 | #include "c64enh_font.h" 26 | 27 | void setup() 28 | { 29 | Serial.begin(9600); 30 | pinMode(LCD_BL, OUTPUT); 31 | //analogWrite(LCD_BL,30); 32 | digitalWrite(LCD_BL, HIGH); 33 | 34 | SPI.begin(); 35 | lcd.init(); 36 | lcd.cls(); 37 | lcd.setFont(c64enh); 38 | lcd.printStr(ALIGN_CENTER, 30, "Hello World!"); 39 | lcd.drawRect(4,20,95-4*2,67-20*2,1); 40 | lcd.display(); 41 | } 42 | 43 | void loop() 44 | { 45 | } 46 | 47 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_Graphics/HX1230_libfb_Graphics.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // (c) 2019 Pawel A. Hernik 3 | 4 | /* 5 | HX1230 96x68 LCD connections (header on bottom, from left): 6 | #1 RST - D6 or any digital 7 | #2 CE - D7 or any digital 8 | #3 N/C 9 | #4 DIN - D11/MOSI 10 | #5 CLK - D13/SCK 11 | #6 VCC - 3V3 12 | #7 BL - 3V3 or any digital 13 | #8 GND - GND 14 | */ 15 | 16 | #define LCD_RST 6 17 | #define LCD_CS 7 18 | #define LCD_BL 8 19 | 20 | #include "HX1230_FB.h" 21 | #include 22 | HX1230_FB lcd(LCD_RST, LCD_CS); 23 | 24 | void setup() 25 | { 26 | Serial.begin(9600); 27 | pinMode(LCD_BL, OUTPUT); 28 | digitalWrite(LCD_BL, HIGH); 29 | lcd.init(); 30 | lcd.cls(); 31 | lcd.drawRectD(0,0,SCR_WD,SCR_HT,1); 32 | 33 | lcd.drawRect(8,7,20,20,1); 34 | lcd.fillRect(8+30,7,20,20,1); 35 | lcd.fillRectD(8+60,7,20,20,1); 36 | 37 | lcd.drawCircle(5+12,48,12,1); 38 | lcd.fillCircle(5+30+12,48,12,1); 39 | lcd.fillCircleD(5+60+12,48,12,1); 40 | 41 | lcd.display(); 42 | } 43 | 44 | void loop() 45 | { 46 | } 47 | 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HX1230_FB 2 | Fast 9-bit SPI graphics library for HX1230 96x68 LCD (aka Nokia 1202, STE2007) 3 | 4 | Uses 96x9 bytes of RAM as frame buffer memory. Most common graphics primitives implemented. Dithering available. 5 | 6 | YouTube videos: 7 | https://www.youtube.com/playlist?list=PLxb1losWErZ5eNiQAwB75pXTec5KzX_Cf 8 | 9 | 10 | ## Features 11 | 12 | - proportional fonts support built-in (requires fonts from PropFonts library https://github.com/cbm80amiga/PropFonts) 13 | - simple primitives 14 | - pixels 15 | - lines 16 | - rectangles 17 | - filled rectangles 18 | - circles 19 | - filled circles 20 | - triangles 21 | - filled triangles 22 | - fast ordered dithering (17 patterns) 23 | - ultra fast horizontal and vertical line drawing 24 | - bitmaps drawing 25 | - example programs 26 | 27 | ## Connections 28 | 29 | |HX1230 pin|Pin name| Arduino| 30 | |--|--|--| 31 | |#1| RST |D6 or any digital| 32 | |#2| CE |D7 or any digital| 33 | |#3| N/C || 34 | |#4| DIN | D11/MOSI | 35 | |#5| CLK |D13/SCK| 36 | |#6| VCC| 3.3V| 37 | |#7| BL| 3.3V or via resistor to any digital pin| 38 | |#8 |GND|GND| 39 | 40 | If you find it useful and want to buy me a coffee or a beer: 41 | 42 | https://www.paypal.me/cbm80amiga 43 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | HX1230_FB KEYWORD3 2 | 3 | init KEYWORD2 4 | setFont KEYWORD2 5 | setFontMinWd KEYWORD2 6 | setCharMinWd KEYWORD2 7 | setDigitMinWd KEYWORD2 8 | setCR KEYWORD2 9 | printStr KEYWORD2 10 | printChar KEYWORD2 11 | charWidth KEYWORD2 12 | strWidth KEYWORD2 13 | cls KEYWORD2 14 | drawBitmap KEYWORD2 15 | drawBuf KEYWORD2 16 | setIsNumberFun KEYWORD2 17 | 18 | fillWin KEYWORD2 19 | sendData KEYWORD2 20 | sendCmd KEYWORD2 21 | gotoXY KEYWORD2 22 | sleep KEYWORD2 23 | setContrast KEYWORD2 24 | setRotate KEYWORD2 25 | setScroll KEYWORD2 26 | setInvert KEYWORD2 27 | setInvertMask KEYWORD2 28 | displayMode KEYWORD2 29 | displayInvert KEYWORD2 30 | displayOn KEYWORD2 31 | setInvert KEYWORD2 32 | 33 | cls KEYWORD2 34 | clearDisplay KEYWORD2 35 | drawPixel KEYWORD2 36 | drawLine KEYWORD2 37 | drawLineH KEYWORD2 38 | drawLineV KEYWORD2 39 | drawLineVfast KEYWORD2 40 | drawLineVfastD KEYWORD2 41 | drawLineHfast KEYWORD2 42 | drawLineHfastD KEYWORD2 43 | drawRect KEYWORD2 44 | drawRectD KEYWORD2 45 | fillRect KEYWORD2 46 | fillRectD KEYWORD2 47 | drawCircle KEYWORD2 48 | fillCircle KEYWORD2 49 | fillCircleD KEYWORD2 50 | drawTriangle KEYWORD2 51 | fillTriangle KEYWORD2 52 | fillTriangleD KEYWORD2 53 | setDither KEYWORD2 54 | 55 | SCR_WD LITERAL1 56 | SCR_HT LITERAL1 57 | ALIGN_LEFT LITERAL1 58 | ALIGN_RIGHT LITERAL1 59 | ALIGN_CENTER LITERAL1 60 | SET LITERAL1 61 | CLR LITERAL1 62 | XOR LITERAL1 63 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_HariChord/HX1230_libfb_HariChord.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // (c) 2019 Pawel A. Hernik 3 | 4 | /* 5 | HX1230 96x68 LCD connections (header on bottom, from left): 6 | #1 RST - D6 or any digital 7 | #2 CE - D7 or any digital 8 | #3 N/C 9 | #4 DIN - D11/MOSI 10 | #5 CLK - D13/SCK 11 | #6 VCC - 3V3 12 | #7 BL - 3V3 or any digital 13 | #8 GND - GND 14 | */ 15 | 16 | #define LCD_RST 6 17 | #define LCD_CS 7 18 | #define LCD_BL 8 19 | 20 | #include "HX1230_FB.h" 21 | #include 22 | HX1230_FB lcd(LCD_RST, LCD_CS); 23 | 24 | void setup() 25 | { 26 | Serial.begin(9600); 27 | pinMode(LCD_BL, OUTPUT); 28 | digitalWrite(LCD_BL, HIGH); 29 | lcd.init(); 30 | } 31 | 32 | int nFrames = 36; 33 | 34 | void loop() 35 | { 36 | for (int i=0; i= 0; i--) HariChord(i); 38 | } 39 | 40 | // by Hari Wiguna 41 | void HariChord(int frame) 42 | { 43 | lcd.clearDisplay(); 44 | int n = 7; 45 | int r = frame * 64 / nFrames; 46 | float rot = frame * 2*PI / nFrames; 47 | for (int i=0; i<(n-1); i++) { 48 | float a = rot + i * 2*PI / n; 49 | int x1 = SCR_WD/2 + cos(a) * r; 50 | int y1 = SCR_HT/2 + sin(a) * r; 51 | for (int j=i+1; j 22 | HX1230_FB lcd(LCD_RST, LCD_CS); 23 | 24 | // from PropFonts library 25 | #include "c64enh_font.h" 26 | #include "tiny3x7sq_font.h" 27 | 28 | char buf[20]; 29 | 30 | void setup() 31 | { 32 | Serial.begin(9600); 33 | pinMode(LCD_BL, OUTPUT); 34 | digitalWrite(LCD_BL, HIGH); 35 | lcd.init(); 36 | lcd.cls(); 37 | int dx = SCR_WD/16; 38 | for(int j=1;j<17;j++) { lcd.setDither(j); lcd.fillRectD((j-1)*dx,0,dx,SCR_HT,1); } 39 | lcd.display(); 40 | delay(5000); 41 | } 42 | 43 | void sample(int s) 44 | { 45 | lcd.cls(); 46 | lcd.setDither(s); 47 | lcd.setFont(c64enh); 48 | snprintf(buf,20,"Pattern: %02d",s); 49 | lcd.printStr(ALIGN_CENTER, 2, buf); 50 | lcd.fillRectD(6,13,44,32,1); 51 | lcd.fillCircleD(96-24,28,16,1); 52 | int dx = SCR_WD/16; 53 | for(int j=1;j<17;j++) { 54 | lcd.setFont(Tiny3x7SqPL); 55 | buf[0]=(j>9) ? j-10+'A' : j+'0'; 56 | buf[1]=0; 57 | lcd.printStr(2+(j-1)*dx, SCR_HT-8*2, buf); 58 | lcd.setDither(j); 59 | lcd.fillRectD((j-1)*dx,SCR_HT-8,dx,8,1); 60 | } 61 | lcd.display(); 62 | delay(500); 63 | } 64 | 65 | void loop() 66 | { 67 | for(int i=0;i<=16;i++) sample(i); 68 | for(int i=16;i>0;i--) sample(i); 69 | } 70 | 71 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_Bitmap/HX1230_libfb_Bitmap.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // (c) 2019 Pawel A. Hernik 3 | 4 | /* 5 | HX1230 96x68 LCD connections (header on bottom, from left): 6 | #1 RST - D6 or any digital 7 | #2 CE - D7 or any digital 8 | #3 N/C 9 | #4 DIN - D11/MOSI 10 | #5 CLK - D13/SCK 11 | #6 VCC - 3V3 12 | #7 BL - 3V3 or any digital 13 | #8 GND - GND 14 | */ 15 | 16 | #define LCD_RST 6 17 | #define LCD_CS 7 18 | #define LCD_BL 8 19 | 20 | #include "HX1230_FB.h" 21 | #include 22 | HX1230_FB lcd(LCD_RST, LCD_CS); 23 | 24 | const uint8_t icon1 [] PROGMEM = { 16,16, 25 | 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xDE, 0xCC, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 26 | 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0x7B, 0x33, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 27 | }; 28 | 29 | const uint8_t icon2 [] PROGMEM = { 16,16, 30 | 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xCC, 0xDE, 0xFE, 0xFC, 0xF8, 0xF0, 0xE0, 0xC0, 0x80, 31 | 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x33, 0x7B, 0x7F, 0x3F, 0x1F, 0x0F, 0x07, 0x03, 0x01, 32 | }; 33 | 34 | const uint8_t icon3 [] PROGMEM = { 16,16, 35 | 0xFC, 0x0C, 0x14, 0x24, 0x44, 0x84, 0x04, 0x04, 0x04, 0x04, 0x84, 0x44, 0x24, 0x14, 0x0C, 0xFC, 36 | 0x3F, 0x30, 0x28, 0x24, 0x22, 0x21, 0x21, 0x22, 0x22, 0x21, 0x21, 0x22, 0x24, 0x28, 0x30, 0x3F, 37 | }; 38 | void setup() 39 | { 40 | Serial.begin(9600); 41 | pinMode(LCD_BL, OUTPUT); 42 | //analogWrite(LCD_BL,30); 43 | digitalWrite(LCD_BL, HIGH); 44 | SPI.begin(); 45 | lcd.init(); 46 | lcd.cls(); 47 | lcd.drawBitmap(icon1,0,0); 48 | lcd.drawBitmap(icon2,24,0); 49 | lcd.drawBitmap(icon3,48,0); 50 | 51 | lcd.drawBitmap(icon1,ALIGN_LEFT,16); 52 | lcd.drawBitmap(icon2,ALIGN_RIGHT,16); 53 | lcd.drawBitmap(icon3,ALIGN_CENTER,16); 54 | 55 | lcd.drawBitmap(icon3,86,57); // clipping 56 | lcd.display(); 57 | } 58 | 59 | void loop() 60 | { 61 | } 62 | 63 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_Bitmap2/HX1230_libfb_Bitmap2.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // (c) 2019 Pawel A. Hernik 3 | 4 | /* 5 | HX1230 96x68 LCD connections (header on bottom, from left): 6 | #1 RST - D6 or any digital 7 | #2 CE - D7 or any digital 8 | #3 N/C 9 | #4 DIN - D11/MOSI 10 | #5 CLK - D13/SCK 11 | #6 VCC - 3V3 12 | #7 BL - 3V3 or any digital 13 | #8 GND - GND 14 | */ 15 | 16 | #define LCD_RST 6 17 | #define LCD_CS 7 18 | #define LCD_BL 8 19 | 20 | #include "HX1230_FB.h" 21 | #include 22 | HX1230_FB lcd(LCD_RST, LCD_CS); 23 | 24 | const uint8_t cat [] PROGMEM = {35,6*8, 25 | 0x00, 0x00, 0x00, 0x00, 0xF8, 0x0C, 0x06, 0x02, 0x0E, 0x30, 0x60, 0x20, 0x20, 0x40, 0x80, 0x00, 26 | 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 27 | 0x00, 0x00, 0x00, 0x00, 0x78, 0x8E, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | 0x00, 0x00, 0x01, 0xF9, 0x0C, 0x87, 0xC0, 0x60, 0x30, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 29 | 0x08, 0x10, 0x20, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xFC, 0x00, 0x00, 0x00, 0x00, 30 | 0xF0, 0x10, 0x18, 0x08, 0x0C, 0x06, 0x03, 0xFC, 0x07, 0x00, 0x00, 0x80, 0xE0, 0x38, 0x08, 0x0C, 31 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x18, 0x0F, 0x00, 0x00, 0x00, 0xC0, 0x78, 0x0F, 0x01, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x07, 0x18, 0x20, 0xC0, 0x00, 0x00, 0x01, 0x0E, 0xF0, 0x00, 0x07, 0xF8, 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7E, 0x03, 0x00, 34 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x1C, 0xE0, 0xC0, 0x7D, 35 | 0x06, 0x00, 0xF3, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 36 | 0x0E, 0x10, 0x20, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 37 | 0x20, 0x31, 0x18, 0x0C, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 38 | 0x00, 0x00, 39 | }; 40 | 41 | const uint8_t dog [] PROGMEM = {47,6*8, 42 | 0x70, 0x90, 0x18, 0x08, 0x0C, 0x04, 0x06, 0x02, 0x04, 0x04, 0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 43 | 0x04, 0x06, 0x02, 0x04, 0x04, 0x04, 0x08, 0x38, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 | 0x01, 0x02, 0x04, 0x08, 0x18, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 | 0x00, 0x00, 0x60, 0xBC, 0x84, 0x88, 0x9E, 0x83, 0x00, 0x00, 0x80, 0x80, 0xC0, 0x40, 0x60, 0x20, 47 | 0x30, 0x90, 0x98, 0xC8, 0x48, 0x68, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x38, 0x00, 0x00, 0x00, 48 | 0x00, 0x00, 0x00, 0xE0, 0x3C, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x06, 0x1A, 0xE3, 50 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 | 0x00, 0x00, 0xEF, 0x30, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x40, 0x40, 0x40, 0x80, 0x00, 0x00, 0x07, 53 | 0x18, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 54 | 0x00, 0x07, 0xF8, 0x00, 0x00, 0x00, 0xFE, 0x03, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0xC2, 0x7E, 55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x3C, 0xC0, 0x00, 56 | 0x03, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xE0, 0xB0, 57 | 0x98, 0x8F, 0x80, 0x80, 0xC0, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0B, 0x49, 0xF8, 0x80, 58 | 0x80, 0x80, 0x80, 0x8F, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E, 0x23, 0x20, 0x20, 59 | 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 | }; 61 | 62 | 63 | void setup() 64 | { 65 | Serial.begin(9600); 66 | pinMode(LCD_BL, OUTPUT); 67 | digitalWrite(LCD_BL, HIGH); 68 | lcd.init(); 69 | lcd.cls(); 70 | lcd.drawBitmap(dog,ALIGN_LEFT,10); 71 | lcd.drawBitmap(cat,ALIGN_RIGHT,10); 72 | lcd.display(); 73 | } 74 | 75 | void loop() 76 | { 77 | } 78 | 79 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_Demo/HX1230_libfb_Demo.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // (c) 2019 Pawel A. Hernik 3 | 4 | /* 5 | HX1230 96x68 LCD connections (header on bottom, from left): 6 | #1 RST - D6 or any digital 7 | #2 CE - D7 or any digital 8 | #3 N/C 9 | #4 DIN - D11/MOSI 10 | #5 CLK - D13/SCK 11 | #6 VCC - 3V3 12 | #7 BL - 3V3 or any digital 13 | #8 GND - GND 14 | */ 15 | 16 | #define LCD_RST 6 17 | #define LCD_CS 7 18 | #define LCD_BL 8 19 | 20 | #include "HX1230_FB.h" 21 | #include 22 | HX1230_FB lcd(LCD_RST, LCD_CS); 23 | 24 | // from PropFonts library 25 | #include "c64enh_font.h" 26 | 27 | char buf[20]; 28 | 29 | void setup() 30 | { 31 | Serial.begin(9600); 32 | pinMode(LCD_BL, OUTPUT); 33 | //analogWrite(LCD_BL,30); 34 | digitalWrite(LCD_BL, HIGH); 35 | SPI.begin(); 36 | lcd.init(); 37 | } 38 | 39 | float t=0; 40 | 41 | void animSinLines() 42 | { 43 | lcd.cls(); 44 | float x; 45 | for(int i=0;i0) y=SCR_HT/2-sqrt(y2)-5; 88 | if(y<0) y=0; 89 | if(y>yt) y=yt; 90 | x+=lcd.printChar(x,(int)y,*txt++); 91 | } 92 | 93 | lcd.fillCircleD(SCR_WD/2+xo,SCR_HT/2,r,1); 94 | //lcd.drawCircle(SCR_WD/2+xo,SCR_HT/2,r+1,1); 95 | t+=0.4; 96 | lcd.display(); 97 | } 98 | 99 | void rects() 100 | { 101 | int x,y; 102 | x = random(SCR_WD); 103 | y = random(40); 104 | lcd.setDither(random(12)); 105 | lcd.fillRect(x,y,30,30,0); 106 | lcd.fillRectD(x,y,30,30,1); 107 | lcd.drawRect(x,y,30,30,1); 108 | lcd.display(); 109 | //delay(100); 110 | } 111 | 112 | void circles() 113 | { 114 | int x,y; 115 | x = 15+random(SCR_WD-30); 116 | y = 15+random(SCR_HT-30); 117 | lcd.setDither(random(12)); 118 | lcd.fillCircle(x,y,15,0); 119 | lcd.fillCircleD(x,y,15,1); 120 | lcd.drawCircle(x,y,16,1); 121 | lcd.display(); 122 | //delay(100); 123 | } 124 | 125 | int x=40,y=0; 126 | int dx=6,dy=5; 127 | int x2=80,y2=40; 128 | int dx2=9,dy2=8; 129 | 130 | void animRect() 131 | { 132 | x+=dx; 133 | y+=dy; 134 | if(x>SCR_WD/2 || x<0) { dx=-dx; x+=dx; } 135 | if(y>SCR_HT/2 || y<0) { dy=-dy; y+=dy; } 136 | lcd.fillRect(x,y,SCR_WD/2,SCR_HT/2,2); 137 | lcd.display(); 138 | lcd.fillRect(x,y,SCR_WD/2,SCR_HT/2,2); 139 | delay(40); 140 | } 141 | 142 | #define MAX_LINES 10 143 | byte lx0[MAX_LINES]; 144 | byte lx1[MAX_LINES]; 145 | byte ly0[MAX_LINES]; 146 | byte ly1[MAX_LINES]; 147 | byte curLine=0; 148 | 149 | void animLines() 150 | { 151 | x+=dx; 152 | y+=dy; 153 | x2+=dx2; 154 | y2+=dy2; 155 | if(x>SCR_WD-1) { dx=-dx; x=SCR_WD-1; } 156 | if(x<1) { dx=-dx; x=0; } 157 | if(y>SCR_HT-1) { dy=-dy; y=SCR_HT-1; } 158 | if(y<1) { dy=-dy; y=0; } 159 | if(x2>SCR_WD-1) { dx2=-dx2; x2=SCR_WD-1; } 160 | if(x2<1) { dx2=-dx2; x2=0; } 161 | if(y2>SCR_HT-1) { dy2=-dy2; y2=SCR_HT-1; } 162 | if(y2<1) { dy2=-dy2; y2=0; } 163 | lx0[curLine]=x; 164 | lx1[curLine]=x2; 165 | ly0[curLine]=y; 166 | ly1[curLine]=y2; 167 | if(++curLine>=MAX_LINES) curLine=0; 168 | lcd.cls(); 169 | for(int i=0;i 24 | #include 25 | 26 | #define CMD 0x00 27 | #define DAT 0x80 28 | 29 | // HX1230 Commands 30 | #define HX1230_POWER_ON 0x2F // internal power supply on 31 | #define HX1230_POWER_OFF 0x28 // internal power supply off 32 | #define HX1230_CONTRAST 0x80 // 0x80 + (0..31) 33 | #define HX1230_SEG_NORMAL 0xA0 // SEG remap normal 34 | #define HX1230_SEG_REMAP 0xA1 // SEG remap reverse (flip horizontal) 35 | #define HX1230_DISPLAY_NORMAL 0xA4 // display ram contents 36 | #define HX1230_DISPLAY_TEST 0xA5 // all pixels on 37 | #define HX1230_INVERT_OFF 0xA6 // not inverted 38 | #define HX1230_INVERT_ON 0xA7 // inverted 39 | #define HX1230_DISPLAY_ON 0XAF // display on 40 | #define HX1230_DISPLAY_OFF 0XAE // display off 41 | #define HX1230_SCAN_START_LINE 0x40 // scrolling 0x40 + (0..63) 42 | #define HX1230_COM_NORMAL 0xC0 // COM remap normal 43 | #define HX1230_COM_REMAP 0xC8 // COM remap reverse (flip vertical) 44 | #define HX1230_SW_RESET 0xE2 // connect RST pin to GND and rely on software reset 45 | #define HX1230_NOP 0xE3 // no operation 46 | #define HX1230_COL_ADDR_H 0x10 // x pos (0..95) 4 MSB 47 | #define HX1230_COL_ADDR_L 0x00 // x pos (0..95) 4 LSB 48 | #define HX1230_PAGE_ADDR 0xB0 // y pos, 8.5 rows (0..8) 49 | 50 | #define SCR_WD 96 51 | #define SCR_HT 68 52 | #define SCR_HT8 9 // (SCR_HT+7)/8 53 | 54 | #define ALIGN_LEFT 0 55 | #define ALIGN_RIGHT -1 56 | #define ALIGN_CENTER -2 57 | 58 | #define SET 1 59 | #define CLR 0 60 | #define XOR 2 61 | 62 | struct _propFont 63 | { 64 | const uint8_t* font; 65 | int8_t xSize; 66 | uint8_t ySize; 67 | uint8_t firstCh; 68 | uint8_t lastCh; 69 | uint8_t minCharWd; 70 | uint8_t minDigitWd; 71 | }; 72 | 73 | // --------------------------------- 74 | class HX1230_FB { 75 | public: 76 | HX1230_FB(uint8_t rst, uint8_t cs); 77 | 78 | inline void sendSPI(uint8_t v, uint8_t dc) __attribute__((always_inline)); // costs about 350B of flash 79 | inline void sendCmd(uint8_t cmd); 80 | inline void sendData(uint8_t data); 81 | void init(); 82 | void display(); 83 | void copy(uint8_t x, uint8_t y8, uint8_t wd, uint8_t ht8); 84 | void gotoXY(byte x, byte y); 85 | void sleep(bool mode=true); 86 | void setContrast(byte val); 87 | void setScroll(byte val); 88 | void displayInvert(bool mode); 89 | void displayOn(bool mode); 90 | void displayMode(byte val); 91 | void setRotate(int mode); 92 | 93 | void cls(); 94 | void clearDisplay() { cls(); } 95 | void drawPixel(uint8_t x, uint8_t y, uint8_t col); 96 | void drawLine(int8_t x0, int8_t y0, int8_t x1, int8_t y1, uint8_t col); 97 | void drawLineH(uint8_t x0, uint8_t x1, uint8_t y, uint8_t col); 98 | void drawLineV(uint8_t x, uint8_t y0, uint8_t y1, uint8_t col); 99 | void drawLineVfast(uint8_t x, uint8_t y0, uint8_t y1, uint8_t col); 100 | void drawLineVfastD(uint8_t x, uint8_t y0, uint8_t y1, uint8_t col); 101 | void drawLineHfast(uint8_t x0, uint8_t x1, uint8_t y, uint8_t col); 102 | void drawLineHfastD(uint8_t x0, uint8_t x1, uint8_t y, uint8_t col); 103 | void drawRect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t col); 104 | void drawRectD(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t col); 105 | void fillRect(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t col); 106 | void fillRectD(uint8_t x0, uint8_t y0, uint8_t w, uint8_t h, uint8_t col); 107 | void drawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t col); 108 | void fillCircle(uint8_t x0, uint8_t y0, uint8_t r, uint8_t col); 109 | void fillCircleD(uint8_t x0, uint8_t y0, uint8_t r, uint8_t col); 110 | void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 111 | void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 112 | void fillTriangleD(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 113 | void setDither(int8_t s); 114 | int drawBitmap(const uint8_t *bmp, int x, uint8_t y, uint8_t w, uint8_t h); 115 | int drawBitmap(const uint8_t *bmp, int x, uint8_t y); 116 | 117 | void setFont(const uint8_t* f); 118 | void setCR(uint8_t _cr) { cr = _cr; } 119 | void setInvert(uint8_t _inv) { invertCh = _inv; } 120 | void setFontMinWd(uint8_t wd) { cfont.minCharWd = wd; } 121 | void setCharMinWd(uint8_t wd) { cfont.minCharWd = wd; } 122 | void setDigitMinWd(uint8_t wd) { cfont.minDigitWd = wd; } 123 | int printChar(int xpos, int ypos, unsigned char c); 124 | int printStr(int xpos, int ypos, char *str); 125 | int charWidth(uint8_t _ch, bool last=true); 126 | int fontHeight(); 127 | int strWidth(char *txt); 128 | unsigned char convertPolish(unsigned char _c); 129 | static bool isNumber(uint8_t ch); 130 | static bool isNumberExt(uint8_t ch); 131 | void setIsNumberFun(bool (*fun)(uint8_t)) { isNumberFun=fun; } 132 | 133 | public: 134 | static byte scr[SCR_WD*SCR_HT8]; 135 | byte scrWd = SCR_WD; 136 | byte scrHt = SCR_HT8; 137 | uint8_t csPin, rstPin; 138 | 139 | static byte ystab[8]; 140 | static byte yetab[8]; 141 | static byte pattern[4]; 142 | static const byte ditherTab[4*17]; 143 | 144 | //private: 145 | bool (*isNumberFun)(uint8_t ch); 146 | _propFont cfont; 147 | uint8_t cr; // carriage return mode for printStr 148 | uint8_t dualChar; 149 | uint8_t invertCh; 150 | uint8_t spacing = 1; 151 | }; 152 | #endif 153 | 154 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_Clock/HX1230_libfb_Clock.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // Analog Clock without floating-point calculations, no slow sin, cos 3 | // (c) 2019 Pawel A. Hernik 4 | // YouTube video: https://youtu.be/uBId9KbtGuQ 5 | 6 | /* 7 | HX1230 96x68 LCD connections (header on bottom, from left): 8 | #1 RST - D6 or any digital 9 | #2 CE - D7 or any digital 10 | #3 N/C 11 | #4 DIN - D11/MOSI 12 | #5 CLK - D13/SCK 13 | #6 VCC - 3V3 14 | #7 BL - 3V3 or any digital 15 | #8 GND - GND 16 | */ 17 | 18 | #define LCD_RST 6 19 | #define LCD_CS 7 20 | #define LCD_BL 8 21 | 22 | #include "HX1230_FB.h" 23 | #include 24 | HX1230_FB lcd(LCD_RST, LCD_CS); 25 | 26 | #include "small4x6_font.h" 27 | 28 | // configuration 29 | 30 | int cx = SCR_WD/2, cy = SCR_HT/2; // clock center 31 | int rline0 = 34, rline1 = 30, rdot = 33, rnum = 25; // radius for hour lines, minute dots and numbers 32 | int rhr = 16, rmin = 20, rsec = 25; // hour, minute, second hand length 33 | int hrNum = 3; // hour numbers - 0=none, 3-only 12,3,6,9, 1-all 34 | int qdots = 0; // quadrant dots 35 | 36 | /* 37 | int cx = 27; 38 | int cy = 27; 39 | int rline0 = 27, rline1 = 24, rdot = 27, rnum = 20; 40 | int rhr = 10, rmin = 14, rsec = 18; 41 | int hrNum = 3; 42 | int qdots = 0; 43 | */ 44 | 45 | uint8_t txt2num(const char* p) 46 | { 47 | return 10*(*p-'0') + *(p+1)-'0'; 48 | } 49 | 50 | int sx,sy,mx,my,hx,hy; 51 | int sdeg,mdeg,hdeg; 52 | int osx,osy,omx,omy,ohx,ohy; 53 | int xs,ys,xe,ye; 54 | unsigned long styleTime, ms; 55 | uint8_t hh = txt2num(__TIME__+0); 56 | uint8_t mm = txt2num(__TIME__+3); 57 | uint8_t ss = txt2num(__TIME__+6); 58 | uint8_t start = 1; 59 | int i; 60 | char buf[20]; 61 | 62 | // ------------------------------------------------ 63 | #define MAXSIN 255 64 | const uint8_t sinTab[91] PROGMEM = { 65 | 0,4,8,13,17,22,26,31,35,39,44,48,53,57,61,65,70,74,78,83,87,91,95,99,103,107,111,115,119,123, 66 | 127,131,135,138,142,146,149,153,156,160,163,167,170,173,177,180,183,186,189,192,195,198,200,203,206,208,211,213,216,218, 67 | 220,223,225,227,229,231,232,234,236,238,239,241,242,243,245,246,247,248,249,250,251,251,252,253,253,254,254,254,254,254, 68 | 255 69 | }; 70 | 71 | int fastSin(int i) 72 | { 73 | while(i<0) i+=360; 74 | while(i>=360) i-=360; 75 | if(i<90) return(pgm_read_byte(&sinTab[i])); else 76 | if(i<180) return(pgm_read_byte(&sinTab[180-i])); else 77 | if(i<270) return(-pgm_read_byte(&sinTab[i-180])); else 78 | return(-pgm_read_byte(&sinTab[360-i])); 79 | } 80 | 81 | int fastCos(int i) 82 | { 83 | return fastSin(i+90); 84 | } 85 | 86 | // ------------------------------------------------ 87 | 88 | void setup(void) 89 | { 90 | Serial.begin(9600); 91 | pinMode(LCD_BL, OUTPUT); 92 | digitalWrite(LCD_BL, HIGH); 93 | lcd.init(); 94 | lcd.setFont(Small4x6PL); 95 | 96 | //for(i=0; i<360; i+=4) lcd.drawPixel(i/4,34-fastSin(i)*30/MAXSIN,1); 97 | //for(i=0; i<360; i+=4) lcd.drawPixel(i/4,34-fastCos(i)*30/MAXSIN,1); 98 | //lcd.display(); delay(10000); 99 | /* 100 | for(i=0; i<360; i++) { 101 | if((i%30)==0) Serial.println(); 102 | sx = sin(radians(i))*255; 103 | Serial.print((int)sx); Serial.print(","); 104 | } 105 | */ 106 | clockConst(); 107 | ms = styleTime = millis(); 108 | } 109 | 110 | void loop() 111 | { 112 | nextClockStyle(); 113 | clockUpdate(); 114 | } 115 | 116 | int style=0; 117 | 118 | void nextClockStyle() 119 | { 120 | if(millis()-styleTime<10000) return; 121 | styleTime = millis(); 122 | if(++style>8) style=0; 123 | switch(style) { 124 | default: 125 | case 0: // default, only 12,3,6,9, no quadrant dots 126 | cx = SCR_WD/2, cy = SCR_HT/2; 127 | rline0 = 34; rline1 = 30; rdot = 33; rnum = 25; 128 | rhr = 16; rmin = 20; rsec = 25; 129 | hrNum = 3; qdots = 0; 130 | start = 1; 131 | break; 132 | case 1: // full option 133 | hrNum = 1; qdots = 1; 134 | break; 135 | case 2: 136 | qdots = 0; hrNum = 3; 137 | break; 138 | case 3: // no hour numbers 139 | hrNum = 0; 140 | break; 141 | case 4: // no minute dots 142 | hrNum = 3; rdot = 0; 143 | break; 144 | case 5: // only hour lines 145 | hrNum = 0; rdot = 0; 146 | break; 147 | case 6: // only minute dots and numbers 148 | hrNum = 3; rdot = 33; rline0 = 0; 149 | break; 150 | case 7: // smaller, no minute dots, with numbers 151 | cx = 25, cy = 25; 152 | rline0 = 26; rline1 = 23; rdot = 0; rnum = 17; 153 | rhr = 9; rmin = 13; rsec = 18; 154 | hrNum = 3; qdots = 0; 155 | start = 1; 156 | break; 157 | case 8: // smaller, minute dots, no hour lines and numbers 158 | cx = SCR_WD-20, cy = SCR_HT-20; 159 | rline0 = 20; rline1 = 17; rdot = 20; rnum = 0; 160 | rhr = 9; rmin = 12; rsec = 16; 161 | hrNum = 0; qdots = 0; 162 | start = 1; 163 | break; 164 | } 165 | clockConst(); 166 | } 167 | 168 | void clockConst() 169 | { 170 | lcd.cls(); 171 | // 12 hour lines 172 | if(rline0>0) 173 | for(i=0; i<360; i+=30) { 174 | sx = fastCos(i-90); 175 | sy = fastSin(i-90); 176 | xs = cx+sx*rline0/MAXSIN; 177 | ys = cy+sy*rline0/MAXSIN; 178 | xe = cx+sx*rline1/MAXSIN; 179 | ye = cy+sy*rline1/MAXSIN; 180 | lcd.drawLine(xs, ys, xe, ye, 1); 181 | } 182 | 183 | // 60 second dots 184 | if(rdot>0) 185 | for(i=0; i<360; i+=6) { 186 | sx = fastCos(i-90); 187 | sy = fastSin(i-90); 188 | xs = cx+sx*rdot/MAXSIN; 189 | ys = cy+sy*rdot/MAXSIN; 190 | lcd.drawPixel(xs, ys, 1); 191 | 192 | // 4 quadrant dots 193 | if(qdots && i%90==0) lcd.fillCircle(xs, ys, 1, 1); 194 | } 195 | } 196 | 197 | void clockUpdate() 198 | { 199 | if(millis()-ms>=1000 || start) 200 | { 201 | ms = millis(); 202 | if(++ss>59) { 203 | ss=0; 204 | if(++mm>59) { 205 | mm=0; 206 | if(++hh>23) hh=0; 207 | } 208 | } 209 | 210 | sdeg = ss*6; 211 | mdeg = mm*6+sdeg/60; 212 | hdeg = hh*30+mdeg/12; 213 | hx = fastCos(hdeg-90); 214 | hy = fastSin(hdeg-90); 215 | mx = fastCos(mdeg-90); 216 | my = fastSin(mdeg-90); 217 | sx = fastCos(sdeg-90); 218 | sy = fastSin(sdeg-90); 219 | 220 | if(ss==0 || start) { 221 | start = 0; 222 | // clear hour and minute hand positions every minute 223 | lcd.drawLine(ohx,ohy, cx,cy, 0); 224 | ohx = cx+hx*rhr/MAXSIN; 225 | ohy = cy+hy*rhr/MAXSIN; 226 | lcd.drawLine(omx,omy, cx,cy, 0); 227 | omx = cx+mx*rmin/MAXSIN; 228 | omy = cy+my*rmin/MAXSIN; 229 | } 230 | 231 | // new hand positions 232 | lcd.drawLine(osx,osy, cx,cy, 0); 233 | osx = cx+sx*rsec/MAXSIN; 234 | osy = cy+sy*rsec/MAXSIN; 235 | lcd.drawLine(ohx,ohy, cx,cy, 1); 236 | lcd.drawLine(omx,omy, cx,cy, 1); 237 | lcd.drawLine(osx,osy, cx,cy, 1); 238 | lcd.fillCircle(cx,cy, 1, 1); 239 | 240 | if(hrNum>0) 241 | for(i=0; i<12; i+=hrNum) { // +=3 for 12,3,6,9 242 | sx = fastCos(i*30-90); 243 | sy = fastSin(i*30-90); 244 | xs = cx+sx*rnum/MAXSIN; 245 | ys = cy+sy*rnum/MAXSIN; 246 | snprintf(buf,3,"%d",i==0?12:i); 247 | lcd.printStr(i==0?xs-3:xs-1,ys-3,buf); 248 | } 249 | //snprintf(buf,20,"%02d:%02d:%02d",hh,mm,ss); 250 | //lcd.fillRect(0,0,6*5+4,7,0); lcd.printStr(0,0,buf); 251 | lcd.display(); 252 | } 253 | } 254 | 255 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_Clock_3LCD/HX1230_libfb_Clock_3LCD.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // Analog Clock without floating-point calculations, no slow sin, cos 3 | // Digital Clock requires RREFont library 4 | // (c) 2019 Pawel A. Hernik 5 | // YouTube videos: 6 | // https://youtu.be/nRJxjmrr09A 7 | // https://youtu.be/uBId9KbtGuQ 8 | 9 | /* 10 | HX1230 96x68 LCD connections (header at the bottom, from left): 11 | #1 RST - D6 shared by all 3 LCDs 12 | #2 CE/CS - D7,D8,D9 separate for each LCD 13 | #3 N/C 14 | #4 DIN - D11/MOSI shared by all 3 LCDs 15 | #5 CLK - D13/SCK shared by all 3 LCDs 16 | #6 VCC - 3V3 17 | #7 BL - 3V3 or any digital 18 | #8 GND - GND 19 | */ 20 | 21 | #define LCD_RST 6 22 | #define LCD_CS1 7 23 | #define LCD_CS2 8 24 | #define LCD_CS3 9 25 | //#define LCD_BL 10 26 | 27 | #include "HX1230_FB.h" 28 | #include 29 | HX1230_FB lcd1(LCD_RST, LCD_CS1); // only 1 reset pin defined 30 | HX1230_FB lcd2(255, LCD_CS2); 31 | HX1230_FB lcd3(255, LCD_CS3); 32 | 33 | #include "small4x6_font.h" 34 | 35 | #include "RREFont.h" 36 | #include "rre_arialdig47b.h" 37 | #include "rre_bold13x20.h" 38 | #include "rre_arialbldig54b.h" 39 | 40 | RREFont font; 41 | 42 | // needed for RREFont library initialization, define your fillRect 43 | // here RRE renders fonts in common frambuffer so only lcd1 is used 44 | void customRect1(int x, int y, int w, int h, int c) { return lcd1.fillRect(x, y, w, h, c); } 45 | void customRectDither1(int x, int y, int w, int h, int c) { return lcd1.fillRectD(x, y, w, h, c); } 46 | 47 | 48 | // analog clock configuration 49 | 50 | int cx = SCR_WD/2, cy = SCR_HT/2; // clock center 51 | int rline0 = 34, rline1 = 30, rdot = 33, rnum = 25; // radius for hour lines, minute dots and numbers 52 | int rhr = 16, rmin = 19, rsec = 26; // hour, minute, second hand length 53 | int hrNum = 1; // hour numbers - 0=none, 3-only 12,3,6,9, 1-all 54 | int qdots = 0; // quadrant dots 55 | 56 | uint8_t txt2num(const char* p) 57 | { 58 | return 10*(*p-'0') + *(p+1)-'0'; 59 | } 60 | 61 | int sx,sy,mx,my,hx,hy; 62 | int sdeg,mdeg,hdeg; 63 | int osx,osy,omx,omy,ohx,ohy; 64 | int xs,ys,xe,ye; 65 | long ms,startMillis; 66 | long startTime=16*3600L+58*60+50; 67 | uint8_t hh = txt2num(__TIME__+0); 68 | uint8_t mm = txt2num(__TIME__+3); 69 | uint8_t ss = txt2num(__TIME__+6); 70 | char buf[20]; 71 | 72 | // ------------------------------------------------ 73 | #define MAXSIN 255 74 | const uint8_t sinTab[91] PROGMEM = { 75 | 0,4,8,13,17,22,26,31,35,39,44,48,53,57,61,65,70,74,78,83,87,91,95,99,103,107,111,115,119,123, 76 | 127,131,135,138,142,146,149,153,156,160,163,167,170,173,177,180,183,186,189,192,195,198,200,203,206,208,211,213,216,218, 77 | 220,223,225,227,229,231,232,234,236,238,239,241,242,243,245,246,247,248,249,250,251,251,252,253,253,254,254,254,254,254, 78 | 255 79 | }; 80 | 81 | int fastSin(int i) 82 | { 83 | while(i<0) i+=360; 84 | while(i>=360) i-=360; 85 | if(i<90) return(pgm_read_byte(&sinTab[i])); else 86 | if(i<180) return(pgm_read_byte(&sinTab[180-i])); else 87 | if(i<270) return(-pgm_read_byte(&sinTab[i-180])); else 88 | return(-pgm_read_byte(&sinTab[360-i])); 89 | } 90 | 91 | int fastCos(int i) 92 | { 93 | return fastSin(i+90); 94 | } 95 | 96 | // ------------------------------------------------ 97 | 98 | void setup(void) 99 | { 100 | Serial.begin(9600); 101 | //pinMode(LCD_BL, OUTPUT); 102 | //digitalWrite(LCD_BL, HIGH); 103 | lcd1.init(); 104 | lcd2.init(); 105 | lcd3.init(); 106 | lcd1.cls(); 107 | lcd1.display(); 108 | lcd2.display(); 109 | lcd3.display(); 110 | lcd3.setFont(Small4x6PL); 111 | 112 | font.init(customRect1, SCR_WD, SCR_HT); // custom fillRect function and screen width and height values 113 | ms = startMillis = millis(); 114 | startTime = hh*3600L+mm*60L+ss + 10; // 10 - delay between real time and upload 115 | osx=omx=ohx=cx; 116 | osy=omy=ohy=cy; 117 | } 118 | 119 | void loop() 120 | { 121 | if(ss>15 && ss<=45) analogClock(); else digitalClock(); 122 | } 123 | 124 | void tick() 125 | { 126 | unsigned long tim = startTime+(millis()-startMillis)/1000; 127 | if(tim>=24*3600L) { tim-=24*3600L; startTime-=24*3600L; } 128 | hh = tim/3600L; 129 | mm = (tim-hh*3600L)/60L; 130 | ss = tim-hh*3600L-mm*60L; 131 | } 132 | 133 | int hhOld=hh,mmOld=mm,ssOld=ss; 134 | 135 | // hh,mm,ss on separate LCD 136 | void digitalClock() 137 | { 138 | if(millis()-ms<1000) return; 139 | ms = millis(); 140 | hhOld = hh; 141 | mmOld = mm; 142 | ssOld = ss; 143 | tick(); 144 | font.setFont(&rre_ArialBlDig54b); font.setDigitMinWd(46); 145 | font.setFillRectFun(customRectDither1); 146 | 147 | for(int i=1;i<=16;i++) { 148 | lcd1.cls(); 149 | snprintf(buf,5,"%02d",hhOld); 150 | lcd1.setDither(-i); 151 | font.printStr(ALIGN_CENTER,(SCR_HT-font.getHeight())/2,buf); 152 | lcd1.setDither(i); 153 | snprintf(buf,5,"%02d",hh); 154 | font.printStr(ALIGN_CENTER,(SCR_HT-font.getHeight())/2,buf); 155 | lcd1.display(); 156 | 157 | lcd2.cls(); 158 | snprintf(buf,5,"%02d",mmOld); 159 | lcd1.setDither(-i); 160 | font.printStr(ALIGN_CENTER,(SCR_HT-font.getHeight())/2,buf); 161 | lcd1.setDither(i); 162 | snprintf(buf,5,"%02d",mm); 163 | font.printStr(ALIGN_CENTER,(SCR_HT-font.getHeight())/2,buf); 164 | lcd2.display(); 165 | 166 | lcd3.cls(); 167 | snprintf(buf,5,"%02d",ssOld); 168 | lcd1.setDither(-i); 169 | font.printStr(ALIGN_CENTER,(SCR_HT-font.getHeight())/2,buf); 170 | lcd1.setDither(i); 171 | snprintf(buf,5,"%02d",ss); 172 | font.printStr(ALIGN_CENTER,(SCR_HT-font.getHeight())/2,buf); 173 | lcd3.display(); 174 | //delay(50); 175 | } 176 | } 177 | 178 | int outlineD(int x, int y, char *str, int dither) 179 | { 180 | font.setColor(1); 181 | font.setFillRectFun(customRect1); 182 | font.printStr(x-1,y-1,str); 183 | font.printStr(x-0,y-1,str); 184 | font.printStr(x+1,y-1,str); 185 | font.printStr(x-1,y+1,str); 186 | font.printStr(x-0,y+1,str); 187 | font.printStr(x+1,y+1,str); 188 | font.printStr(x-1,y,str); 189 | font.printStr(x+1,y,str); 190 | font.setColor(0); 191 | font.setFillRectFun(customRectDither1); 192 | lcd1.setDither(dither); 193 | font.printStr(x,y,str); 194 | font.setColor(1); 195 | font.setFillRectFun(customRect1); 196 | } 197 | 198 | // digital hh,mm,ss on lcd1 and lcd2, analog on lcd3 199 | void analogClock() 200 | { 201 | clockUpdate(); 202 | 203 | font.setFont(&rre_ArialDig47b); 204 | lcd1.cls(); 205 | font.setDigitMinWd(31); 206 | font.setFillRectFun(customRectDither1); 207 | snprintf(buf,5,"%02d",hh); 208 | outlineD(3,11,buf,14); 209 | outlineD(96-10,11,":",14); 210 | lcd1.display(); 211 | 212 | lcd2.cls(); 213 | snprintf(buf,3,"%02d",mm); 214 | outlineD(1,11,buf,14); 215 | 216 | font.setFont(&rre_Bold13x20); 217 | font.setCharMinWd(13); 218 | snprintf(buf,3,"%02d",ss); 219 | font.setFillRectFun(customRectDither1); 220 | outlineD(70-2,36,buf,16); 221 | lcd2.display(); 222 | } 223 | 224 | 225 | void clockConst() 226 | { 227 | lcd3.cls(); 228 | // 12 hour lines 229 | if(rline0>0) 230 | for(int i=0; i<360; i+=30) { 231 | sx = fastCos(i-90); 232 | sy = fastSin(i-90); 233 | xs = cx+sx*rline0/MAXSIN; 234 | ys = cy+sy*rline0/MAXSIN; 235 | xe = cx+sx*rline1/MAXSIN; 236 | ye = cy+sy*rline1/MAXSIN; 237 | lcd3.drawLine(xs, ys, xe, ye, 1); 238 | } 239 | 240 | // 60 second dots 241 | if(rdot>0) 242 | for(int i=0; i<360; i+=6) { 243 | sx = fastCos(i-90); 244 | sy = fastSin(i-90); 245 | xs = cx+sx*rdot/MAXSIN; 246 | ys = cy+sy*rdot/MAXSIN; 247 | lcd3.drawPixel(xs, ys, 1); 248 | 249 | // 4 quadrant dots 250 | if(qdots && i%90==0) lcd3.fillCircle(xs, ys, 1, 1); 251 | } 252 | } 253 | 254 | void clockUpdate() 255 | { 256 | //if(millis()-ms<1000) return; 257 | //ms = millis(); 258 | tick(); 259 | clockConst(); 260 | 261 | sdeg = ss*6; 262 | mdeg = mm*6+sdeg/60; 263 | hdeg = hh*30+mdeg/12; 264 | hx = fastCos(hdeg-90); 265 | hy = fastSin(hdeg-90); 266 | mx = fastCos(mdeg-90); 267 | my = fastSin(mdeg-90); 268 | sx = fastCos(sdeg-90); 269 | sy = fastSin(sdeg-90); 270 | 271 | // clear hour and minute hand positions every minute 272 | lcd3.drawLine(ohx,ohy, cx,cy, 0); 273 | ohx = cx+hx*rhr/MAXSIN; 274 | ohy = cy+hy*rhr/MAXSIN; 275 | lcd3.drawLine(omx,omy, cx,cy, 0); 276 | omx = cx+mx*rmin/MAXSIN; 277 | omy = cy+my*rmin/MAXSIN; 278 | 279 | // new hand positions 280 | lcd3.drawLine(osx,osy, cx,cy, 0); 281 | osx = cx+sx*rsec/MAXSIN; 282 | osy = cy+sy*rsec/MAXSIN; 283 | lcd3.drawLine(ohx,ohy, cx,cy, 1); 284 | lcd3.drawLine(omx,omy, cx,cy, 1); 285 | lcd3.drawLine(osx,osy, cx,cy, 1); 286 | lcd3.fillCircle(cx,cy, 1, 1); 287 | 288 | if(hrNum>0) 289 | for(int i=0; i<12; i+=hrNum) { // +=3 for 12,3,6,9 290 | sx = fastCos(i*30-90); 291 | sy = fastSin(i*30-90); 292 | xs = cx+sx*rnum/MAXSIN; 293 | ys = cy+sy*rnum/MAXSIN; 294 | snprintf(buf,3,"%d",i==0?12:i); 295 | lcd3.printStr(i==0?xs-3:xs-1,ys-3,buf); 296 | } 297 | lcd3.display(); 298 | } 299 | 300 | -------------------------------------------------------------------------------- /examples/HX1230_libfb_Gauges/HX1230_libfb_Gauges.ino: -------------------------------------------------------------------------------- 1 | // HX1230 96x68 LCD FB library example 2 | // Gauges 3 | // (c) 2019 Pawel A. Hernik 4 | // YouTube video: https://youtu.be/x94y-qH2RBs 5 | 6 | /* 7 | HX1230 96x68 LCD connections (header on bottom, from left): 8 | #1 RST - D6 or any digital 9 | #2 CE - D7 or any digital 10 | #3 N/C 11 | #4 DIN - D11/MOSI 12 | #5 CLK - D13/SCK 13 | #6 VCC - 3V3 14 | #7 BL - 3V3 or any digital 15 | #8 GND - GND 16 | */ 17 | 18 | #define LCD_RST 6 19 | #define LCD_CS 7 20 | #define LCD_BL 8 21 | 22 | #include "HX1230_FB.h" 23 | #include 24 | HX1230_FB lcd(LCD_RST, LCD_CS); 25 | 26 | #include "bold13x20digtop_font.h" 27 | #include "small4x6_font.h" 28 | 29 | int cx,cy; 30 | int sx,sy; 31 | int xs0,ys0,xe0,ye0; 32 | int xs1,ys1,xe1,ye1; 33 | int i; 34 | char buf[20]; 35 | 36 | // ------------------------------------------------ 37 | #define MAXSIN 255 38 | const uint8_t sinTab[91] PROGMEM = { 39 | 0,4,8,13,17,22,26,31,35,39,44,48,53,57,61,65,70,74,78,83,87,91,95,99,103,107,111,115,119,123, 40 | 127,131,135,138,142,146,149,153,156,160,163,167,170,173,177,180,183,186,189,192,195,198,200,203,206,208,211,213,216,218, 41 | 220,223,225,227,229,231,232,234,236,238,239,241,242,243,245,246,247,248,249,250,251,251,252,253,253,254,254,254,254,254, 42 | 255 43 | }; 44 | 45 | int fastSin(int i) 46 | { 47 | if(i<0) i+=360; 48 | if(i>=360) i-=360; 49 | if(i<90) return(pgm_read_byte(&sinTab[i])); else 50 | if(i<180) return(pgm_read_byte(&sinTab[180-i])); else 51 | if(i<270) return(-pgm_read_byte(&sinTab[i-180])); else 52 | return(-pgm_read_byte(&sinTab[360-i])); 53 | } 54 | 55 | int fastCos(int i) 56 | { 57 | return fastSin(i+90); 58 | } 59 | 60 | // ------------------------------------------------ 61 | 62 | void drawGauge1(int level) 63 | { 64 | lcd.cls(); 65 | cx=96/2; 66 | cy=68-26; 67 | int rx0=35, ry0=30; 68 | int rx1=45, ry1=40; 69 | int mina=-40; 70 | int maxa=180+40; 71 | for(int i=mina; imina) lcd.drawLine(xs0,ys0,lastx,lasty,1); 118 | lastx=xs0; 119 | lasty=ys0; 120 | xs0 = cx+sx*rx2/MAXSIN; 121 | ys0 = cy+sy*rx2/MAXSIN; 122 | lcd.setFont(Small4x6PL); 123 | snprintf(buf,4,"%d",(i-40)/10); 124 | lcd.printStr(i==maxa?xs0-4:xs0-2,ys0-2,buf); 125 | } 126 | int a = map(level,0,100,mina,maxa); 127 | rx1=rx0-8; 128 | sx = fastCos(a-180); 129 | sy = fastSin(a-180); 130 | xs0 = cx+sx*rx1/MAXSIN; 131 | ys0 = cy+sy*rx1/MAXSIN; 132 | lcd.drawLine(xs0,ys0,cx,cy,1); 133 | lcd.fillCircle(cx,cy,2,1); 134 | 135 | rx1=rx0-26; 136 | sx = fastCos(a-180-8); 137 | sy = fastSin(a-180-8); 138 | xe0 = cx+sx*rx1/MAXSIN; 139 | ye0 = cy+sy*rx1/MAXSIN; 140 | sx = fastCos(a-180+8); 141 | sy = fastSin(a-180+8); 142 | xe1 = cx+sx*rx1/MAXSIN; 143 | ye1 = cy+sy*rx1/MAXSIN; 144 | lcd.fillTriangle(xs0,ys0,xe0,ye0,xe1,ye1,1); 145 | 146 | lcd.display(); 147 | } 148 | 149 | void drawGauge3(int level) 150 | { 151 | lcd.cls(); 152 | cx=96/2; 153 | cy=68/2; 154 | int rx0=33; 155 | int rx1=rx0-4; 156 | int mina=0; 157 | int maxa=270; 158 | int lastx,lasty; 159 | for(int i=mina; i<=maxa; i+=3) { 160 | sx = fastCos(i-270); 161 | sy = fastSin(i-270); 162 | xs0 = cx+sx*rx0/MAXSIN; 163 | ys0 = cy+sy*rx0/MAXSIN; 164 | if(i>mina) lcd.drawLine(xs0,ys0,lastx,lasty,1); 165 | lastx=xs0; 166 | lasty=ys0; 167 | } 168 | for(int i=mina; i<=maxa; i+=9) { 169 | sx = fastCos(i-270); 170 | sy = fastSin(i-270); 171 | xs0 = cx+sx*rx0/MAXSIN; 172 | ys0 = cy+sy*rx0/MAXSIN; 173 | if(i%27==0) rx1=rx0-5; else rx1=rx0-3; 174 | xe0 = cx+sx*rx1/MAXSIN; 175 | ye0 = cy+sy*rx1/MAXSIN; 176 | lcd.drawLine(xs0,ys0,xe0,ye0,1); 177 | } 178 | 179 | int a = map(level,0,100,mina,maxa); 180 | rx1=rx0-7; 181 | sx = fastCos(a-270); 182 | sy = fastSin(a-270); 183 | xs0 = cx+sx*rx1/MAXSIN; 184 | ys0 = cy+sy*rx1/MAXSIN; 185 | lcd.drawLine(xs0,ys0,cx,cy,1); 186 | lcd.fillCircle(cx,cy,2,1); 187 | 188 | lcd.setFont(Bold13x20); 189 | snprintf(buf,10,"%d",level); 190 | lcd.printStr(ALIGN_RIGHT,SCR_HT-20,buf); 191 | lcd.display(); 192 | } 193 | 194 | void drawGauge4(int level) 195 | { 196 | lcd.cls(); 197 | cx=96-1; 198 | cy=68-1; 199 | int rx0=cx-2, ry0=cy-2; 200 | int rx1=rx0-20, ry1=ry0-20; 201 | int rx2=rx0+2, ry2=ry0+2; 202 | int mina=0; 203 | int maxa=90; 204 | for(int i=mina; i<=maxa; i+=5) { 205 | sx = fastCos(i-180); 206 | sy = fastSin(i-180); 207 | xs0 = cx+sx*rx0/MAXSIN; 208 | ys0 = cy+sy*ry0/MAXSIN; 209 | xe0 = cx+sx*rx1/MAXSIN; 210 | ye0 = cy+sy*ry1/MAXSIN; 211 | //if(90*(i-mina)/(maxa-mina)<=level) lcd.drawLine(xs0,ys0,xe0,ye0, 1); else lcd.drawPixel(xs0,ys0, 1); 212 | if(i>mina) { 213 | if(i<=level) { 214 | lcd.fillTriangle(xs0,ys0,xe0,ye0,xe1,ye1, 1); 215 | lcd.fillTriangle(xs1,ys1,xe1,ye1,xs0,ys0, 1); 216 | } else { 217 | lcd.fillTriangleD(xs0,ys0,xe0,ye0,xe1,ye1, 1); 218 | lcd.fillTriangleD(xs1,ys1,xe1,ye1,xs0,ys0, 1); 219 | } 220 | } 221 | xs1 = xs0; ys1 = ys0; 222 | xe1 = xe0; ye1 = ye0; 223 | xe0 = cx+sx*rx2/MAXSIN; 224 | ye0 = cy+sy*ry2/MAXSIN; 225 | lcd.drawLine(xs0,ys0,xe0,ye0, 1); 226 | } 227 | lcd.setFont(Bold13x20); 228 | snprintf(buf,10,"%d",level); 229 | lcd.printStr(ALIGN_RIGHT,SCR_HT-20,buf); 230 | lcd.display(); 231 | } 232 | 233 | void drawBar(int level) 234 | { 235 | lcd.cls(); 236 | int i=level*96/100; 237 | lcd.setDither(7+10*level/100); 238 | lcd.fillRectD(0,5,i,10,1); 239 | lcd.setDither(4); 240 | lcd.fillRectD(i,5,96-i,10,1); 241 | 242 | for(i=0;i<96;i+=8) { 243 | if(ibarLevSet[i]) { 268 | barLev[i]-=4; 269 | if(barLev[i]barLevSet[i]) { barLev[i]=barLevSet[i]; barDec[i]=1; } 273 | } 274 | } else { 275 | barLev[i]--; 276 | if(barLev[i]<0) barLev[i]=0; 277 | } 278 | } 279 | int r; 280 | r=random(12); 281 | barLevSet[r]=random(5,67); barDec[r]=0; 282 | if(r>0) { barLevSet[r-1]=7*barLevSet[r]/10; barDec[r-1]=0; } 283 | if(r<11) { barLevSet[r+1]=7*barLevSet[r]/10; barDec[r+1]=0; } 284 | } 285 | 286 | unsigned long ms,tm=15000; 287 | 288 | void setup(void) 289 | { 290 | Serial.begin(9600); 291 | pinMode(LCD_BL, OUTPUT); 292 | digitalWrite(LCD_BL, HIGH); 293 | lcd.init(); 294 | lcd.cls(); 295 | lcd.setFont(Small4x6PL); 296 | lcd.printStr(ALIGN_CENTER,SCR_HT/2-3,"GAUGES DEMO"); 297 | lcd.display(); 298 | delay(2000); 299 | } 300 | 301 | void loop() 302 | { 303 | ms=millis(); 304 | while(millis()-ms=0;i-=5) { drawGauge1(i); delay(30); } 308 | delay(250); 309 | } 310 | 311 | ms=millis(); 312 | while(millis()-ms=0;i-=5) { drawBar(i); delay(60); } 316 | delay(250); 317 | } 318 | 319 | ms=millis(); 320 | while(millis()-ms=0;i-=2) { drawGauge2(i); delay(40); } 324 | delay(450); 325 | } 326 | 327 | ms=millis(); 328 | while(millis()-ms=0;i-=2) { drawGauge3(i); delay(40); } 337 | delay(450); 338 | } 339 | 340 | ms=millis(); 341 | while(millis()-ms=0;i-=5) { drawGauge4(i); delay(40); } 345 | delay(450); 346 | } 347 | 348 | } 349 | 350 | 351 | --------------------------------------------------------------------------------