├── QR_Code ├── BuildQRTemplate.ino ├── DisplayQR.ino ├── QR_Code.ino └── generateBits.ino ├── README.md └── TFT Libraries └── TouchScreen ├── README.txt ├── TouchScreen.cpp └── TouchScreen.h /QR_Code/BuildQRTemplate.ino: -------------------------------------------------------------------------------- 1 | void drawTemplate() 2 | { 3 | 4 | //TOP LEFT CORNER OUTER BOX 5 | Tft.fillRectangle(10,250,10,10,BLACK); 6 | Tft.fillRectangle(10,240,10,10,BLACK); 7 | Tft.fillRectangle(10,230,10,10,BLACK); 8 | Tft.fillRectangle(10,220,10,10,BLACK); 9 | Tft.fillRectangle(10,210,10,10,BLACK); 10 | Tft.fillRectangle(10,200,10,10,BLACK); 11 | Tft.fillRectangle(10,190,10,10,BLACK); 12 | 13 | 14 | Tft.fillRectangle(20,250,10,10,BLACK); 15 | Tft.fillRectangle(30,250,10,10,BLACK); 16 | Tft.fillRectangle(40,250,10,10,BLACK); 17 | Tft.fillRectangle(50,250,10,10,BLACK); 18 | Tft.fillRectangle(60,250,10,10,BLACK); 19 | Tft.fillRectangle(70,250,10,10,BLACK); 20 | 21 | Tft.fillRectangle(70,240,10,10,BLACK); 22 | Tft.fillRectangle(70,230,10,10,BLACK); 23 | Tft.fillRectangle(70,220,10,10,BLACK); 24 | Tft.fillRectangle(70,210,10,10,BLACK); 25 | Tft.fillRectangle(70,200,10,10,BLACK); 26 | Tft.fillRectangle(70,190,10,10,BLACK); 27 | 28 | Tft.fillRectangle(60,190,10,10,BLACK); 29 | Tft.fillRectangle(50,190,10,10,BLACK); 30 | Tft.fillRectangle(40,190,10,10,BLACK); 31 | Tft.fillRectangle(30,190,10,10,BLACK); 32 | Tft.fillRectangle(20,190,10,10,BLACK); 33 | //TOP LEFT CORNER OUTER BOX END 34 | 35 | //TOP LEFT CORNER INSIDE BOX START 36 | Tft.fillRectangle(30,230,10,10,BLACK); 37 | Tft.fillRectangle(30,220,10,10,BLACK); 38 | Tft.fillRectangle(30,210,10,10,BLACK); 39 | 40 | Tft.fillRectangle(40,230,10,10,BLACK); 41 | Tft.fillRectangle(40,220,10,10,BLACK); 42 | Tft.fillRectangle(40,210,10,10,BLACK); 43 | 44 | Tft.fillRectangle(50,230,10,10,BLACK); 45 | Tft.fillRectangle(50,220,10,10,BLACK); 46 | Tft.fillRectangle(50,210,10,10,BLACK); 47 | //TOP LEFT CORNER INSIDE BOX END 48 | 49 | //TOP RIGHT OUTER BOX START 50 | Tft.fillRectangle(10,50,10,10,BLACK); 51 | Tft.fillRectangle(10,60,10,10,BLACK); 52 | Tft.fillRectangle(10,70,10,10,BLACK); 53 | Tft.fillRectangle(10,80,10,10,BLACK); 54 | Tft.fillRectangle(10,90,10,10,BLACK); 55 | Tft.fillRectangle(10,100,10,10,BLACK); 56 | Tft.fillRectangle(10,110,10,10,BLACK); 57 | 58 | Tft.fillRectangle(20,50,10,10,BLACK); 59 | Tft.fillRectangle(30,50,10,10,BLACK); 60 | Tft.fillRectangle(40,50,10,10,BLACK); 61 | Tft.fillRectangle(50,50,10,10,BLACK); 62 | Tft.fillRectangle(60,50,10,10,BLACK); 63 | Tft.fillRectangle(70,50,10,10,BLACK); 64 | 65 | Tft.fillRectangle(70,60,10,10,BLACK); 66 | Tft.fillRectangle(70,70,10,10,BLACK); 67 | Tft.fillRectangle(70,80,10,10,BLACK); 68 | Tft.fillRectangle(70,90,10,10,BLACK); 69 | Tft.fillRectangle(70,100,10,10,BLACK); 70 | Tft.fillRectangle(70,110,10,10,BLACK); 71 | 72 | Tft.fillRectangle(60,110,10,10,BLACK); 73 | Tft.fillRectangle(50,110,10,10,BLACK); 74 | Tft.fillRectangle(40,110,10,10,BLACK); 75 | Tft.fillRectangle(30,110,10,10,BLACK); 76 | Tft.fillRectangle(20,110,10,10,BLACK); 77 | //TOP RIGHT OUTER BOX END 78 | 79 | //TOP RIGHT INNER BOX START 80 | Tft.fillRectangle(30,90,10,10,BLACK); 81 | Tft.fillRectangle(30,80,10,10,BLACK); 82 | Tft.fillRectangle(30,70,10,10,BLACK); 83 | 84 | Tft.fillRectangle(40,90,10,10,BLACK); 85 | Tft.fillRectangle(40,80,10,10,BLACK); 86 | Tft.fillRectangle(40,70,10,10,BLACK); 87 | 88 | Tft.fillRectangle(50,90,10,10,BLACK); 89 | Tft.fillRectangle(50,80,10,10,BLACK); 90 | Tft.fillRectangle(50,70,10,10,BLACK); 91 | //TOP RIGHT INNER BOX END 92 | 93 | 94 | //BOTTOM RIGHT OUTER BOX START 95 | Tft.fillRectangle(210,250,10,10,BLACK); 96 | Tft.fillRectangle(200,250,10,10,BLACK); 97 | Tft.fillRectangle(190,250,10,10,BLACK); 98 | Tft.fillRectangle(180,250,10,10,BLACK); 99 | Tft.fillRectangle(170,250,10,10,BLACK); 100 | Tft.fillRectangle(160,250,10,10,BLACK); 101 | Tft.fillRectangle(150,250,10,10,BLACK); 102 | 103 | Tft.fillRectangle(210,240,10,10,BLACK); 104 | Tft.fillRectangle(210,230,10,10,BLACK); 105 | Tft.fillRectangle(210,220,10,10,BLACK); 106 | Tft.fillRectangle(210,210,10,10,BLACK); 107 | Tft.fillRectangle(210,200,10,10,BLACK); 108 | Tft.fillRectangle(210,190,10,10,BLACK); 109 | 110 | Tft.fillRectangle(200,190,10,10,BLACK); 111 | Tft.fillRectangle(190,190,10,10,BLACK); 112 | Tft.fillRectangle(180,190,10,10,BLACK); 113 | Tft.fillRectangle(170,190,10,10,BLACK); 114 | Tft.fillRectangle(160,190,10,10,BLACK); 115 | Tft.fillRectangle(150,190,10,10,BLACK); 116 | 117 | Tft.fillRectangle(150,200,10,10,BLACK); 118 | Tft.fillRectangle(150,210,10,10,BLACK); 119 | Tft.fillRectangle(150,220,10,10,BLACK); 120 | Tft.fillRectangle(150,230,10,10,BLACK); 121 | Tft.fillRectangle(150,240,10,10,BLACK); 122 | //BOTTOM RIGHT OUTER BOX END 123 | 124 | //BOTTOM RIGHT INNER BOX START 125 | Tft.fillRectangle(170,230,10,10,BLACK); 126 | Tft.fillRectangle(170,220,10,10,BLACK); 127 | Tft.fillRectangle(170,210,10,10,BLACK); 128 | 129 | Tft.fillRectangle(180,230,10,10,BLACK); 130 | Tft.fillRectangle(180,220,10,10,BLACK); 131 | Tft.fillRectangle(180,210,10,10,BLACK); 132 | 133 | Tft.fillRectangle(190,230,10,10,BLACK); 134 | Tft.fillRectangle(190,220,10,10,BLACK); 135 | Tft.fillRectangle(190,210,10,10,BLACK); 136 | //BOTTOM RIGHT INNER BOX END 137 | 138 | //Timing Pattern 139 | Tft.fillRectangle(70,170,10,10,BLACK); 140 | Tft.fillRectangle(70,150,10,10,BLACK); 141 | Tft.fillRectangle(70,130,10,10,BLACK); 142 | 143 | Tft.fillRectangle(90,190,10,10,BLACK); 144 | Tft.fillRectangle(110,190,10,10,BLACK); 145 | Tft.fillRectangle(130,190,10,10,BLACK); 146 | 147 | Tft.fillRectangle(140,170,10,10,BLACK); 148 | //end Timing Pattern 149 | } 150 | -------------------------------------------------------------------------------- /QR_Code/DisplayQR.ino: -------------------------------------------------------------------------------- 1 | void informationBits() 2 | { 3 | 4 | //format & version information fields 5 | for(int i = 210; i > 140; i-=10){ 6 | if(TypeInfomationBits[counter] == 1){ 7 | Tft.fillRectangle(i,170,10,10,BLACK); 8 | }else{ 9 | Tft.fillRectangle(i,170,10,10,WHITE); 10 | } 11 | counter += 1; 12 | } 13 | 14 | for(int i = 120; i > 40; i-=10){ 15 | if(TypeInfomationBits[counter] == 1){ 16 | Tft.fillRectangle(90,i,10,10,BLACK); 17 | }else{ 18 | Tft.fillRectangle(90,i,10,10,WHITE); 19 | } 20 | counter += 1; 21 | } 22 | 23 | //Clear counter to display information bits again 24 | counter = 0; 25 | 26 | for(int i = 250; i > 190; i-=10){ 27 | if(TypeInfomationBits[counter] == 1){ 28 | Tft.fillRectangle(90,i,10,10,BLACK); 29 | }else{ 30 | Tft.fillRectangle(90,i,10,10,WHITE); 31 | } 32 | counter += 1; 33 | } 34 | 35 | if(TypeInfomationBits[counter] == 1){ 36 | Tft.fillRectangle(90,180,10,10,BLACK); 37 | }else{ 38 | Tft.fillRectangle(90,180,10,10,WHITE); 39 | } 40 | counter += 1; 41 | 42 | if(TypeInfomationBits[counter] == 1){ 43 | Tft.fillRectangle(90,170,10,10,BLACK); 44 | }else{ 45 | Tft.fillRectangle(90,170,10,10,WHITE); 46 | } 47 | counter += 1; 48 | 49 | if(TypeInfomationBits[counter] == 1){ 50 | Tft.fillRectangle(80,170,10,10,BLACK); 51 | }else{ 52 | Tft.fillRectangle(80,170,10,10,WHITE); 53 | } 54 | counter += 1; 55 | 56 | for(int i = 60; i > 0; i-=10){ 57 | if(TypeInfomationBits[counter] == 1){ 58 | Tft.fillRectangle(i,170,10,10,BLACK); 59 | }else{ 60 | Tft.fillRectangle(i,170,10,10,WHITE); 61 | } 62 | counter += 1; 63 | } 64 | 65 | //end format & version 66 | //clear counter for message bits 67 | counter = 0; 68 | 69 | //Write Data Bits 70 | //up 71 | for(int xPos = 210; xPos > 90; xPos-=10){ 72 | for(int yPos = 50; yPos < 70; yPos+=10){ 73 | getXY(xPos, yPos); 74 | int mask = (y + x) % 2; 75 | if(mask == 0){ 76 | if(BinaryMessage[counter] == 1){ 77 | //Do oposite 78 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 79 | } 80 | if(BinaryMessage[counter] == 0){ 81 | //Do oposite 82 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 83 | } 84 | }else if(mask == 1){ 85 | if(BinaryMessage[counter] == 1){ 86 | //Do oposite 87 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 88 | } 89 | if(BinaryMessage[counter] == 0){ 90 | //Do oposite 91 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 92 | } 93 | } 94 | counter += 1; 95 | } 96 | } 97 | 98 | 99 | 100 | 101 | //down 102 | for(int xPos = 100; xPos < 220; xPos +=10){ 103 | for(int yPos = 70; yPos < 90; yPos+=10){ 104 | getXY(xPos, yPos); 105 | int mask = (y + x) % 2; 106 | if(mask == 0){ 107 | if(BinaryMessage[counter] == 1){ 108 | //Do oposite 109 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 110 | } 111 | if(BinaryMessage[counter] == 0){ 112 | //Do oposite 113 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 114 | } 115 | }else if(mask == 1){ 116 | if(BinaryMessage[counter] == 1){ 117 | //Do oposite 118 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 119 | } 120 | if(BinaryMessage[counter] == 0){ 121 | //Do oposite 122 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 123 | } 124 | } 125 | counter += 1; 126 | 127 | } 128 | } 129 | 130 | 131 | //up 132 | for(int xPos = 210; xPos > 90; xPos-=10){ 133 | for(int yPos = 90; yPos < 110; yPos+=10){ 134 | getXY(xPos, yPos); 135 | int mask = (y + x) % 2; 136 | if(mask == 0){ 137 | if(BinaryMessage[counter] == 1){ 138 | //Do oposite 139 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 140 | } 141 | if(BinaryMessage[counter] == 0){ 142 | //Do oposite 143 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 144 | } 145 | }else if(mask == 1){ 146 | if(BinaryMessage[counter] == 1){ 147 | //Do oposite 148 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 149 | } 150 | if(BinaryMessage[counter] == 0){ 151 | //Do oposite 152 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 153 | } 154 | } 155 | counter += 1; 156 | 157 | } 158 | } 159 | 160 | 161 | //down 162 | for(int xPos = 100; xPos < 220; xPos +=10){ 163 | for(int yPos = 110; yPos < 130; yPos+=10){ 164 | getXY(xPos, yPos); 165 | int mask = (y + x) % 2; 166 | if(mask == 0){ 167 | if(BinaryMessage[counter] == 1){ 168 | //Do oposite 169 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 170 | } 171 | if(BinaryMessage[counter] == 0){ 172 | //Do oposite 173 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 174 | } 175 | }else if(mask == 1){ 176 | if(BinaryMessage[counter] == 1){ 177 | //Do oposite 178 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 179 | } 180 | if(BinaryMessage[counter] == 0){ 181 | //Do oposite 182 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 183 | } 184 | } 185 | counter += 1; 186 | } 187 | } 188 | 189 | 190 | //up 191 | for(int xPos = 210; xPos > 170; xPos-=10){ 192 | for(int yPos = 130; yPos < 150; yPos+=10){ 193 | getXY(xPos, yPos); 194 | int mask = (y + x) % 2; 195 | if(mask == 0){ 196 | if(BinaryMessage[counter] == 1){ 197 | //Do oposite 198 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 199 | } 200 | if(BinaryMessage[counter] == 0){ 201 | //Do oposite 202 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 203 | } 204 | }else if(mask == 1){ 205 | if(BinaryMessage[counter] == 1){ 206 | //Do oposite 207 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 208 | } 209 | if(BinaryMessage[counter] == 0){ 210 | //Do oposite 211 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 212 | } 213 | } 214 | counter += 1; 215 | 216 | } 217 | } 218 | 219 | 220 | //Clear counter to begin ECC Bits 221 | counter = 0; 222 | //continue up 223 | for(int xPos = 170; xPos > 70; xPos-=10){ 224 | for(int yPos = 130; yPos < 150; yPos+=10){ 225 | getXY(xPos, yPos); 226 | int mask = (y + x) % 2; 227 | if(mask == 0){ 228 | if(BinaryECCWords[counter] == 1){ 229 | //Do oposite 230 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 231 | } 232 | if(BinaryECCWords[counter] == 0){ 233 | //Do oposite 234 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 235 | } 236 | }else if(mask == 1){ 237 | if(BinaryECCWords[counter] == 1){ 238 | //Do oposite 239 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 240 | } 241 | if(BinaryECCWords[counter] == 0){ 242 | //Do oposite 243 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 244 | } 245 | } 246 | counter += 1; 247 | 248 | } 249 | } 250 | 251 | 252 | //skip over timing pattern 253 | //up 254 | for(int xPos = 60; xPos > 0; xPos-=10){ 255 | for(int yPos = 130; yPos < 150; yPos+=10){ 256 | getXY(xPos, yPos); 257 | int mask = (y + x) % 2; 258 | if(mask == 0){ 259 | if(BinaryECCWords[counter] == 1){ 260 | //Do oposite 261 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 262 | } 263 | if(BinaryECCWords[counter] == 0){ 264 | //Do oposite 265 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 266 | } 267 | }else if(mask == 1){ 268 | if(BinaryECCWords[counter] == 1){ 269 | //Do oposite 270 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 271 | } 272 | if(BinaryECCWords[counter] == 0){ 273 | //Do oposite 274 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 275 | } 276 | } 277 | counter += 1; 278 | } 279 | } 280 | 281 | 282 | //down 283 | for(int xPos = 10; xPos < 70; xPos +=10){ 284 | for(int yPos = 150; yPos < 170; yPos+=10){ 285 | getXY(xPos, yPos); 286 | int mask = (y + x) % 2; 287 | if(mask == 0){ 288 | if(BinaryECCWords[counter] == 1){ 289 | //Do oposite 290 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 291 | } 292 | if(BinaryECCWords[counter] == 0){ 293 | //Do oposite 294 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 295 | } 296 | }else if(mask == 1){ 297 | if(BinaryECCWords[counter] == 1){ 298 | //Do oposite 299 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 300 | } 301 | if(BinaryECCWords[counter] == 0){ 302 | //Do oposite 303 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 304 | } 305 | } 306 | counter += 1; 307 | } 308 | } 309 | 310 | //skip over timing pattern 311 | //down 312 | for(int xPos = 80; xPos < 220; xPos +=10){ 313 | for(int yPos = 150; yPos < 170; yPos+=10){ 314 | getXY(xPos, yPos); 315 | int mask = (y + x) % 2; 316 | if(mask == 0){ 317 | if(BinaryECCWords[counter] == 1){ 318 | //Do oposite 319 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 320 | } 321 | if(BinaryECCWords[counter] == 0){ 322 | //Do oposite 323 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 324 | } 325 | }else if(mask == 1){ 326 | if(BinaryECCWords[counter] == 1){ 327 | //Do oposite 328 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 329 | } 330 | if(BinaryECCWords[counter] == 0){ 331 | //Do oposite 332 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 333 | } 334 | } 335 | counter += 1; 336 | } 337 | } 338 | 339 | 340 | //up 341 | for(int xPos = 130; xPos > 90; xPos-=10){ 342 | for(int yPos = 170; yPos < 190; yPos+=10){ 343 | getXY(xPos, yPos); 344 | int mask = (y + x) % 2; 345 | if(mask == 0){ 346 | if(BinaryECCWords[counter] == 1){ 347 | //Do oposite 348 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 349 | } 350 | if(BinaryECCWords[counter] == 0){ 351 | //Do oposite 352 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 353 | } 354 | }else if(mask == 1){ 355 | if(BinaryECCWords[counter] == 1){ 356 | //Do oposite 357 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 358 | } 359 | if(BinaryECCWords[counter] == 0){ 360 | //Do oposite 361 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 362 | } 363 | } 364 | counter += 1; 365 | } 366 | } 367 | 368 | 369 | //down 370 | for(int xPos = 100; xPos < 140; xPos +=10){ 371 | for(int yPos = 200; yPos < 220; yPos+=10){ 372 | getXY(xPos, yPos); 373 | int mask = (y + x) % 2; 374 | if(mask == 0){ 375 | if(BinaryECCWords[counter] == 1){ 376 | //Do oposite 377 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 378 | } 379 | if(BinaryECCWords[counter] == 0){ 380 | //Do oposite 381 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 382 | } 383 | }else if(mask == 1){ 384 | if(BinaryECCWords[counter] == 1){ 385 | //Do oposite 386 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 387 | } 388 | if(BinaryECCWords[counter] == 0){ 389 | //Do oposite 390 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 391 | } 392 | } 393 | counter += 1; 394 | } 395 | } 396 | 397 | 398 | 399 | //up 400 | for(int xPos = 130; xPos > 90; xPos-=10){ 401 | for(int yPos = 220; yPos < 240; yPos+=10){ 402 | getXY(xPos, yPos); 403 | int mask = (y + x) % 2; 404 | if(mask == 0){ 405 | if(BinaryECCWords[counter] == 1){ 406 | //Do oposite 407 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 408 | } 409 | if(BinaryECCWords[counter] == 0){ 410 | //Do oposite 411 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 412 | } 413 | }else if(mask == 1){ 414 | if(BinaryECCWords[counter] == 1){ 415 | //Do oposite 416 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 417 | } 418 | if(BinaryECCWords[counter] == 0){ 419 | //Do oposite 420 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 421 | } 422 | } 423 | counter += 1; 424 | } 425 | } 426 | 427 | //down 428 | for(int xPos = 100; xPos < 140; xPos +=10){ 429 | for(int yPos = 240; yPos < 260; yPos+=10){ 430 | getXY(xPos, yPos); 431 | int mask = (y + x) % 2; 432 | if(mask == 0){ 433 | if(BinaryECCWords[counter] == 1){ 434 | //Do oposite 435 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 436 | } 437 | if(BinaryECCWords[counter] == 0){ 438 | //Do oposite 439 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 440 | } 441 | }else if(mask == 1){ 442 | if(BinaryECCWords[counter] == 1){ 443 | //Do oposite 444 | Tft.fillRectangle(xPos,yPos,10,10,BLACK); 445 | } 446 | if(BinaryECCWords[counter] == 0){ 447 | //Do oposite 448 | Tft.fillRectangle(xPos,yPos,10,10,WHITE); 449 | } 450 | } 451 | counter += 1; 452 | } 453 | } 454 | 455 | counter = 0; 456 | 457 | } 458 | 459 | void getXY(int x1, int y1) 460 | { 461 | if(y1 == 50){ 462 | x = 1; 463 | } 464 | if(y1 == 60){ 465 | x = 2; 466 | } 467 | if(y1 == 70){ 468 | x = 3; 469 | } 470 | if(y1 == 80){ 471 | x = 4; 472 | } 473 | if(y1 == 90){ 474 | x = 5; 475 | } 476 | if(y1 == 100){ 477 | x = 6; 478 | } 479 | if(y1 == 110){ 480 | x = 7; 481 | } 482 | if(y1 == 120){ 483 | x = 8; 484 | } 485 | if(y1 == 130){ 486 | x = 9; 487 | } 488 | if(y1 == 140){ 489 | x = 10; 490 | } 491 | if(y1 == 150){ 492 | x = 11; 493 | } 494 | if(y1 == 160){ 495 | x = 12; 496 | } 497 | if(y1 == 170){ 498 | x = 13; 499 | } 500 | if(y1 == 180){ 501 | x = 14; 502 | } 503 | if(y1 == 190){ 504 | x = 15; 505 | } 506 | if(y1 == 200){ 507 | x = 16; 508 | } 509 | if(y1 == 210){ 510 | x = 17; 511 | } 512 | if(y1 == 220){ 513 | x = 18; 514 | } 515 | if(y1 == 230){ 516 | x = 19; 517 | } 518 | if(y1 == 240){ 519 | x = 20; 520 | } 521 | if(y1 == 250){ 522 | x = 21; 523 | } 524 | 525 | 526 | if(x1 == 210){ 527 | y = 1; 528 | } 529 | 530 | if(x1 == 200){ 531 | y = 2; 532 | } 533 | if(x1 == 190){ 534 | y = 3; 535 | } 536 | 537 | if(x1 == 180){ 538 | y = 4; 539 | } 540 | if(x1 == 170){ 541 | y = 5; 542 | } 543 | 544 | if(x1 == 160){ 545 | y = 6; 546 | } 547 | if(x1 == 150){ 548 | y = 7; 549 | } 550 | 551 | if(x1 == 140){ 552 | y = 8; 553 | } 554 | 555 | if(x1 == 130){ 556 | y = 9; 557 | } 558 | 559 | if(x1 == 120){ 560 | y = 10; 561 | } 562 | 563 | if(x1 == 110){ 564 | y = 11; 565 | } 566 | if(x1 == 100){ 567 | y = 12; 568 | } 569 | 570 | if(x1 == 90){ 571 | y = 13; 572 | } 573 | 574 | if(x1 == 80){ 575 | y = 14; 576 | } 577 | 578 | if(x1 == 70){ 579 | y = 15; 580 | } 581 | 582 | if(x1 == 60){ 583 | y = 16; 584 | } 585 | 586 | if(x1 == 50){ 587 | y = 17; 588 | } 589 | 590 | if(x1 == 40){ 591 | y = 18; 592 | } 593 | 594 | if(x1 == 30){ 595 | y = 19; 596 | } 597 | 598 | if(x1 == 20){ 599 | y = 20; 600 | } 601 | 602 | if(x1 == 10){ 603 | y = 21; 604 | } 605 | 606 | } 607 | 608 | -------------------------------------------------------------------------------- /QR_Code/QR_Code.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This program takes the current time & displays it as an QR code 3 | So far this program is capable of converting numbers 0-9, & 4 | characters : and (space) into QR code format. Then displays 5 | that information as a QR code on the screen. 6 | */ 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef SEEEDUINO 12 | #define YP A2 // must be an analog pin, use "An" notation! 13 | #define XM A1 // must be an analog pin, use "An" notation! 14 | #define YM 14 // can be a digital pin, this is A0 15 | #define XP 17 // can be a digital pin, this is A3 16 | #endif 17 | 18 | #ifdef MEGA 19 | #define YP A2 // must be an analog pin, use "An" notation! 20 | #define XM A1 // must be an analog pin, use "An" notation! 21 | #define YM 54 // can be a digital pin, this is A0 22 | #define XP 57 // can be a digital pin, this is A3 23 | #endif 24 | 25 | 26 | //Set to true to enable serial debug information 27 | boolean debug = true; 28 | 29 | /* 30 | Log/Anti-Log table used to switch between integer notation 31 | and alpha notation when performing arithmetic to calculate 32 | ecc bits. Arduino supports log functions but does not work 33 | in the same way as this table does. 34 | */ 35 | 36 | unsigned int LogTable[255][4] = { 37 | {1,2,1,0}, 38 | {2,4,2,1}, 39 | {3,8,3,25}, 40 | {4,16,4,2}, 41 | {5,32,5,50}, 42 | {6,64,6,26}, 43 | {7,128,7,198}, 44 | {8,29,8,3}, 45 | {9,58,9,223}, 46 | {10,116,10,51}, 47 | {11,232,11,238}, 48 | {12,205,12,27}, 49 | {13,135,13,104}, 50 | {14,19,14,199}, 51 | {15,38,15,75}, 52 | {16,76,16,4}, 53 | {17,152,17,100}, 54 | {18,45,18,224}, 55 | {19,90,19,14}, 56 | {20,180,20,52}, 57 | {21,117,21,141}, 58 | {22,234,22,239}, 59 | {23,201,23,129}, 60 | {24,143,24,28}, 61 | {25,3,25,193}, 62 | {26,6,26,105}, 63 | {27,12,27,248}, 64 | {28,24,28,200}, 65 | {29,48,29,8}, 66 | {30,96,30,76}, 67 | {31,192,31,113}, 68 | {32,157,32,5}, 69 | {33,39,33,138}, 70 | {34,78,34,101}, 71 | {35,156,35,47}, 72 | {36,37,36,225}, 73 | {37,74,37,36}, 74 | {38,148,38,15}, 75 | {39,53,39,33}, 76 | {40,106,40,53}, 77 | {41,212,41,147}, 78 | {42,181,42,142}, 79 | {43,119,43,218}, 80 | {44,238,44,240}, 81 | {45,193,45,18}, 82 | {46,159,46,130}, 83 | {47,35,47,69}, 84 | {48,70,48,29}, 85 | {49,140,49,181}, 86 | {50,5,50,194}, 87 | {51,10,51,125}, 88 | {52,20,52,106}, 89 | {53,40,53,39}, 90 | {54,80,54,249}, 91 | {55,160,55,185}, 92 | {56,93,56,201}, 93 | {57,186,57,154}, 94 | {58,105,58,9}, 95 | {59,210,59,120}, 96 | {60,185,60,77}, 97 | {61,111,61,228}, 98 | {62,222,62,114}, 99 | {63,161,63,166}, 100 | {64,95,64,6}, 101 | {65,190,65,191}, 102 | {66,97,66,139}, 103 | {67,194,67,98}, 104 | {68,153,68,102}, 105 | {69,47,69,221}, 106 | {70,94,70,48}, 107 | {71,188,71,253}, 108 | {72,101,72,226}, 109 | {73,202,73,152}, 110 | {74,137,74,37}, 111 | {75,15,75,179}, 112 | {76,30,76,16}, 113 | {77,60,77,145}, 114 | {78,120,78,34}, 115 | {79,240,79,136}, 116 | {80,253,80,54}, 117 | {81,231,81,208}, 118 | {82,211,82,148}, 119 | {83,187,83,206}, 120 | {84,107,84,143}, 121 | {85,214,85,150}, 122 | {86,177,86,219}, 123 | {87,127,87,189}, 124 | {88,254,88,241}, 125 | {89,225,89,210}, 126 | {90,223,90,19}, 127 | {91,163,91,92}, 128 | {92,91,92,131}, 129 | {93,182,93,56}, 130 | {94,113,94,70}, 131 | {95,226,95,64}, 132 | {96,217,96,30}, 133 | {97,175,97,66}, 134 | {98,67,98,182}, 135 | {99,134,99,163}, 136 | {100,17,100,195}, 137 | {101,34,101,72}, 138 | {102,68,102,126}, 139 | {103,136,103,110}, 140 | {104,13,104,107}, 141 | {105,26,105,58}, 142 | {106,52,106,40}, 143 | {107,104,107,84}, 144 | {108,208,108,250}, 145 | {109,189,109,133}, 146 | {110,103,110,186}, 147 | {111,206,111,61}, 148 | {112,129,112,202}, 149 | {113,31,113,94}, 150 | {114,62,114,155}, 151 | {115,124,115,159}, 152 | {116,248,116,10}, 153 | {117,237,117,21}, 154 | {118,199,118,121}, 155 | {119,147,119,43}, 156 | {120,59,120,78}, 157 | {121,118,121,212}, 158 | {122,236,122,229}, 159 | {123,197,123,172}, 160 | {124,151,124,115}, 161 | {125,51,125,243}, 162 | {126,102,126,167}, 163 | {127,204,127,87}, 164 | {128,133,128,7}, 165 | {129,23,129,112}, 166 | {130,46,130,192}, 167 | {131,92,131,247}, 168 | {132,184,132,140}, 169 | {133,109,133,128}, 170 | {134,218,134,99}, 171 | {135,169,135,13}, 172 | {136,79,136,103}, 173 | {137,158,137,74}, 174 | {138,33,138,222}, 175 | {139,66,139,237}, 176 | {140,132,140,49}, 177 | {141,21,141,197}, 178 | {142,42,142,254}, 179 | {143,84,143,24}, 180 | {144,168,144,227}, 181 | {145,77,145,165}, 182 | {146,154,146,153}, 183 | {147,41,147,119}, 184 | {148,82,148,38}, 185 | {149,164,149,184}, 186 | {150,85,150,180}, 187 | {151,170,151,124}, 188 | {152,73,152,17}, 189 | {153,146,153,68}, 190 | {154,57,154,146}, 191 | {155,114,155,217}, 192 | {156,228,156,35}, 193 | {157,213,157,32}, 194 | {158,183,158,137}, 195 | {159,115,159,46}, 196 | {160,230,160,55}, 197 | {161,209,161,63}, 198 | {162,191,162,209}, 199 | {163,99,163,91}, 200 | {164,198,164,149}, 201 | {165,145,165,188}, 202 | {166,63,166,207}, 203 | {167,126,167,205}, 204 | {168,252,168,144}, 205 | {169,229,169,135}, 206 | {170,215,170,151}, 207 | {171,179,171,178}, 208 | {172,123,172,220}, 209 | {173,246,173,252}, 210 | {174,241,174,190}, 211 | {175,255,175,97}, 212 | {176,227,176,242}, 213 | {177,219,177,86}, 214 | {178,171,178,211}, 215 | {179,75,179,171}, 216 | {180,150,180,20}, 217 | {181,49,181,42}, 218 | {182,98,182,93}, 219 | {183,196,183,158}, 220 | {184,149,184,132}, 221 | {185,55,185,60}, 222 | {186,110,186,57}, 223 | {187,220,187,83}, 224 | {188,165,188,71}, 225 | {189,87,189,109}, 226 | {190,174,190,65}, 227 | {191,65,191,162}, 228 | {192,130,192,31}, 229 | {193,25,193,45}, 230 | {194,50,194,67}, 231 | {195,100,195,216}, 232 | {196,200,196,183}, 233 | {197,141,197,123}, 234 | {198,7,198,164}, 235 | {199,14,199,118}, 236 | {200,28,200,196}, 237 | {201,56,201,23}, 238 | {202,112,202,73}, 239 | {203,224,203,236}, 240 | {204,221,204,127}, 241 | {205,167,205,12}, 242 | {206,83,206,111}, 243 | {207,166,207,246}, 244 | {208,81,208,108}, 245 | {209,162,209,161}, 246 | {210,89,210,59}, 247 | {211,178,211,82}, 248 | {212,121,212,41}, 249 | {213,242,213,157}, 250 | {214,249,214,85}, 251 | {215,239,215,170}, 252 | {216,195,216,251}, 253 | {217,155,217,96}, 254 | {218,43,218,134}, 255 | {219,86,219,177}, 256 | {220,172,220,187}, 257 | {221,69,221,204}, 258 | {222,138,222,62}, 259 | {223,9,223,90}, 260 | {224,18,224,203}, 261 | {225,36,225,89}, 262 | {226,72,226,95}, 263 | {227,144,227,176}, 264 | {228,61,228,156}, 265 | {229,122,229,169}, 266 | {230,244,230,160}, 267 | {231,245,231,81}, 268 | {232,247,232,11}, 269 | {233,243,233,245}, 270 | {234,251,234,22}, 271 | {235,235,235,235}, 272 | {236,203,236,122}, 273 | {237,139,237,117}, 274 | {238,11,238,44}, 275 | {239,22,239,215}, 276 | {240,44,240,79}, 277 | {241,88,241,174}, 278 | {242,176,242,213}, 279 | {243,125,243,233}, 280 | {244,250,244,230}, 281 | {245,233,245,231}, 282 | {246,207,246,173}, 283 | {247,131,247,232}, 284 | {248,27,248,116}, 285 | {249,54,249,214}, 286 | {250,108,250,244}, 287 | {251,216,251,234}, 288 | {252,173,252,168}, 289 | {253,71,253,80}, 290 | {254,142,254,88}, 291 | {255,1,255,175} 292 | }; 293 | 294 | //Type infomation bits encode the mask used, ecc level, ect. 295 | unsigned int TypeInfomationBits[15] = {0,1,1,0,1,0,1,0,1,0,1,1,1,1,1}; 296 | //Message in binary to be displayed 297 | unsigned int BinaryMessage[104] = {}; 298 | //Binary ECC data to be displayed 299 | unsigned int BinaryECCWords[104] = {}; 300 | //Array to hold Message in Integer format (used in arithmetic) 301 | unsigned int MessageI[13] = {}; 302 | //Array to hold Message in Alpha Notation (used in arithmetic) 303 | unsigned int MessageA[13] = {}; 304 | //Generator Polynomial data to perform calculations 305 | unsigned int GeneratorA[14] = {0,74,152,176,100,86,100,106,104,130,218,206,140,78}; 306 | //Result from XOR operation (used in arithmetic) 307 | unsigned int xorResult[15] = {}; 308 | //Result from arithmitic 309 | unsigned int Result[15] = {}; 310 | 311 | //ECC words in binary 312 | String eccBinary = ""; 313 | //All the binary data is appended into dataString 314 | String dataString = ""; 315 | //Then transfered to byteMessage 316 | String byteMessage = ""; 317 | //Message that we hope to convert 318 | String messageToEncode = ""; 319 | //dataString length 320 | int length = 0; 321 | //byte counter 322 | int byteCounter = 0; 323 | //Coefficients of binary data 324 | int coefficients[13]; 325 | //First Term Exponent 326 | int exponent = 25; 327 | //Used to remove zeros from XOR results 328 | boolean zeroFound = false; 329 | //x & y position for binary data used for masking 330 | int x = 1; 331 | int y = 1; 332 | //Start position for binary data 333 | int xPos = 0; 334 | int yPos = 0; 335 | //Keeps track of data displayed 336 | int counter = 0; 337 | 338 | #define TS_MINX 140 339 | #define TS_MAXX 900 340 | #define TS_MINY 120 341 | #define TS_MAXY 940 342 | 343 | TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //init TouchScreen port pins 344 | 345 | void setup() 346 | { 347 | //Start Serial at 9600 baud 348 | Serial.begin(115200); 349 | //Init LCD 350 | Tft.init(); 351 | //Paint background white 352 | Tft.fillRectangle(0, 0, 240,320,WHITE); 353 | //Generate data used for QR 354 | calculateQRCode(); 355 | //Draw base QR code 356 | drawTemplate(); 357 | //Fill in data bits 358 | informationBits(); 359 | 360 | } 361 | 362 | void loop() 363 | { 364 | 365 | } 366 | 367 | -------------------------------------------------------------------------------- /QR_Code/generateBits.ino: -------------------------------------------------------------------------------- 1 | void calculateQRCode() 2 | { 3 | //Initialize varaibles 4 | eccBinary = ""; 5 | dataString = ""; 6 | byteMessage = ""; 7 | messageToEncode = "HACKADAY"; 8 | length = 0; 9 | byteCounter = 0; 10 | exponent = 25; 11 | zeroFound = false; 12 | 13 | //Set Datamode bits to 1 for alphanumic 14 | setDataModeBits(1); 15 | if(debug){ 16 | Serial.println("------------------------ Step 1 ------------------------ "); 17 | Serial.println("Set data mode to : Alphanumeric"); 18 | Serial.println("Sending type bits (4) to output ..."); 19 | Serial.print("Sent 4 bits of output: "); 20 | Serial.println(dataString); 21 | Serial.println("------------------------ Step 2 ------------------------ "); 22 | Serial.println("Encode length of data."); 23 | Serial.println("Calculating bit size for data length .."); 24 | Serial.println("QR Type: Alphanumeric, QR Version 1, Bit Size: 9 bits."); 25 | } 26 | //Encode length of data 27 | encodeDataLength(); 28 | if(debug){ 29 | Serial.print("Data stored in output : "); 30 | Serial.println(dataString); 31 | Serial.println("------------------------ Step 3 ------------------------ "); 32 | Serial.println("Encode Data to Binary"); 33 | Serial.println("Writing characters .."); 34 | } 35 | //Endcode Data in binary 36 | encodeData(); 37 | if(debug){ 38 | Serial.println("Input successfully encoded to binary."); 39 | Serial.println("------------------------ Step 4 ------------------------ "); 40 | Serial.println("Finishing binary string..."); 41 | } 42 | //Terminate the bits 43 | terminateBits(); 44 | if(debug){ 45 | Serial.println("------------------------ Step 5 ------------------------ "); 46 | Serial.println("Dividing bits into bytes (8 bits per byte)..."); 47 | } 48 | //Delimit the string into 8-bit words, then pad with 0's if necessary 49 | delimitBitstoBytes(); 50 | if(debug){ 51 | Serial.println("------------------------ Step 6 ------------------------ "); 52 | Serial.println("Inserting characters to fill missing data string..."); 53 | } 54 | //Add words at end of string if less than 104 bit's or 13 8-bit words 55 | addWord(); 56 | if(debug){ 57 | Serial.println("------------------------ Step 7 ------------------------ "); 58 | Serial.println("Calculating error code correction..."); 59 | } 60 | //Convert each 8-bit word from binary to decmil 61 | decimal(); 62 | //Convert & store decimal Message to Alpha Notation 63 | messageToAlpha(); 64 | //Generate ECC words 65 | ecc(); 66 | //Convert & Store ECC Words in binary to eccBinary 67 | for(int h = 0; h < 13; h++){ 68 | //Convert to binary and append to eccBinary 69 | for(int j = 8-1; j > -1; j--){ 70 | eccBinary += bitRead(Result[h], j); 71 | } 72 | } 73 | //Take the binary message and store in BinaryMessage array 74 | for(int i = 0; i < 104; i++){ 75 | BinaryMessage[i] = byteMessage.charAt(i) - '0'; 76 | } 77 | //Take the ecc binary data and store in BinaryECCWords array 78 | for(int i = 0; i < 104; i++){ 79 | BinaryECCWords[i] = eccBinary.charAt(i) - '0'; 80 | } 81 | 82 | if(debug){ 83 | Serial.println("------------------------ ECC Words ------------------------ "); 84 | for(int i = 0; i < 13; i++){ 85 | Serial.print(Result[i]); 86 | Serial.print(" "); 87 | } 88 | Serial.println(); 89 | 90 | Serial.println("------------------------ Binary Data ------------------------ "); 91 | Serial.println("Binary Message : "); 92 | Serial.println(byteMessage); 93 | Serial.println("Binary ECC Words : "); 94 | Serial.println(eccBinary); 95 | } 96 | 97 | } 98 | 99 | void setDataModeBits(int datamode) 100 | { 101 | switch(datamode) 102 | { 103 | //numeric 104 | case 0: 105 | dataString += "0001"; 106 | break; 107 | case 1: 108 | //alphanumeric 109 | dataString += "0010"; 110 | break; 111 | } 112 | } 113 | 114 | void encodeDataLength() 115 | { 116 | length = messageToEncode.length(); 117 | 118 | //Insert Padding for 9 bit 119 | dataString += "0000"; 120 | 121 | for(int i = 4; i > -1; i--){ 122 | dataString += bitRead(length, i); 123 | } 124 | } 125 | 126 | void encodeData() 127 | { 128 | int numArray[20]; 129 | int totalArray[20]; 130 | char charBuffer[20] = {}; 131 | int numBits = 0; 132 | 133 | /*Read the String messageToEncode 2 characters at a time 134 | Convert characters to ASCII & then perform some arthmitic 135 | Store the result in totalArray which will then get converted 136 | to binary and appended to dataString. 137 | */ 138 | 139 | //If the length of the message is even 140 | if (length == 2 || length == 4 || length == 6 || length == 8 || length == 10 || length == 12 || length == 14 || length == 16){ 141 | for (int i = 0; i < length; i+=2){ 142 | //First Character 143 | charBuffer[i] = messageToEncode.charAt(i); 144 | //Second Character 145 | charBuffer[i+1] = messageToEncode.charAt(i+1); 146 | //If the character is a number convert it to an int 147 | if(isDigit(charBuffer[i])) { 148 | numArray[i] = charBuffer[i] - '0'; 149 | } 150 | //If the character is punctuation I assume it found : & force the value 44. 151 | //ASCII values in arduino seems to differ slightly from QR code ASCII 152 | if(isPunct(charBuffer[i])) { 153 | numArray[i] = 44; 154 | } 155 | //If the character is a space force the value 36 156 | if(isSpace(charBuffer[i])) { 157 | numArray[i] = 36; 158 | } 159 | //If the character is alpha numeric 160 | if(isAlphaNumeric(charBuffer[i])){ 161 | if(charBuffer[i] == 'A') 162 | numArray[i] = 10; 163 | if(charBuffer[i] == 'B') 164 | numArray[i] = 11; 165 | if(charBuffer[i] == 'C') 166 | numArray[i] = 12; 167 | if(charBuffer[i] == 'D') 168 | numArray[i] = 13; 169 | if(charBuffer[i] == 'E') 170 | numArray[i] = 14; 171 | if(charBuffer[i] == 'F') 172 | numArray[i] = 15; 173 | if(charBuffer[i] == 'G') 174 | numArray[i] = 16; 175 | if(charBuffer[i] == 'H') 176 | numArray[i] = 17; 177 | if(charBuffer[i] == 'I') 178 | numArray[i] = 18; 179 | if(charBuffer[i] == 'J') 180 | numArray[i] = 19; 181 | if(charBuffer[i] == 'K') 182 | numArray[i] = 20; 183 | if(charBuffer[i] == 'L') 184 | numArray[i] = 21; 185 | if(charBuffer[i] == 'M') 186 | numArray[i] = 22; 187 | if(charBuffer[i] == 'N') 188 | numArray[i] = 23; 189 | if(charBuffer[i] == 'O') 190 | numArray[i] = 24; 191 | if(charBuffer[i] == 'P') 192 | numArray[i] = 25; 193 | if(charBuffer[i] == 'Q') 194 | numArray[i] = 26; 195 | if(charBuffer[i] == 'R') 196 | numArray[i] = 27; 197 | if(charBuffer[i] == 'S') 198 | numArray[i] = 28; 199 | if(charBuffer[i] == 'T') 200 | numArray[i] = 29; 201 | if(charBuffer[i] == 'U') 202 | numArray[i] = 30; 203 | if(charBuffer[i] == 'V') 204 | numArray[i] = 31; 205 | if(charBuffer[i] == 'W') 206 | numArray[i] = 32; 207 | if(charBuffer[i] == 'X') 208 | numArray[i] = 33; 209 | if(charBuffer[i] == 'Y') 210 | numArray[i] = 34; 211 | if(charBuffer[i] == 'Z') 212 | numArray[i] = 35; 213 | } 214 | //If the character is a number convert it to an int 215 | if(isDigit(charBuffer[i+1])) { 216 | numArray[i+1] = charBuffer[i+1] - '0'; 217 | } 218 | //If the character is punctuation I assume it found : & force the value 44. 219 | //ASCII values in arduino seems to differ slightly from QR code ASCII 220 | if(isPunct(charBuffer[i+1])) { 221 | numArray[i+1] = 44; 222 | } 223 | //If the character is a space force the value 36 224 | if(isSpace(charBuffer[i+1])) { 225 | numArray[i+1] = 36; 226 | } 227 | //If the character is alpha numeric 228 | if(isAlphaNumeric(charBuffer[i+1])){ 229 | if(charBuffer[i+1] == 'A') 230 | numArray[i+1] = 10; 231 | if(charBuffer[i+1] == 'B') 232 | numArray[i+1] = 11; 233 | if(charBuffer[i+1] == 'C') 234 | numArray[i+1] = 12; 235 | if(charBuffer[i+1] == 'D') 236 | numArray[i+1] = 13; 237 | if(charBuffer[i+1] == 'E') 238 | numArray[i+1] = 14; 239 | if(charBuffer[i+1] == 'F') 240 | numArray[i+1] = 15; 241 | if(charBuffer[i+1] == 'G') 242 | numArray[i+1] = 16; 243 | if(charBuffer[i+1] == 'H') 244 | numArray[i+1] = 17; 245 | if(charBuffer[i+1] == 'I') 246 | numArray[i+1] = 18; 247 | if(charBuffer[i+1] == 'J') 248 | numArray[i+1] = 19; 249 | if(charBuffer[i+1] == 'K') 250 | numArray[i+1] = 20; 251 | if(charBuffer[i+1] == 'L') 252 | numArray[i+1] = 21; 253 | if(charBuffer[i+1] == 'M') 254 | numArray[i+1] = 22; 255 | if(charBuffer[i+1] == 'N') 256 | numArray[i+1] = 23; 257 | if(charBuffer[i+1] == 'O') 258 | numArray[i+1] = 24; 259 | if(charBuffer[i+1] == 'P') 260 | numArray[i+1] = 25; 261 | if(charBuffer[i+1] == 'Q') 262 | numArray[i+1] = 26; 263 | if(charBuffer[i+1] == 'R') 264 | numArray[i+1] = 27; 265 | if(charBuffer[i+1] == 'S') 266 | numArray[i+1] = 28; 267 | if(charBuffer[i+1] == 'T') 268 | numArray[i+1] = 29; 269 | if(charBuffer[i+1] == 'U') 270 | numArray[i+1] = 30; 271 | if(charBuffer[i+1] == 'V') 272 | numArray[i+1] = 31; 273 | if(charBuffer[i+1] == 'W') 274 | numArray[i+1] = 32; 275 | if(charBuffer[i+1] == 'X') 276 | numArray[i+1] = 33; 277 | if(charBuffer[i+1] == 'Y') 278 | numArray[i+1] = 34; 279 | if(charBuffer[i+1] == 'Z') 280 | numArray[i+1] = 35; 281 | } 282 | //Perform the necessay arthmitic & store the result in totalArray 283 | //Later each value in the array will be converted to its binary equevillant 284 | totalArray[i] = (45 * numArray[i]) + numArray[i+1]; 285 | 286 | if (debug) { 287 | //Print the output in a readable manor 288 | Serial.print("- Characters: "); 289 | Serial.print(charBuffer[i]); 290 | Serial.print(", "); 291 | Serial.print(charBuffer[i+1]); 292 | Serial.print(": (45 * "); 293 | Serial.print(numArray[i]); 294 | Serial.print(") + "); 295 | Serial.print(numArray[i+1]); 296 | Serial.print(" = "); 297 | Serial.print(totalArray[i]); 298 | Serial.println(); 299 | } 300 | } 301 | 302 | //take the contents of totalArray & convert to binary append to dataString 303 | for(int h = 0; h < length; h+=2){ 304 | //You need 11 bit binay results so there is no reason to 305 | //determine binary output size 306 | for(int j = 11-1; j > -1; j--){ 307 | dataString += bitRead(totalArray[h], j); 308 | } 309 | } 310 | 311 | } 312 | 313 | //If the message length is odd 314 | if (length == 1 || length == 3 || length == 5 || length == 7 || length == 9 || length == 11 || length == 13 || length == 15){ 315 | //Remove the last character that way it can 316 | for (int i = 0; i < length-1; i+=2){ 317 | //First Character 318 | charBuffer[i] = messageToEncode.charAt(i); 319 | //Second Character 320 | charBuffer[i+1] = messageToEncode.charAt(i+1); 321 | //If the character is a number convert it to an int 322 | if(isDigit(charBuffer[i])) { 323 | numArray[i] = charBuffer[i] - '0'; 324 | } 325 | //If the character is punctuation I assume it found : & force the value 44. 326 | //ASCII values in arduino seems to differ slightly from QR code ASCII 327 | if(isPunct(charBuffer[i])) { 328 | numArray[i] = 44; 329 | } 330 | //If the character is a space force the value 36 331 | if(isSpace(charBuffer[i])) { 332 | numArray[i] = 36; 333 | } 334 | //If the character is alpha numeric 335 | if(isAlphaNumeric(charBuffer[i])){ 336 | if(charBuffer[i] == 'A') 337 | numArray[i] = 10; 338 | if(charBuffer[i] == 'B') 339 | numArray[i] = 11; 340 | if(charBuffer[i] == 'C') 341 | numArray[i] = 12; 342 | if(charBuffer[i] == 'D') 343 | numArray[i] = 13; 344 | if(charBuffer[i] == 'E') 345 | numArray[i] = 14; 346 | if(charBuffer[i] == 'F') 347 | numArray[i] = 15; 348 | if(charBuffer[i] == 'G') 349 | numArray[i] = 16; 350 | if(charBuffer[i] == 'H') 351 | numArray[i] = 17; 352 | if(charBuffer[i] == 'I') 353 | numArray[i] = 18; 354 | if(charBuffer[i] == 'J') 355 | numArray[i] = 19; 356 | if(charBuffer[i] == 'K') 357 | numArray[i] = 20; 358 | if(charBuffer[i] == 'L') 359 | numArray[i] = 21; 360 | if(charBuffer[i] == 'M') 361 | numArray[i] = 22; 362 | if(charBuffer[i] == 'N') 363 | numArray[i] = 23; 364 | if(charBuffer[i] == 'O') 365 | numArray[i] = 24; 366 | if(charBuffer[i] == 'P') 367 | numArray[i] = 25; 368 | if(charBuffer[i] == 'Q') 369 | numArray[i] = 26; 370 | if(charBuffer[i] == 'R') 371 | numArray[i] = 27; 372 | if(charBuffer[i] == 'S') 373 | numArray[i] = 28; 374 | if(charBuffer[i] == 'T') 375 | numArray[i] = 29; 376 | if(charBuffer[i] == 'U') 377 | numArray[i] = 30; 378 | if(charBuffer[i] == 'V') 379 | numArray[i] = 31; 380 | if(charBuffer[i] == 'W') 381 | numArray[i] = 32; 382 | if(charBuffer[i] == 'X') 383 | numArray[i] = 33; 384 | if(charBuffer[i] == 'Y') 385 | numArray[i] = 34; 386 | if(charBuffer[i] == 'Z') 387 | numArray[i] = 35; 388 | } 389 | //If the character is a number convert it to an int 390 | if(isDigit(charBuffer[i+1])) { 391 | numArray[i+1] = charBuffer[i+1] - '0'; 392 | } 393 | //If the character is punctuation I assume it found : & force the value 44. 394 | //ASCII values in arduino seems to differ slightly from QR code ASCII 395 | if(isPunct(charBuffer[i+1])) { 396 | numArray[i+1] = 44; 397 | } 398 | //If the character is a space force the value 36 399 | if(isSpace(charBuffer[i+1])) { 400 | numArray[i+1] = 36; 401 | } 402 | //If the character is alpha numeric 403 | if(isAlphaNumeric(charBuffer[i+1])){ 404 | if(charBuffer[i+1] == 'A') 405 | numArray[i+1] = 10; 406 | if(charBuffer[i+1] == 'B') 407 | numArray[i+1] = 11; 408 | if(charBuffer[i+1] == 'C') 409 | numArray[i+1] = 12; 410 | if(charBuffer[i+1] == 'D') 411 | numArray[i+1] = 13; 412 | if(charBuffer[i+1] == 'E') 413 | numArray[i+1] = 14; 414 | if(charBuffer[i+1] == 'F') 415 | numArray[i+1] = 15; 416 | if(charBuffer[i+1] == 'G') 417 | numArray[i+1] = 16; 418 | if(charBuffer[i+1] == 'H') 419 | numArray[i+1] = 17; 420 | if(charBuffer[i+1] == 'I') 421 | numArray[i+1] = 18; 422 | if(charBuffer[i+1] == 'J') 423 | numArray[i+1] = 19; 424 | if(charBuffer[i+1] == 'K') 425 | numArray[i+1] = 20; 426 | if(charBuffer[i+1] == 'L') 427 | numArray[i+1] = 21; 428 | if(charBuffer[i+1] == 'M') 429 | numArray[i+1] = 22; 430 | if(charBuffer[i+1] == 'N') 431 | numArray[i+1] = 23; 432 | if(charBuffer[i+1] == 'O') 433 | numArray[i+1] = 24; 434 | if(charBuffer[i+1] == 'P') 435 | numArray[i+1] = 25; 436 | if(charBuffer[i+1] == 'Q') 437 | numArray[i+1] = 26; 438 | if(charBuffer[i+1] == 'R') 439 | numArray[i+1] = 27; 440 | if(charBuffer[i+1] == 'S') 441 | numArray[i+1] = 28; 442 | if(charBuffer[i+1] == 'T') 443 | numArray[i+1] = 29; 444 | if(charBuffer[i+1] == 'U') 445 | numArray[i+1] = 30; 446 | if(charBuffer[i+1] == 'V') 447 | numArray[i+1] = 31; 448 | if(charBuffer[i+1] == 'W') 449 | numArray[i+1] = 32; 450 | if(charBuffer[i+1] == 'X') 451 | numArray[i+1] = 33; 452 | if(charBuffer[i+1] == 'Y') 453 | numArray[i+1] = 34; 454 | if(charBuffer[i+1] == 'Z') 455 | numArray[i+1] = 35; 456 | } 457 | 458 | //Perform the necessay arthmitic & store the result in totalArray 459 | //Later each value in the array will be converted to its binary equevillant 460 | totalArray[i] = (45 * numArray[i]) + numArray[i+1]; 461 | 462 | if (debug) { 463 | //Print the output in a readable manor 464 | Serial.print("- Characters: "); 465 | Serial.print(charBuffer[i]); 466 | Serial.print(", "); 467 | Serial.print(charBuffer[i+1]); 468 | Serial.print(": (45 * "); 469 | Serial.print(numArray[i]); 470 | Serial.print(") + "); 471 | Serial.print(numArray[i+1]); 472 | Serial.print(" = "); 473 | Serial.print(totalArray[i]); 474 | Serial.println(); 475 | } 476 | } 477 | 478 | //take the contents of totalArray & convert to binary append to dataString 479 | for(int h = 0; h < length-1; h+=2){ 480 | //You need 11 bit binay results so there is no reason to 481 | //determine binary output size 482 | for(int j = 11-1; j > -1; j--){ 483 | dataString += bitRead(totalArray[h], j); 484 | } 485 | } 486 | 487 | 488 | //Take the last character & convert it into a 6 bit binary representation then append to dataString 489 | for(int j = 6-1; j > -1; j--){ 490 | dataString += bitRead(totalArray[length], j); 491 | } 492 | Serial.println("Message was odd last character encoded as 6 bit binary."); 493 | } 494 | 495 | 496 | 497 | 498 | } 499 | 500 | void terminateBits() 501 | { 502 | int totalLength = dataString.length(); 503 | if(totalLength+4 < 104){ 504 | if(debug){ 505 | Serial.print("Maxium bits for current version : 104 current bits: "); 506 | Serial.println(totalLength); 507 | } 508 | dataString += "0000"; 509 | if (debug){ 510 | Serial.print("Added 4 bits to binary output. Total : "); 511 | Serial.println(dataString.length()); 512 | } 513 | } 514 | } 515 | 516 | void delimitBitstoBytes() 517 | { 518 | int stringSize = dataString.length(); 519 | //Delimit dataString into 8 bit bytes & store in char array or something similar 520 | //I cant think of a good reason I would have to store it in a binary array 521 | //If final byte < 8 bits pad the ending with zeros 522 | for(int k = 0; k < stringSize; k+=8){ 523 | 524 | int byteSize = dataString.substring(k, k + 8).length(); 525 | if(byteSize == 8){ 526 | byteMessage += dataString.substring(k, k + 8); 527 | 528 | }else if(byteSize < 8){ 529 | int bitDifference = 8 - byteSize; 530 | 531 | byteMessage += dataString.substring(k, k + 8); 532 | 533 | for(int i = 0; i < bitDifference;i++){ 534 | byteMessage += '0'; 535 | } 536 | } 537 | } 538 | 539 | for(int k = 0; k < stringSize; k+=8){ 540 | //Serial.println(byteMessage.substring(k, k + 8)); 541 | byteCounter += 1; 542 | } 543 | 544 | } 545 | 546 | void addWord() 547 | { 548 | if(debug){ 549 | Serial.print("Current output size : "); 550 | Serial.print(byteCounter); 551 | Serial.print(", missing: "); 552 | } 553 | int byteDifference = 13 - byteCounter; 554 | if(debug){ 555 | Serial.print(byteDifference); 556 | Serial.print(" bytes."); 557 | Serial.println(); 558 | Serial.print("Added bytes: "); 559 | } 560 | 561 | for(int i = 0; i < byteDifference; i++){ 562 | if(i == 0 || i == 2 || i == 4 || i == 6 || i == 8 || i == 10 || i == 12){ 563 | if(debug){ 564 | Serial.print(" 236 "); 565 | } 566 | byteMessage += "11101100"; 567 | byteCounter += 1; 568 | } 569 | if(i == 1 || i == 3 || i == 5 || i == 6 || i == 9 || i == 11 || i == 13){ 570 | if(debug){ 571 | Serial.print(" 17 "); 572 | } 573 | byteMessage += "00010001"; 574 | byteCounter += 1; 575 | } 576 | } 577 | 578 | if(debug){ 579 | Serial.println(); 580 | Serial.print("Output size filled to match data size: "); 581 | Serial.print(byteCounter); 582 | Serial.println("/13 bytes"); 583 | } 584 | 585 | 586 | } 587 | 588 | void decimal() 589 | { 590 | 591 | if(debug){ 592 | Serial.println("Dividing message into 8 bit binary segments"); 593 | Serial.println("Creating message polynomial for each block."); 594 | Serial.println("-------------------------------------------------------- "); 595 | Serial.println("Message Polynomial :"); 596 | } 597 | 598 | int stringSize = byteMessage.length(); 599 | 600 | int counter = 0; 601 | 602 | for(int k = 0; k < stringSize; k+=8){ 603 | String binary = byteMessage.substring(k, k + 8); 604 | MessageI[counter] = binaryToDecimal(binary); 605 | counter += 1; 606 | } 607 | 608 | if(debug){ 609 | //Display polynomial 610 | for(int i = 0; i < 13; i++){ 611 | if(i == 6 || i == 12){ 612 | Serial.println(); 613 | } 614 | Serial.print("("); 615 | Serial.print(MessageI[i]); 616 | Serial.print("x ^ "); 617 | Serial.print(exponent-i); 618 | if(i < 12){ 619 | Serial.print(") + "); 620 | }else{ 621 | Serial.print(")"); 622 | } 623 | } 624 | Serial.println(); 625 | } 626 | 627 | } 628 | 629 | int binaryToDecimal(String bits) 630 | { 631 | char charBuffer[8]; 632 | int numArray[8] = {}; 633 | 634 | for(int i = 0; i < 8; i++){ 635 | charBuffer[i] = bits.charAt(i); 636 | numArray[i] = charBuffer[i] - '0'; 637 | } 638 | 639 | return (numArray[0] * pow(2, 7)) + (numArray[1] * pow(2, 6)) + (numArray[2] * pow(2, 5)) + (numArray[3] * pow(2, 4)) + (numArray[4] * pow(2, 3)) +(numArray[5] * pow(2, 2)) + (numArray[6] * pow(2, 1)) + (numArray[7] * pow(2, 0)); 640 | } 641 | 642 | void messageToAlpha() 643 | { 644 | for(int i = 0; i < 13; i++){ 645 | int x = MessageI[i]; 646 | x -= 1; 647 | MessageA[i] = LogTable[x][3]; 648 | } 649 | 650 | } 651 | 652 | void ecc() 653 | { 654 | 655 | //Add exponents 656 | for(int i = 0; i < 14; i++){ 657 | Result[i] = MessageA[0] + GeneratorA[i]; 658 | } 659 | 660 | //Modulo Result 661 | for(int i = 0; i < 14; i++){ 662 | if(Result[i] > 255){ 663 | Result[i] = Result[i] % 255; 664 | } 665 | } 666 | 667 | //Convert result from Alpha Notation to Integer Notation 668 | for(int i = 0; i < 14; i++){ 669 | int x = Result[i]; 670 | x -= 1; 671 | Result[i] = LogTable[x][1]; 672 | } 673 | 674 | //XOR Polynomial 675 | for(int i = 0; i < 13; i++){ 676 | int x = MessageI[i]; 677 | int y = Result[i]; 678 | Result[i] = x ^ y; 679 | } 680 | 681 | //Loop until last exponent in polynomial is zero 682 | while(exponent > 13){ 683 | //Remove zeros & decrement exponent 684 | for(int i = 0; i < 14; i++){ 685 | if(Result[i] == 0){ 686 | zeroFound = true; 687 | exponent -= 1; 688 | } 689 | 690 | if(zeroFound == true){ 691 | Result[i] = Result[i+1]; 692 | xorResult[i] = Result[i]; 693 | } 694 | } 695 | 696 | 697 | //Convert result from Integer Notation to Alpha Notation 698 | for(int i = 0; i < 13; i++){ 699 | int x = Result[i]; 700 | x -= 1; 701 | Result[i] = LogTable[x][3]; 702 | } 703 | 704 | //Add Polynomial exponents 705 | for(int i = 0; i < 14; i++){ 706 | Result[i] = Result[0] + GeneratorA[i]; 707 | } 708 | 709 | //Modulo Result 710 | for(int i = 0; i < 14; i++){ 711 | if(Result[i] > 255){ 712 | Result[i] = Result[i] % 255; 713 | } 714 | } 715 | 716 | //Modulo xorResult 717 | for(int i = 0; i < 14; i++){ 718 | if(xorResult[i] > 255){ 719 | xorResult[i] = xorResult[i] % 255; 720 | } 721 | } 722 | 723 | //Convert result from Alpha Notation to Integer Notation 724 | for(int i = 0; i < 14; i++){ 725 | int x = Result[i]; 726 | x -= 1; 727 | Result[i] = LogTable[x][1]; 728 | } 729 | 730 | 731 | //XOR Polynomial 732 | for(int i = 0; i < 14; i++){ 733 | int x = xorResult[i]; 734 | int y = Result[i]; 735 | Result[i] = x ^ y; 736 | } 737 | } 738 | 739 | //Remove zeroes without decrementing exponent 740 | for(int i = 0; i < 13; i++){ 741 | if(Result[i] == 0){ 742 | zeroFound = true; 743 | } 744 | 745 | if(zeroFound == true){ 746 | Result[i] = Result[i+1]; 747 | xorResult[i] = Result[i]; 748 | } 749 | } 750 | 751 | } 752 | 753 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | QR-Code-Generator 2 | ================= 3 | 4 | Arduino Mega 2560 + SeedStudio TFT 1.0 QR Code Generator 5 | 6 | This program will generate an alpha-numeric QR code and display it on an LCD. 7 | 8 | QR Code Details: 9 | 10 | Version 1 QR code with level Q error correction 11 | 12 | 13 | 14 | I learned how to create QR Codes using this tutorial; I converted it into an arduino sketch. 15 | 16 | http://www.thonky.com/qr-code-tutorial/ 17 | -------------------------------------------------------------------------------- /TFT Libraries/TouchScreen/README.txt: -------------------------------------------------------------------------------- 1 | This is the 4-wire resistive touch screen firmware for Arduino. Works with all Arduinos and the Mega 2 | 3 | 4 | To install, click DOWNLOAD SOURCE in the top right corner, and rename the uncompressed folder "TouchScreen". See our tutorial at http://www.ladyada.net/library/arduino/libraries.html on Arduino Library installation -------------------------------------------------------------------------------- /TFT Libraries/TouchScreen/TouchScreen.cpp: -------------------------------------------------------------------------------- 1 | // Touch screen library with X Y and Z (pressure) readings as well 2 | // as oversampling to avoid 'bouncing' 3 | // (c) ladyada / adafruit 4 | // Code under MIT License 5 | 6 | #include "pins_arduino.h" 7 | #include "wiring_private.h" 8 | #include 9 | #include "TouchScreen.h" 10 | 11 | // increase or decrease the touchscreen oversampling. This is a little different than you make think: 12 | // 1 is no oversampling, whatever data we get is immediately returned 13 | // 2 is double-sampling and we only return valid data if both points are the same 14 | // 3+ uses insert sort to get the median value. 15 | // We found 2 is precise yet not too slow so we suggest sticking with it! 16 | 17 | #define NUMSAMPLES 2 18 | 19 | Point::Point(void) { 20 | x = y = 0; 21 | } 22 | 23 | Point::Point(int16_t x0, int16_t y0, int16_t z0) { 24 | x = x0; 25 | y = y0; 26 | z = z0; 27 | } 28 | 29 | bool Point::operator==(Point p1) { 30 | return ((p1.x == x) && (p1.y == y) && (p1.z == z)); 31 | } 32 | 33 | bool Point::operator!=(Point p1) { 34 | return ((p1.x != x) || (p1.y != y) || (p1.z != z)); 35 | } 36 | 37 | #if (NUMSAMPLES > 2) 38 | static void insert_sort(int array[], uint8_t size) { 39 | uint8_t j; 40 | int save; 41 | 42 | for (int i = 1; i < size; i++) { 43 | save = array[i]; 44 | for (j = i; j >= 1 && save < array[j - 1]; j--) 45 | array[j] = array[j - 1]; 46 | array[j] = save; 47 | } 48 | } 49 | #endif 50 | 51 | Point TouchScreen::getPoint(void) { 52 | int x, y, z; 53 | int samples[NUMSAMPLES]; 54 | uint8_t i, valid; 55 | 56 | 57 | uint8_t xp_port = digitalPinToPort(_xp); 58 | uint8_t yp_port = digitalPinToPort(_yp); 59 | uint8_t xm_port = digitalPinToPort(_xm); 60 | uint8_t ym_port = digitalPinToPort(_ym); 61 | 62 | uint8_t xp_pin = digitalPinToBitMask(_xp); 63 | uint8_t yp_pin = digitalPinToBitMask(_yp); 64 | uint8_t xm_pin = digitalPinToBitMask(_xm); 65 | uint8_t ym_pin = digitalPinToBitMask(_ym); 66 | 67 | 68 | valid = 1; 69 | 70 | pinMode(_yp, INPUT); 71 | pinMode(_ym, INPUT); 72 | 73 | *portOutputRegister(yp_port) &= ~yp_pin; 74 | *portOutputRegister(ym_port) &= ~ym_pin; 75 | //digitalWrite(_yp, LOW); 76 | //digitalWrite(_ym, LOW); 77 | 78 | pinMode(_xp, OUTPUT); 79 | pinMode(_xm, OUTPUT); 80 | //digitalWrite(_xp, HIGH); 81 | //digitalWrite(_xm, LOW); 82 | *portOutputRegister(xp_port) |= xp_pin; 83 | *portOutputRegister(xm_port) &= ~xm_pin; 84 | 85 | for (i=0; i 2 89 | insert_sort(samples, NUMSAMPLES); 90 | #endif 91 | #if NUMSAMPLES == 2 92 | if (samples[0] != samples[1]) { valid = 0; } 93 | #endif 94 | x = (1023-samples[NUMSAMPLES/2]); 95 | 96 | pinMode(_xp, INPUT); 97 | pinMode(_xm, INPUT); 98 | *portOutputRegister(xp_port) &= ~xp_pin; 99 | //digitalWrite(_xp, LOW); 100 | 101 | pinMode(_yp, OUTPUT); 102 | *portOutputRegister(yp_port) |= yp_pin; 103 | //digitalWrite(_yp, HIGH); 104 | pinMode(_ym, OUTPUT); 105 | 106 | for (i=0; i 2 111 | insert_sort(samples, NUMSAMPLES); 112 | #endif 113 | #if NUMSAMPLES == 2 114 | if (samples[0] != samples[1]) { valid = 0; } 115 | #endif 116 | 117 | y = (1023-samples[NUMSAMPLES/2]); 118 | 119 | // Set X+ to ground 120 | pinMode(_xp, OUTPUT); 121 | *portOutputRegister(xp_port) &= ~xp_pin; 122 | //digitalWrite(_xp, LOW); 123 | 124 | // Set Y- to VCC 125 | *portOutputRegister(ym_port) |= ym_pin; 126 | //digitalWrite(_ym, HIGH); 127 | 128 | // Hi-Z X- and Y+ 129 | *portOutputRegister(yp_port) &= ~yp_pin; 130 | //digitalWrite(_yp, LOW); 131 | pinMode(_yp, INPUT); 132 | 133 | int z1 = analogRead(_xm); 134 | int z2 = analogRead(_yp); 135 | 136 | if (_rxplate != 0) { 137 | // now read the x 138 | float rtouch; 139 | rtouch = z2; 140 | rtouch /= z1; 141 | rtouch -= 1; 142 | rtouch *= x; 143 | rtouch *= _rxplate; 144 | rtouch /= 1024; 145 | 146 | z = rtouch; 147 | } else { 148 | z = (1023-(z2-z1)); 149 | } 150 | 151 | if (! valid) { 152 | z = 0; 153 | } 154 | 155 | return Point(x, y, z); 156 | } 157 | 158 | TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym) { 159 | _yp = yp; 160 | _xm = xm; 161 | _ym = ym; 162 | _xp = xp; 163 | _rxplate = 0; 164 | pressureThreshhold = 10; 165 | } 166 | 167 | 168 | TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, 169 | uint16_t rxplate) { 170 | _yp = yp; 171 | _xm = xm; 172 | _ym = ym; 173 | _xp = xp; 174 | _rxplate = rxplate; 175 | 176 | pressureThreshhold = 10; 177 | } 178 | 179 | int TouchScreen::readTouchX(void) { 180 | pinMode(_yp, INPUT); 181 | pinMode(_ym, INPUT); 182 | digitalWrite(_yp, LOW); 183 | digitalWrite(_ym, LOW); 184 | 185 | pinMode(_xp, OUTPUT); 186 | digitalWrite(_xp, HIGH); 187 | pinMode(_xm, OUTPUT); 188 | digitalWrite(_xm, LOW); 189 | 190 | return (1023-analogRead(_yp)); 191 | } 192 | 193 | 194 | int TouchScreen::readTouchY(void) { 195 | pinMode(_xp, INPUT); 196 | pinMode(_xm, INPUT); 197 | digitalWrite(_xp, LOW); 198 | digitalWrite(_xm, LOW); 199 | 200 | pinMode(_yp, OUTPUT); 201 | digitalWrite(_yp, HIGH); 202 | pinMode(_ym, OUTPUT); 203 | digitalWrite(_ym, LOW); 204 | 205 | return (1023-analogRead(_xm)); 206 | } 207 | 208 | 209 | uint16_t TouchScreen::pressure(void) { 210 | // Set X+ to ground 211 | pinMode(_xp, OUTPUT); 212 | digitalWrite(_xp, LOW); 213 | 214 | // Set Y- to VCC 215 | pinMode(_ym, OUTPUT); 216 | digitalWrite(_ym, HIGH); 217 | 218 | // Hi-Z X- and Y+ 219 | digitalWrite(_xm, LOW); 220 | pinMode(_xm, INPUT); 221 | digitalWrite(_yp, LOW); 222 | pinMode(_yp, INPUT); 223 | 224 | int z1 = analogRead(_xm); 225 | int z2 = analogRead(_yp); 226 | 227 | if (_rxplate != 0) { 228 | // now read the x 229 | float rtouch; 230 | rtouch = z2; 231 | rtouch /= z1; 232 | rtouch -= 1; 233 | rtouch *= readTouchX(); 234 | rtouch *= _rxplate; 235 | rtouch /= 1024; 236 | 237 | return rtouch; 238 | } else { 239 | return (1023-(z2-z1)); 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /TFT Libraries/TouchScreen/TouchScreen.h: -------------------------------------------------------------------------------- 1 | // Touch screen library with X Y and Z (pressure) readings as well 2 | // as oversampling to avoid 'bouncing' 3 | // (c) ladyada / adafruit 4 | // Code under MIT License 5 | 6 | class Point { 7 | public: 8 | Point(void); 9 | Point(int16_t x, int16_t y, int16_t z); 10 | 11 | bool operator==(Point); 12 | bool operator!=(Point); 13 | 14 | int16_t x, y, z; 15 | }; 16 | 17 | class TouchScreen { 18 | public: 19 | TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym); 20 | TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx); 21 | 22 | bool isTouching(void); 23 | uint16_t pressure(void); 24 | int readTouchY(); 25 | int readTouchX(); 26 | Point getPoint(); 27 | int16_t pressureThreshhold; 28 | 29 | private: 30 | uint8_t _yp, _ym, _xm, _xp; 31 | uint16_t _rxplate; 32 | }; 33 | --------------------------------------------------------------------------------