1#include <Wire.h>
2#include <Adafruit_GFX.h>
3#include <Adafruit_SSD1306.h>
4
5#define SCREEN_WIDTH 128
6#define SCREEN_HEIGHT 64
7#define OLED_RESET -1
8#define SCREEN_ADDRESS 0x3C
9
10Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
11
12
13int ReadPin = A0;
14
15int lightLevel = 0;
16
17
18void drawNeutralEyes() {
19 display.clearDisplay();
20
21
22 display.drawCircle(40, 32, 10, SSD1306_WHITE);
23 display.fillCircle(40, 32, 5, SSD1306_WHITE);
24
25
26 display.drawCircle(88, 32, 10, SSD1306_WHITE);
27 display.fillCircle(88, 32, 5, SSD1306_WHITE);
28
29 display.display();
30}
31
32
33void drawClosedEyes() {
34 display.clearDisplay();
35
36
37 display.drawLine(30, 32, 50, 32, SSD1306_WHITE);
38
39
40 display.drawLine(78, 32, 98, 32, SSD1306_WHITE);
41
42 display.display();
43}
44
45
46void blink() {
47 drawClosedEyes();
48 delay(200);
49 drawNeutralEyes();
50}
51
52void setup() {
53
54 Serial.begin(9600);
55
56
57 if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
58 Serial.println(F("SSD1306 allocation failed"));
59 for(;;);
60 }
61
62
63 pinMode(ReadPin, INPUT);
64
65}
66
67void loop() {
68
69 lightLevel = analogRead(ReadPin);
70
71
72 if (lightLevel > 650) {
73 blink();
74 delay(1500);
75 } else {
76 drawClosedEyes();
77 }
78}
prestigesuncre
2 months ago
It Looks Interesting