└── Paint.ino /Paint.ino: -------------------------------------------------------------------------------- 1 | #include 2 | TFT_eSPI tft = TFT_eSPI(); 3 | TFT_eSprite img = TFT_eSprite(&tft); 4 | #define gray 0xD69A 5 | #define dgray 0xA514 6 | #define ddgray 0x2124 7 | 8 | int fase=0; 9 | int debounce=0; 10 | int debounce2=0; 11 | int debounce3=0; 12 | int debounce4=0; 13 | int x,y; 14 | int nShapes=0; 15 | int chosenShape=0; 16 | int tx1,ty1,tx2,ty2; 17 | 18 | const int pwmFreq = 5000; 19 | const int pwmResolution = 8; 20 | const int pwmLedChannelTFT = 5; 21 | 22 | 23 | int colorsY[10]={120,120,138,138,156,156,174,174,192,192}; 24 | int colorsX[10]={206,224,206,224,206,224,206,224,206,224}; 25 | 26 | int shapesX[5]={206,224,206,224,206}; 27 | int shapesY[5]={40,40,58,58,76}; 28 | 29 | unsigned short shapes[250][8]; 30 | const unsigned short colors[10]={TFT_RED,0x1D5E,TFT_GREEN,TFT_ORANGE,TFT_PURPLE,dgray,TFT_YELLOW, 0xBA22,TFT_BLACK,TFT_WHITE}; 31 | int c=0; 32 | 33 | void setup() { 34 | pinMode(22,INPUT_PULLUP); 35 | pinMode(12,INPUT_PULLUP); 36 | pinMode(1,INPUT_PULLUP); 37 | pinMode(23,INPUT_PULLUP); 38 | 39 | pinMode(18,OUTPUT); 40 | digitalWrite(18,1); 41 | 42 | tft.init(); 43 | tft.fillScreen(gray); 44 | tft.setTextColor(TFT_WHITE,0xA000); 45 | tft.drawString(" X ",224,0); 46 | tft.setTextColor(TFT_BLACK,gray); 47 | 48 | tft.drawRect(1,18,202,222,dgray); 49 | tft.drawString("| FILE | EDIT | ",4,2,2); 50 | tft.drawString("COL",206,100,2); 51 | tft.drawString("SHA",206,20,2); 52 | img.createSprite(200, 220); 53 | img.fillSprite(TFT_WHITE); 54 | 55 | shapes[0][0]=0; //shape 56 | shapes[0][1]=20; //x1 coordinae 57 | shapes[0][2]=20; //x1 coordinae 58 | shapes[0][3]=100; //x1 coordinae 59 | shapes[0][4]=180; //x1 coordinae 60 | shapes[0][5]=TFT_GREEN; //x1 coordinae 61 | tft.setTextColor(ddgray,gray); 62 | tft.drawString(String(fase),214,212,4); 63 | //tft.fillRect(206,210,32,28,colors[c]); 64 | 65 | int counter=0; 66 | 67 | for(int j=0;j<10;j++) 68 | tft.fillRect(colorsX[j],colorsY[j],14,14,colors[j]); 69 | tft.drawRect(colorsX[c]-1,colorsY[c]-1,16,16,TFT_BLACK); 70 | tft.drawRect(colorsX[c]-2,colorsY[c]-2,18,18,TFT_BLACK); 71 | 72 | for(int m=0;m<5;m++) 73 | tft.fillRect(shapesX[m],shapesY[m],14,14,TFT_WHITE); 74 | tft.drawRect(shapesX[chosenShape]-1,shapesY[chosenShape]-1,16,16,TFT_BLACK); 75 | tft.drawRect(shapesX[chosenShape]-2,shapesY[chosenShape]-2,18,18,TFT_BLACK); 76 | 77 | tft.drawLine(shapesX[0]+2,shapesY[0]+2,shapesX[0]+12,shapesY[0]+12,TFT_BLACK); 78 | tft.fillRect(shapesX[1]+3,shapesY[1]+3,8,8,TFT_PURPLE); 79 | tft.fillCircle(shapesX[2]+7,shapesY[2]+7,5,TFT_RED); 80 | tft.fillTriangle(shapesX[3]+1,shapesY[3]+12,shapesX[3]+13,shapesY[3]+12,shapesX[3]+7,shapesY[3]+1,TFT_BLUE); 81 | 82 | } 83 | //0 is line, 1 is rect, 2 is circle, 3 is triangle 84 | 85 | void loop() { 86 | x=map(analogRead(25),0,4095,0,200); 87 | y=map(analogRead(26),0,4095,0,220); 88 | // tft.drawString(" "+String(x)+" ",6,0,2); 89 | // tft.drawString(" "+String(y)+" ",26,0,2); 90 | draw(x,y); 91 | 92 | } 93 | 94 | 95 | 96 | void draw(int x,int y) 97 | { 98 | img.fillSprite(TFT_WHITE); 99 | 100 | 101 | 102 | //draw Old Objects 103 | for(int i=0;i0){ 122 | nShapes--; 123 | tft.drawString("SHAPES: "+String(nShapes)+" ",130,2,2); 124 | fase=0;} 125 | delay(100); 126 | } 127 | }else debounce4=0; 128 | 129 | if(digitalRead(1)==0) 130 | { 131 | if(debounce3==0) 132 | { 133 | debounce3=1; 134 | tft.drawRect(shapesX[chosenShape]-1,shapesY[chosenShape]-1,16,16,gray); 135 | tft.drawRect(shapesX[chosenShape]-2,shapesY[chosenShape]-2,18,18,gray); 136 | chosenShape++; 137 | if(chosenShape>3) 138 | chosenShape=0; 139 | tft.drawRect(shapesX[chosenShape]-1,shapesY[chosenShape]-1,16,16,TFT_BLACK); 140 | tft.drawRect(shapesX[chosenShape]-2,shapesY[chosenShape]-2,18,18,TFT_BLACK); 141 | delay(100); 142 | } 143 | }else debounce3=0; 144 | 145 | if(digitalRead(23)==0) 146 | { 147 | if(debounce2==0) 148 | { 149 | debounce2=1; 150 | 151 | 152 | tft.drawRect(colorsX[c]-1,colorsY[c]-1,16,16,gray); 153 | tft.drawRect(colorsX[c]-2,colorsY[c]-2,18,18,gray); 154 | c++; 155 | if(c>9) 156 | c=0; 157 | tft.drawRect(colorsX[c]-1,colorsY[c]-1,16,16,TFT_BLACK); 158 | tft.drawRect(colorsX[c]-2,colorsY[c]-2,18,18,TFT_BLACK); 159 | 160 | 161 | // tft.fillRect(206,210,32,28,colors[c]); 162 | delay(100); 163 | } 164 | }else debounce2=0; 165 | 166 | if(digitalRead(22)==0) 167 | { 168 | if(debounce==0) 169 | { 170 | if(chosenShape==3) 171 | { 172 | debounce=1; 173 | fase++; 174 | tft.drawString(String(fase),214,212,4); 175 | if(fase==1) 176 | { 177 | tx1=x; 178 | ty1=y; 179 | fase++; 180 | } 181 | if(fase==3) 182 | { 183 | tx2=x; 184 | ty2=y; 185 | fase++; 186 | } 187 | if(fase==5) 188 | { 189 | 190 | shapes[nShapes][0]=chosenShape; 191 | shapes[nShapes][1]=tx1; 192 | shapes[nShapes][2]=ty1; 193 | shapes[nShapes][3]=tx2; 194 | shapes[nShapes][4]=ty2; 195 | shapes[nShapes][6]=x; 196 | shapes[nShapes][7]=y; 197 | shapes[nShapes][5]=colors[c]; 198 | nShapes++; 199 | tft.drawString("SHAPES: "+String(nShapes),130,2,2); 200 | fase=0; 201 | tft.drawString(String(fase),214,212,4); 202 | } 203 | 204 | }else{ 205 | debounce=1; 206 | fase++; 207 | tft.drawString(String(fase),214,212,4); 208 | 209 | if(fase==1) 210 | { 211 | tx1=x; 212 | ty1=y; 213 | fase++; 214 | } 215 | if(fase==3) 216 | { 217 | 218 | shapes[nShapes][0]=chosenShape; 219 | shapes[nShapes][1]=tx1; 220 | shapes[nShapes][2]=ty1; 221 | shapes[nShapes][3]=x; 222 | shapes[nShapes][4]=y; 223 | shapes[nShapes][5]=colors[c]; 224 | fase=0; 225 | nShapes++; 226 | tft.drawString(String(fase),214,212,4); 227 | tft.drawString("SHAPES: "+String(nShapes),130,2,2); 228 | } 229 | }} 230 | delay(100); 231 | }else {debounce=0;} 232 | 233 | 234 | 235 | if(chosenShape==0 && fase==2) 236 | img.drawLine(tx1,ty1,x,y,colors[c]); 237 | if(chosenShape==1 && fase==2) 238 | img.fillRect(tx1,ty1,x-tx1,y-ty1,colors[c]); 239 | if(chosenShape==2 && fase==2) 240 | img.fillCircle(tx1,ty1,y/2,colors[c]); 241 | if(chosenShape==3 && fase==4) 242 | img.fillTriangle(tx1,ty1,tx2,ty2,x,y,colors[c]); 243 | 244 | 245 | img.fillCircle(x,y,2,TFT_RED); 246 | img.pushSprite(2, 19); 247 | } 248 | --------------------------------------------------------------------------------