#include <Adafruit_GFX.h> // include adafruit GFX library
#include <KS0108_GLCD.h> // include KS0108 GLCD library
#define ArrLen(x) (sizeof(x)/sizeof(x[0]))
// KS0108 GLCD library initialization according to the following connection:
// KS0108_GLCD(DI, RW, E, DB0, DB1, DB2, DB3, DB4, DB5, DB6, DB7, CS1, CS2, RES);
KS0108_GLCD display = KS0108_GLCD(A0, A1, A2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
static const unsigned char PROGMEM logo_bmp[] =
{ 0b00000000, 0b11000000,
0b00000001, 0b11000000,
0b00000001, 0b11000000,
0b00000011, 0b11100000,
0b11110011, 0b11100000,
0b11111110, 0b11111000,
0b01111110, 0b11111111,
0b00110011, 0b10011111,
0b00011111, 0b11111100,
0b00001101, 0b01110000,
0b00011011, 0b10100000,
0b00111111, 0b11100000,
0b00111111, 0b11110000,
0b01111100, 0b11110000,
0b01110000, 0b01110000,
0b00000000, 0b00110000 };
// ---------------------------------------------------------------------
// Serial -> CP437
int16_t ascii2lcd(unsigned char input) {
switch(input) {
case 230: return 145; // æ
case 248: return 236; // ø
case 229: return 134; // å
case 198: return 146; // Æ
case 216: return 237; // Ø
case 197: return 143; // Å
default: return input;
}
}
// ---------------------------------------------------------------------
int char2int(char c) {
return (isdigit(c)) ? int(c-'0') : -1;
}
// ---------------------------------------------------------------------
constexpr char ae = -26;
constexpr char oe = -8;
constexpr char aa = -27;
char chars[] = {
//'a', -26, -8, -27
'a', ae, oe, aa
};
char buf[32];
const char str[] = "\xE6";
void setup() {
delay(500);
Serial.begin(9600);
delay(500);
memset(buf, '\0', 32);
while (!Serial && millis() < 3000);
Serial.println( F("display initialization!") );
// initialize KS0108 GLCD module with active high CS pins
if ( display.begin(KS0108_CS_ACTIVE_HIGH) == false ) {
Serial.println( F("display initialization failed!") ); // lack of RAM space
while(true); // stay here forever!
}
display.display();
delay(2000); // Pause for 2 seconds
display.setTextSize(2);
display.setTextColor(KS0108_ON);
display.cp437(true);
// Clear the buffer
display.clearDisplay();
display.println("READY!");
display.display();
delay(2000);
/*
for (byte i=0; i<255; i++)
Serial.print(i),
Serial.print(": "),
Serial.println((char)i);
Serial.println();
*/
display.write(125);
display.display();
}
void loop() {
if (Serial.available() > 0) {
String s = Serial.readStringUntil('\n');
int x = s.toInt();
display.clearDisplay();
display.print(x); display.print(" -> ");
display.write(x); display.println();
display.display();
/*
String s = Serial.readStringUntil('\n');
int x = s.toInt(); x = (x > 255) ? 255 : ((x < 0)?0:x);
char c = x;
Serial.print("int: "); Serial.print(x);
Serial.print(", char: "); Serial.println(c);
display.clearDisplay();
display.print(c); display.print(" -> ");
display.write((byte)c); display.println();
display.display();
*/
}
delay(1);
}