GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Key-Chain-Screen/src/main.cpp at main · Bentarraya/Key-Chain-Screen

Expand file tree

/

main.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
164 lines (136 loc) · 4.38 KB
/

main.cpp

Copy path

File metadata and controls

164 lines (136 loc) · 4.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <FluxGarage_RoboEyes.h>
#include "VideoFrame.h"
// ================= KONFIGURASI =================
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C
#define I2C_SDA 8 // sesuaikan dengan board lu
#define I2C_SCL 9
#define TOUCH_PIN 2 // output modul touch (TTP223 dll)
#define TOUCH_ACTIVE HIGH // TTP223 default HIGH saat disentuh
// Kalau nama array/konstanta di VideoFrame.h beda, ubah 3 baris ini aja
#define VIDEO_FRAMES video_frames // const unsigned char video_frames[][1024] PROGMEM
#define VIDEO_FRAME_COUNT TOTAL_FRAMES // 425 frame
#define VIDEO_FRAME_DELAY FRAME_DELAY // 33 ms (~30 fps)
// Durasi tiap tahap sequence mata (ms)
#define EYE_DEFAULT_MS 3000
#define EYE_HAPPY_MS 3000
#define EYE_LAUGH_MS 2500
#define EYE_ANGRY_MS 3500
#define DEBOUNCE_MS 60 // anti-bouncing per sentuhan
#define DOUBLE_TAP_MS 800 // jeda maksimal antar 2 sentuhan
// ===============================================
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
RoboEyes<Adafruit_SSD1306> roboEyes(display);
enum Mode { MODE_EYES, MODE_VIDEO };
Mode currentMode = MODE_EYES;
// state sequence mata
uint8_t eyeStep = 0;
unsigned long eyeStepStart = 0;
// state video
uint16_t videoIdx = 0;
unsigned long lastFrameTime = 0;
// state touch
bool lastTouch = false;
unsigned long lastTouchTime = 0;
uint8_t touchCount = 0;
unsigned long firstTouchTime = 0;
void startEyes() {
currentMode = MODE_EYES;
eyeStep = 0;
eyeStepStart = millis();
roboEyes.setMood(DEFAULT); // mulai dari ekspresi default
}
void startVideo() {
currentMode = MODE_VIDEO;
videoIdx = 0;
lastFrameTime = 0;
}
void updateEyes() {
unsigned long now = millis();
switch (eyeStep) {
case 0: // default (tanpa ekspresi) -> senang
if (now - eyeStepStart >= EYE_DEFAULT_MS) {
eyeStep = 1;
eyeStepStart = now;
roboEyes.setMood(HAPPY);
}
break;
case 1: // senang -> ketawa
if (now - eyeStepStart >= EYE_HAPPY_MS) {
eyeStep = 2;
eyeStepStart = now;
roboEyes.setMood(HAPPY);
roboEyes.anim_laugh();
}
break;
case 2: // ketawa -> marah
if (now - eyeStepStart >= EYE_LAUGH_MS) {
eyeStep = 3;
eyeStepStart = now;
roboEyes.setMood(ANGRY);
}
break;
case 3: // marah -> balik default (loop)
if (now - eyeStepStart >= EYE_ANGRY_MS) {
eyeStep = 0;
eyeStepStart = now;
roboEyes.setMood(DEFAULT);
}
break;
}
roboEyes.update(); // gambar mata (non-blocking)
}
void updateVideo() {
unsigned long now = millis();
if (now - lastFrameTime < VIDEO_FRAME_DELAY) return;
lastFrameTime = now;
display.clearDisplay();
display.drawBitmap(0, 0, VIDEO_FRAMES[videoIdx], SCREEN_WIDTH, SCREEN_HEIGHT, SSD1306_WHITE);
display.display();
videoIdx++;
if (videoIdx >= VIDEO_FRAME_COUNT) videoIdx = 0; // loop terus
}
void checkTouch() {
bool touched = (digitalRead(TOUCH_PIN) == TOUCH_ACTIVE);
unsigned long now = millis();
// rising edge + debounce = 1 sentuhan valid
if (touched && !lastTouch && (now - lastTouchTime > DEBOUNCE_MS)) {
lastTouchTime = now;
if (touchCount == 0) {
touchCount = 1; // sentuhan pertama, tunggu yang kedua
firstTouchTime = now;
} else if (now - firstTouchTime <= DOUBLE_TAP_MS) {
touchCount = 0; // sentuhan kedua tepat waktu -> pindah animasi
if (currentMode == MODE_EYES) startVideo();
else startEyes();
}
}
lastTouch = touched;
// kalau sentuhan kedua telat, anggap batal
if (touchCount == 1 && (now - firstTouchTime > DOUBLE_TAP_MS)) {
touchCount = 0;
}
}
void setup() {
Serial.begin(115200);
pinMode(TOUCH_PIN, INPUT);
Wire.begin(I2C_SDA, I2C_SCL);
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println(F("OLED ga ketemu, cek wiring!"));
for (;;) delay(1000);
}
roboEyes.begin(SCREEN_WIDTH, SCREEN_HEIGHT, 60); // 60 fps
roboEyes.setAutoblinker(ON, 3, 2);
roboEyes.setIdleMode(ON, 2, 2);
startEyes(); // boot -> default -> senang -> ketawa -> marah -> loop
}
void loop() {
checkTouch();
if (currentMode == MODE_EYES) updateEyes();
else updateVideo();
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.