Components and supplies
ESP32
2.9inch E-Ink display module
Project description
Code
e-ink_hangman
arduino
1#define ENABLE_GxEPD2_GFX 0 2 3#include <GxEPD2_BW.h> // including both doesn't use more code or ram 4#include <GxEPD2_3C.h> // including both doesn't use more code or ram 5#include <U8g2_for_Adafruit_GFX.h> 6 7GxEPD2_BW<GxEPD2_290_T94_V2, GxEPD2_290_T94_V2::HEIGHT> display(GxEPD2_290_T94_V2(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEM029T94, Waveshare 2.9" V2 variant 8U8G2_FOR_ADAFRUIT_GFX u8g2Fonts; 9 10uint16_t bg = GxEPD_WHITE; 11uint16_t fg = GxEPD_BLACK; 12const char abc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 13char words[] = "HOUSE,CAR,PLANE,WATER,INFORMATION,UNDERSTANDING,KNOWLEDGE,TEMPERATURE,AREA,SOCIETY,ACTIVITY,STORY,INDUSTRY,MEDIA,OVEN,COMMUNITY,DEFINITION,BIVOUAC,CATARACT,CONCOURSE,RUMOUR,FINDING,LAKE,MESSAGE,PHONE,SCENE,DEATH,DISCUSSION,BLOOD,OPINION,CITY,HEART,PHOTO,COLLECTION,IMAGINATION,PASSION,CRITICISM,SOLUTION,ALCOHOL,POSSESSION,DEVICE,ENGINE,ELEVATOR,GUITAR,HOMEWORK,LEADER,TENNIS,CHURCH,COFFE,HAIR,ORANGE,RESTAURANT,SONG,TOWN,ERROR,MEAL,RIVER,CHOCOLATE,COOKIE,GARBAGE,PIANO,POTATO,SALAD,APPLE,BEER,DIAMOND,MIDNIGHT,STRANGER,TIME,WORK,FILM,MONEY,GAME,LIFE,NUMBER,EXPERIENCE,SCHOOL,PRACTICE,RESEARCH,ANSWER,PICTURE,GARDEN,FUTURE,RECORD,NOTHING,WEATHER,CHICKEN,QUESTION,SUN,SPEED,ADVANTAGE,DISCIPLIN,CHALLENGE,SUMMER,VEGETABLE,BREAKFAST,STORM,TELEPHONE,WINTER,HOLIDAY,VACATION,LANDSCAPE,BAR,CHAIR,JACKET,MONITOR,SURPRISE,WEEKEND,ALARM,BICYCLE,CONCERT,SHIP,ENGINEER,"; 14int abc_pointer = 0; 15char word1[] = "h"; 16int length_word1 = 0; 17int number_guessed = 0; 18int hangman_progress = 0; 19int wrong_x = 150; 20 21bool touch1detected = false; 22bool touch2detected = false; 23 24void gotTouch2(){ 25 touch2detected = true; 26} 27void gotTouch1(){ 28 touch1detected = true; 29} 30 31 32void(* resetFunc) (void) = 0; 33 34 35void new_word(){ 36 strcpy(word1, ""); 37 int x = random(1, 114); 38 int count = 0; 39 int j = 0; 40 for(; x > 0; x--){ 41 count = 0; 42 while(words[j] != words[5]){ 43 ++count; 44 ++j; 45 } 46 ++j; 47 } 48 for(int i = j-count-1 ; i < j-1; i++){ 49 strncat(word1, &words[i], 1); 50 } 51 length_word1 = count; 52 return; 53} 54 55 56void draw_hangman(){ 57 display.setPartialWindow(185, 18, 200, 200); 58 display.firstPage(); 59 bool lost = false; 60 do{ 61 switch(hangman_progress){ 62 case 11: 63 display.drawRect(258, 75, 5, 24, fg); 64 lost = true; 65 case 10: 66 display.drawRect(251, 75, 5, 24, fg); 67 case 9: 68 display.fillRect(257, 54, 23, 5, fg); 69 case 8: 70 display.fillRect(234, 54, 23, 5, fg); 71 case 7: 72 display.fillRoundRect(250, 53, 14, 25, 3, fg); 73 case 6: 74 display.drawCircle(257, 48, 5, fg); 75 case 5: 76 display.drawLine(257, 23, 257, 43, fg); 77 case 4: 78 display.drawLine(217, 45, 247, 23, fg); 79 case 3: 80 display.fillRect(217, 20, 45, 6, fg); 81 case 2: 82 display.fillRect(217, 20, 6, 80, fg); 83 case 1: 84 display.fillTriangle(185, 120, 285, 120, 220, 95, fg); 85 break; 86 default: 87 break; 88 } 89 }while(display.nextPage()); 90 91 if(lost){ 92 display.setPartialWindow(0, 35, 150, 35); 93 display.firstPage(); 94 do{ 95 display.fillScreen(GxEPD_WHITE); 96 u8g2Fonts.setCursor(10, 70); 97 u8g2Fonts.print("You lost!"); 98 } 99 while(display.nextPage()); 100 delay(3000); 101 resetFunc(); 102 } 103 104} 105 106 107void setup() 108{ 109 touchAttachInterrupt(T3, gotTouch2, 70); 110 touchAttachInterrupt(T4, gotTouch1, 70); 111 112 randomSeed(analogRead(0)); 113 Serial.begin(115200); 114 115 display.init(); 116 display.setTextColor(GxEPD_BLACK); 117 display.setRotation(1); 118 119 u8g2Fonts.setFont(u8g2_font_logisoso16_tr); 120 121 u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color 122 u8g2Fonts.setBackgroundColor(bg); 123 124 u8g2Fonts.begin(display); // connect u8g2 procedures to Adafruit GFX 125 delay(1000); 126 127 display.firstPage(); 128 do 129 { 130 display.fillScreen(GxEPD_WHITE); 131 u8g2Fonts.setCursor(10, 30); 132 u8g2Fonts.println("A"); 133 //u8g2Fonts.setCursor(10, 110); 134 new_word(); 135 //u8g2Fonts.println(word1); 136 137 for(int i = length_word1-1; i >= 0; i--){ 138 display.fillRect(11+i*12, 112, 8, 3, fg); 139 } 140 141 } 142 while (display.nextPage()); 143} 144 145 146void loop(){ 147 148 touch2detected = false; 149 touch1detected = false; 150 while(!touch2detected && !touch1detected){delay(10);} 151 if(touch1detected){ 152 abc_pointer += 1; 153 if(abc_pointer > 25){abc_pointer = 0;} 154 155 display.setPartialWindow(0, 0, 50, 50); 156 display.firstPage(); 157 158 do{ 159 display.fillScreen(GxEPD_WHITE); 160 u8g2Fonts.setCursor(10, 30); 161 u8g2Fonts.println(abc[abc_pointer]); 162 } 163 while(display.nextPage()); 164 } 165 166 else if(touch2detected){ 167 char character = abc[abc_pointer]; 168 bool character_found = false; 169 for(int i = 0; i < length_word1; i++){ 170 if(word1[i] == character){ 171 character_found = true; 172 display.setPartialWindow(11+i*12, 80, 10, 30); 173 display.firstPage(); 174 do{ 175 display.fillScreen(GxEPD_WHITE); 176 u8g2Fonts.setCursor(11+i*12, 110); 177 u8g2Fonts.println(abc[abc_pointer]); 178 } 179 while(display.nextPage()); 180 181 ++number_guessed; 182 if(number_guessed == length_word1){ 183 display.setPartialWindow(0, 35, 150, 35); 184 display.firstPage(); 185 do{ 186 display.fillScreen(GxEPD_WHITE); 187 u8g2Fonts.setCursor(10, 70); 188 u8g2Fonts.print("You won!"); 189 } 190 while(display.nextPage()); 191 delay(3000); 192 resetFunc(); 193 } 194 195 } 196 } 197 198 if(!character_found){ 199 ++hangman_progress; 200 draw_hangman(); 201 display.setPartialWindow(wrong_x, 0, 200, 14); 202 display.firstPage(); 203 do{ 204 u8g2Fonts.setFont(u8g2_font_7x14_tr); 205 u8g2Fonts.setCursor(wrong_x, 13); 206 u8g2Fonts.print(abc[abc_pointer]); 207 u8g2Fonts.setFont(u8g2_font_logisoso16_tr); 208 wrong_x += 13; 209 }while(display.nextPage()); 210 } 211 212 delay(100); 213 } 214 215}
e-ink_hangman
arduino
1#define ENABLE_GxEPD2_GFX 0 2 3#include <GxEPD2_BW.h> // including both doesn't use more code or ram 4#include <GxEPD2_3C.h> // including both doesn't use more code or ram 5#include <U8g2_for_Adafruit_GFX.h> 6 7GxEPD2_BW<GxEPD2_290_T94_V2, GxEPD2_290_T94_V2::HEIGHT> display(GxEPD2_290_T94_V2(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEM029T94, Waveshare 2.9" V2 variant 8U8G2_FOR_ADAFRUIT_GFX u8g2Fonts; 9 10uint16_t bg = GxEPD_WHITE; 11uint16_t fg = GxEPD_BLACK; 12const char abc[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 13char words[] = "HOUSE,CAR,PLANE,WATER,INFORMATION,UNDERSTANDING,KNOWLEDGE,TEMPERATURE,AREA,SOCIETY,ACTIVITY,STORY,INDUSTRY,MEDIA,OVEN,COMMUNITY,DEFINITION,BIVOUAC,CATARACT,CONCOURSE,RUMOUR,FINDING,LAKE,MESSAGE,PHONE,SCENE,DEATH,DISCUSSION,BLOOD,OPINION,CITY,HEART,PHOTO,COLLECTION,IMAGINATION,PASSION,CRITICISM,SOLUTION,ALCOHOL,POSSESSION,DEVICE,ENGINE,ELEVATOR,GUITAR,HOMEWORK,LEADER,TENNIS,CHURCH,COFFE,HAIR,ORANGE,RESTAURANT,SONG,TOWN,ERROR,MEAL,RIVER,CHOCOLATE,COOKIE,GARBAGE,PIANO,POTATO,SALAD,APPLE,BEER,DIAMOND,MIDNIGHT,STRANGER,TIME,WORK,FILM,MONEY,GAME,LIFE,NUMBER,EXPERIENCE,SCHOOL,PRACTICE,RESEARCH,ANSWER,PICTURE,GARDEN,FUTURE,RECORD,NOTHING,WEATHER,CHICKEN,QUESTION,SUN,SPEED,ADVANTAGE,DISCIPLIN,CHALLENGE,SUMMER,VEGETABLE,BREAKFAST,STORM,TELEPHONE,WINTER,HOLIDAY,VACATION,LANDSCAPE,BAR,CHAIR,JACKET,MONITOR,SURPRISE,WEEKEND,ALARM,BICYCLE,CONCERT,SHIP,ENGINEER,"; 14int abc_pointer = 0; 15char word1[] = "h"; 16int length_word1 = 0; 17int number_guessed = 0; 18int hangman_progress = 0; 19int wrong_x = 150; 20 21bool touch1detected = false; 22bool touch2detected = false; 23 24void gotTouch2(){ 25 touch2detected = true; 26} 27void gotTouch1(){ 28 touch1detected = true; 29} 30 31 32void(* resetFunc) (void) = 0; 33 34 35void new_word(){ 36 strcpy(word1, ""); 37 int x = random(1, 114); 38 int count = 0; 39 int j = 0; 40 for(; x > 0; x--){ 41 count = 0; 42 while(words[j] != words[5]){ 43 ++count; 44 ++j; 45 } 46 ++j; 47 } 48 for(int i = j-count-1 ; i < j-1; i++){ 49 strncat(word1, &words[i], 1); 50 } 51 length_word1 = count; 52 return; 53} 54 55 56void draw_hangman(){ 57 display.setPartialWindow(185, 18, 200, 200); 58 display.firstPage(); 59 bool lost = false; 60 do{ 61 switch(hangman_progress){ 62 case 11: 63 display.drawRect(258, 75, 5, 24, fg); 64 lost = true; 65 case 10: 66 display.drawRect(251, 75, 5, 24, fg); 67 case 9: 68 display.fillRect(257, 54, 23, 5, fg); 69 case 8: 70 display.fillRect(234, 54, 23, 5, fg); 71 case 7: 72 display.fillRoundRect(250, 53, 14, 25, 3, fg); 73 case 6: 74 display.drawCircle(257, 48, 5, fg); 75 case 5: 76 display.drawLine(257, 23, 257, 43, fg); 77 case 4: 78 display.drawLine(217, 45, 247, 23, fg); 79 case 3: 80 display.fillRect(217, 20, 45, 6, fg); 81 case 2: 82 display.fillRect(217, 20, 6, 80, fg); 83 case 1: 84 display.fillTriangle(185, 120, 285, 120, 220, 95, fg); 85 break; 86 default: 87 break; 88 } 89 }while(display.nextPage()); 90 91 if(lost){ 92 display.setPartialWindow(0, 35, 150, 35); 93 display.firstPage(); 94 do{ 95 display.fillScreen(GxEPD_WHITE); 96 u8g2Fonts.setCursor(10, 70); 97 u8g2Fonts.print("You lost!"); 98 } 99 while(display.nextPage()); 100 delay(3000); 101 resetFunc(); 102 } 103 104} 105 106 107void setup() 108{ 109 touchAttachInterrupt(T3, gotTouch2, 70); 110 touchAttachInterrupt(T4, gotTouch1, 70); 111 112 randomSeed(analogRead(0)); 113 Serial.begin(115200); 114 115 display.init(); 116 display.setTextColor(GxEPD_BLACK); 117 display.setRotation(1); 118 119 u8g2Fonts.setFont(u8g2_font_logisoso16_tr); 120 121 u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color 122 u8g2Fonts.setBackgroundColor(bg); 123 124 u8g2Fonts.begin(display); // connect u8g2 procedures to Adafruit GFX 125 delay(1000); 126 127 display.firstPage(); 128 do 129 { 130 display.fillScreen(GxEPD_WHITE); 131 u8g2Fonts.setCursor(10, 30); 132 u8g2Fonts.println("A"); 133 //u8g2Fonts.setCursor(10, 110); 134 new_word(); 135 //u8g2Fonts.println(word1); 136 137 for(int i = length_word1-1; i >= 0; i--){ 138 display.fillRect(11+i*12, 112, 8, 3, fg); 139 } 140 141 } 142 while (display.nextPage()); 143} 144 145 146void loop(){ 147 148 touch2detected = false; 149 touch1detected = false; 150 while(!touch2detected && !touch1detected){delay(10);} 151 if(touch1detected){ 152 abc_pointer += 1; 153 if(abc_pointer > 25){abc_pointer = 0;} 154 155 display.setPartialWindow(0, 0, 50, 50); 156 display.firstPage(); 157 158 do{ 159 display.fillScreen(GxEPD_WHITE); 160 u8g2Fonts.setCursor(10, 30); 161 u8g2Fonts.println(abc[abc_pointer]); 162 } 163 while(display.nextPage()); 164 } 165 166 else if(touch2detected){ 167 char character = abc[abc_pointer]; 168 bool character_found = false; 169 for(int i = 0; i < length_word1; i++){ 170 if(word1[i] == character){ 171 character_found = true; 172 display.setPartialWindow(11+i*12, 80, 10, 30); 173 display.firstPage(); 174 do{ 175 display.fillScreen(GxEPD_WHITE); 176 u8g2Fonts.setCursor(11+i*12, 110); 177 u8g2Fonts.println(abc[abc_pointer]); 178 } 179 while(display.nextPage()); 180 181 ++number_guessed; 182 if(number_guessed == length_word1){ 183 display.setPartialWindow(0, 35, 150, 35); 184 display.firstPage(); 185 do{ 186 display.fillScreen(GxEPD_WHITE); 187 u8g2Fonts.setCursor(10, 70); 188 u8g2Fonts.print("You won!"); 189 } 190 while(display.nextPage()); 191 delay(3000); 192 resetFunc(); 193 } 194 195 } 196 } 197 198 if(!character_found){ 199 ++hangman_progress; 200 draw_hangman(); 201 display.setPartialWindow(wrong_x, 0, 200, 14); 202 display.firstPage(); 203 do{ 204 u8g2Fonts.setFont(u8g2_font_7x14_tr); 205 u8g2Fonts.setCursor(wrong_x, 13); 206 u8g2Fonts.print(abc[abc_pointer]); 207 u8g2Fonts.setFont(u8g2_font_logisoso16_tr); 208 wrong_x += 13; 209 }while(display.nextPage()); 210 } 211 212 delay(100); 213 } 214 215}
Downloadable files
Schematics
Unfortunately I can't create a Fritzing file because the parts are not available there. Just connect all the wires so that the colors match. You also have to look at the pinout of your specific ESP32 board.
Schematics
Comments
Only logged in users can leave comments
galoebn
5 Followers
•9 Projects
0
0