// Written by: Widyo Rio
// Subscribe our YT channel: SkwaDrone Salatiga
// Follow our IG n TikTok: @skwadronesalatiga
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_ADDRESS 0x3C
// LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Mendefinisikan ukuran array 2 dimensi
const int rows = 5;
const int cols = 11;
// Array 2 dimensi untuk menyimpan data char (huruf kecil)
char charArray[rows][cols] = {
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'},
{'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v'},
{'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G'},
{'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R'},
{'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ':', '/', '.'}
};
void showKboard(int cc,int rr,String sTmp)
{
display.clearDisplay();
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
display.setCursor(10*j+2, i*10+1);
display.print(charArray[i][j]);
}
}
// display.setCursor(cc*10,rr*10);
// display.print("X");
display.drawRect(cc*10,rr*10,10,10, WHITE);
display.fillRect(0,50,127,13, BLACK);
display.drawRect(0,50,127,13, WHITE);
display.setCursor(2,52);
display.print(sTmp);
//display.drawBitmap(116, 0, bitmap_help, 12, 50, 1);
display.display();
}
void setup() {
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.setTextSize(1);
display.setTextColor(WHITE);
showKboard(0,0,"");
pinMode(12,INPUT_PULLUP);
pinMode(13,INPUT_PULLUP);
pinMode(14,INPUT_PULLUP);
pinMode(25,INPUT_PULLUP);
pinMode(26,INPUT_PULLUP);}
int cc=0,rr=0;
String Hasil="";
void loop() {
if (digitalRead(12)==LOW)
{
cc=cc+1;
if (cc==11) cc=0;
showKboard(cc,rr,Hasil);
}
if (digitalRead(13)==LOW)
{
cc=cc-1;
if (cc<0) cc=10;
showKboard(cc,rr,Hasil);
}
if (digitalRead(25)==LOW)
{
rr=rr-1;
if (rr<0) rr=4;
showKboard(cc,rr,Hasil);
}
if (digitalRead(26)==LOW)
{
rr=rr+1;
if (rr>4) rr=0;
showKboard(cc,rr,Hasil);
}
if (digitalRead(14)==LOW)
{
Hasil = Hasil + charArray[rr][cc];
showKboard(cc,rr,Hasil);
}
}
Loading
ssd1306
ssd1306