//board STM32F103C9T6 (64Kb**(64Kb you should beliefe but STM building in 128KB and sellers dont tell)** 72Mhz) || tft: ILI9341 (240x320pixel 2,8" COLOR LCD SPI) || testprogramm uses Adafruit library have fun =^.^= marderchen //pins TFT ::VCC on 3.3V ::LED on 3.3V ::GND on GND :: CS on A0 :: Reset on A1 :: DC/RS on A2 :: SCK on A5 :: MISO on A6 :: MOSI on A7 //pins touch T_clk = PB13 | T_cs = PA8 | T_din = MOSI = PB15 | T_D0 = PB13 | T_IRQ = PB12 #include "SPI.h" #include "Adafruit_GFX_AS.h" #include "Adafruit_ILI9341_STM.h" #include "XPT2046_touch.h" #include #define TFT_CS PA0 #define TFT_DC PA2 #define TFT_RST PA1 #define swap(a, b) { int16_t t = a; a = b; b = t; } #define screeny 9 Adafruit_ILI9341_STM tft = Adafruit_ILI9341_STM(TFT_CS, TFT_DC, TFT_RST); // Use hardware SPI #define CS_PIN PA8 // Chip Select pin #define UPDATES_PER_SECOND 5000 SPIClass mySPI(2); //Create an SPI instance on SPI1 port. XPT2046_touch ts(CS_PIN, mySPI); // Chip Select pin, SPI port its not the chip from touchmodule but working fine uint16_t xy[2]; //led #define LED_PIN PB8 #define BRIGHTNESS 255 #define LED_TYPE WS2812 #define COLOR_ORDER GRB CRGB leds[screeny]; CRGBPalette16 currentPalette; TBlendType currentBlending; #define UPDATES_PER_SECOND 5000 extern CRGBPalette16 myRedWhiteBluePalette; #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define DARKGREEN 0x03E0 #define CYAN 0x07FF #define PURPLE 0x780F #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF long color =0; long colorc =0; int g = 0; int f1 = 0; int ttt[3] ; int ons[4] ; int duty[10] ; int r=0; uint32_t rainbow[129] = {0xff0000,0xff0500,0xff0a00,0xff0f00,0xff1400,0xff1900,0xff1e00,0xff2400,0xff2900,0xff2e00,0xff3300,0xff3800,0xff3d00,0xff4200,0xff4700,0xff4c00,0xff5100,0xff5600,0xff5b00,0xff6100,0xff6600,0xff6b00,0xff7000,0xff7500,0xff7a00,0xff7f00,0xff8400,0xff8900,0xff8e00,0xff9300,0xff9800,0xff9d00,0xffa100,0xffa600,0xffab00,0xffb000,0xffb500,0xffba00,0xffbf00,0xffc400,0xffc900,0xffce00,0xffd300,0xffd800,0xffdd00,0xffe100,0xffe600,0xffeb00,0xfff000,0xfff500,0xfffa00,0xffff00,0xf5ff00,0xebff00,0xe0ff00,0xd6ff00,0xccff00,0xc2ff00,0xb8ff00,0xadff00,0xa3ff00,0x99ff00,0x8fff00,0x85ff00,0x7aff00,0x70ff00,0x66ff00,0x5cff00,0x52ff00,0x47ff00,0x3dff00,0x33ff00,0x29ff00,0x1fff00,0x14ff00,0x0aff00,0x00ff00,0x00ff0a,0x00ff14,0x00ff1d,0x00ff27,0x00ff31,0x00ff3b,0x00ff45,0x00ff4e,0x00ff58,0x00ff62,0x00ff6c,0x00ff76,0x00ff80,0x00ff89,0x00ff93,0x00ff9d,0x00ffa7,0x00ffb1,0x00ffba,0x00ffc4,0x00ffce,0x00ffd8,0x00ffe2,0x00ffeb,0x00fff5,0x00ffff,0x00f5ff,0x00ebff,0x00e0ff,0x00d6ff,0x00ccff,0x00c2ff,0x00b8ff,0x00adff,0x00a3ff,0x0099ff,0x008fff,0x0085ff,0x007aff,0x0070ff,0x0066ff,0x005cff,0x0052ff,0x0047ff,0x003dff,0x0033ff,0x0029ff,0x001fff,0x0014ff,0x000aff,0x0000ff}; int b=0; //------------------- int rainbowcounter =0; long colorcounta1 =0; long colorcounta2 =1000; //ende anizeugs int schneezahl =4096; int schneezahl2 =0; int menge =20; int speedy =0; int achsex =0; int achsey =0; int colorcountv2 =0; void setup() { FastLED.addLeds(leds, screeny).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); currentPalette = RainbowColors_p; currentBlending = BLEND; tft.begin(); ts.begin(); tft.fillScreen(ILI9341_BLACK); tft.setRotation(3); delay( 3000 ); } void loop() { power(); //zeigmal(); WS2812rainbow(); } int tspedy =0; int rhc =45; int rwc =210; int blacky =0; int rgbdlm =0; int x10=0; int rgbc=0; long leinmovcolor =0; int wenig=0; //thanks to adafruit for PROGMAN algoritm int rainbowcolor3 =0; void wuselBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint32_t colorspeed, int8_t chaos, boolean colormove) { int16_t i, j, byteWidth = (w + 7) / 8; uint8_t byte; for(j=0; j= 128) { rainbowcolor3 =1;} if (colormove == true) {colory(rainbow[rainbowcolor3]); tft.drawPixel(x+i+random(-chaos,chaos),y+i+random(-chaos,chaos), tft.color565(r,g,b));} if (colormove == false) {colory(colorspeed); tft.drawPixel(x+i+random(-chaos,chaos),y+i+random(-chaos,chaos), tft.color565(r,g,b));} } } } void wuselfillrect(int16_t eckex, int16_t eckey,int16_t breit, int16_t hoch,uint32_t colorspeed, int8_t chaos, boolean colormove) { for( int ry = eckex; ry < (hoch); ry++) { wuselline(eckex,eckey+ry,eckex+breit,eckey+ry,colorspeed,chaos,colormove); } } void wuselrect(int16_t eckex, int16_t eckey,int16_t breit, int16_t hoch,uint32_t colorspeed, int8_t chaos, boolean colormove) { wuselline(eckex,eckey,eckex+breit,eckey,colorspeed,chaos,colormove); wuselline(eckex+breit,eckey,eckex+breit,eckey+hoch,colorspeed,chaos,colormove); wuselline(eckex+breit,eckey+hoch,eckex,eckey+hoch,colorspeed,chaos,colormove); wuselline(eckex,eckey+hoch,eckex,eckey,colorspeed,chaos,colormove); } int rainbowcolor =0; int rainbowcolor2 =0; int colorslows=0; int colorslows2=0; //Bresenham's algorithm - thx wikpedia (and adafruit) but the marderchenmod void wuselline(int16_t x0, int16_t y0,int16_t x1, int16_t y1,uint32_t colorspeed, int8_t chaos, boolean colormove) { //if colormove =false, colorspeed = color ( 0xFF205B etc.) int16_t steep = abs(y1 - y0) > abs(x1 - x0); if (steep) { swap(x0, y0); swap(x1, y1); } if (x0 > x1) { swap(x0, x1); swap(y0, y1); } int16_t dx, dy; dx = x1 - x0; dy = abs(y1 - y0); int16_t x10=x0; int16_t err = dx / 2; int16_t err2 = dx / 2; int y10 =y0; int16_t ystep; if (y0 < y1) { ystep = 1; } else { ystep = -1; } for (; x0<=x1; x0++) { colorslows2++; if (colorslows2 >50) {rainbowcolor +=colorspeed; colorslows2=0;} if (rainbowcolor >= (128-colorspeed)) { rainbowcolor =1;} if (steep) { if (colormove == true) { colory(rainbow[rainbowcolor2]); tft.drawPixel(y0, x0, tft.color565(r,g,b));} if (colormove == false) { colory(colorspeed); tft.drawPixel(y0, x0,tft.color565(r,g,b));} } else { if (colormove == true) { colory(rainbow[rainbowcolor2]); tft.drawPixel(x0, y0, tft.color565(r,g,b));} if (colormove == false) { colory(colorspeed); tft.drawPixel(x0, y0, tft.color565(r,g,b));} } err -= dy; if (err < 0) { y0 += ystep; err += dx; } } for (; x10<=x1; x10++) { colorslows++; if (colorslows >50) {rainbowcolor2 +=chaos; colorslows=0;} if (rainbowcolor2 >= (128-chaos)) { rainbowcolor2 =1;} if (steep) { if (colormove == true) {colory(rainbow[rainbowcolor2]); tft.drawPixel(x10+random(-chaos,chaos),y10+random(-chaos,chaos), tft.color565(r,g,b)); } if (colormove == false) { colory(colorspeed); tft.drawPixel(x10+random(-chaos,chaos),y10+random(-chaos,chaos), tft.color565(r,g,b)); } } else { if (colormove == true) {colory(rainbow[rainbowcolor2]); tft.drawPixel(x10+random(-chaos,chaos),y10+random(-chaos,chaos), tft.color565(r,g,b));} if (colormove == false) {colory(colorspeed); tft.drawPixel(x10+random(-chaos,chaos),y10+random(-chaos,chaos),tft.color565(r,g,b));} } err2 -= dy; if (err2 < 0) { y10 += ystep; err2 += dx; } } } int colorw =0; int colorIndex =0; void WS2812rainbow() { colorw +=1; if (colorw > 500) {colorw=0;} for( int iy = 0; iy < screeny; iy++) { colorIndex+=3; //leds[iy] = rainbow[round(colorw)]; leds[iy] = ColorFromPalette( currentPalette, colorIndex, 255, currentBlending); } FastLED.show(); FastLED.delay(1000 / 1000); } uint16_t colors [] = {0xF800,0xF81F,0x001F,0x07FF,0x07E0,0xFFE0}; int startx =55; int starty=14; int once =0; int c1 =0; int demotime =0; void power(void) { tft.fillScreen(ILI9341_BLACK); demotime++; if (demotime <=40) {wuselrect(3,3,314,234,1,demotime/10,true);} if (demotime >=40) {wuselrect(3,3,314,234,demotime/10-4,1,true);} if (demotime <=10) { wuselfillrect(20,20,30,200,3,1,true); //wuselrect(220,20,30,200,3,1,true); } if (demotime >=10 && demotime <=12) { for( int iff = 0; iff < 25; iff++) { wuselfillrect(100,20,20,240,2,iff,true); // wuselrect(200,20,20,240,2,iff,true); }} if (demotime >=15 && demotime <=17) { for( int iff = 0; iff < 15; iff++) { wuselfillrect(100,20,iff,240,2,iff,true); //wuselrect(200,20,iff,240,2,iff,true); }} if (demotime >=25 && demotime <=27) { for( int iff = 0; iff < 10; iff++) { wuselfillrect(iff*10,iff*10,40,240,iff,2,true); }} if (demotime >=35 && demotime <=36) { for( int iff = 0; iff < 10; iff++) { wuselrect(100,20,40,240,iff,1,true); // wuselfillrect(200,20,40,240,iff,0,true); }} if (demotime >=40 && demotime <=100) { for( int iff = 0; iff < 10; iff++) { wuselline(random(6,320),random(6,240),320,240,iff*10,1,true); } } if (demotime >=200) { demotime =0; } rainbowcounter+=3; if (rainbowcounter >128) {rainbowcounter=0;} tft.setCursor(6,6); colory(rainbow[rainbowcounter]); tft.setTextColor(tft.color565(r,g,b)); tft.println("RAIBNBOW LCD drawing"); tft.println("by marderchen =^.^"); if(ts.read_XY(xy)){ //if before if only should sett on touching.. but don't work have changet tresolt in library but also none real effect tft.drawRect(ttt[0]-20,ttt[1]-20,40,40,tft.color565(r,g,b)); ttt[0] =320-( xy[1]/11-15); //offset x ttt[1] =240-( xy[0]/15-11); //offset Y if ((ttt[0]-73) >=0 && (ttt[0]-73) <=200) { if (ttt[1] >148 && ttt[1] <= 180) {duty[0] = ttt[0]-73; once=0;} //bereich schieber1 if (ttt[1] >180 && ttt[1] <= 210) {duty[1] = ttt[0]-73; once=0;} //bereich schieber2 if (ttt[1] >210 && ttt[1] <= 240) {duty[2] = ttt[0]-73; once=0;} //bereich schieber3 }}} void colory(uint32_t colorz) { String hexcolor = String(colorz); int number = hexcolor.toInt(); r = number >> 16; g = number >> 8 & 0xFF; b = number & 0xFF; } /* * MEOW! This is maybe a adafruit based aditional thingi.. have createt it caused the lcd colors are not the rainbow spectrumm. so nor can use uint32_t colors like on PC.. and draw the square line fill thingis direct with chaos and rainbow rainbow colors.. * * by marderchen =^.^= MEOW! its free use it or parts if you want its cute to making world more colorfull * its just a help for me to desing the optical interface for me better so there are thinks like touchscreen and WS2812 also in this programm running on same time * iam not professional! writing this mess is just a cute hobby.. so the most working, somthing is not displayed 100% correct, just fast writedown.. * ( questions : mail to meow@marderchen.de or fisit IRC) * ___ * _.-| | / |\__/,| (`\ { | | -- |^ ^ |__ _) ) "-.|___| \ _.( Y ) ` / .--'-`-. _((_ `^--' /__< \ ....-+|______|__.-||__)`-' (((/ (((/ CATS are awesome! */ /* cattz++; colorcount3 +=20; if (cattz == 1) {tft.drawBitmap(102,50, cat,30, 26, colorcount3);} if (cattz == 2) {tft.drawBitmap(102,50+1, cat2,30, 25, colorcount3);} if (cattz == 3) {tft.drawBitmap(102,50+2, cat3,30, 24, colorcount3);} if (cattz == 4) {tft.drawBitmap(102,50+1, cat2,30, 25, colorcount3);} if (cattz == 5) {cattz = 0;} if (colorcount3 >= 65535) {colorcount3=1;} */