Cov txheej txheem:

Arduino TFT Zaj sawv Suab nrov Zaub: 5 Cov Kauj Ruam
Arduino TFT Zaj sawv Suab nrov Zaub: 5 Cov Kauj Ruam

Video: Arduino TFT Zaj sawv Suab nrov Zaub: 5 Cov Kauj Ruam

Video: Arduino TFT Zaj sawv Suab nrov Zaub: 5 Cov Kauj Ruam
Video: SKR Pro V1.1 - TMC2208 UART v3.0 (BigTreeTech) 2024, Kaum ib hlis
Anonim
Image
Image
Teeb Meem Siv Lub Suab nrov
Teeb Meem Siv Lub Suab nrov

Peb tsim txoj haujlwm zaj sawv no siv ntau yam 'suab nrov' cov txheej txheem, uas tsim kev tswj hwm qhov cuam tshuam. Los ntawm kev ntxiv qee qhov xim, cov nyhuv zaj sawv tuaj yeem tsim tawm. Nws siv Arduino Nano thiab 128x128 OLED zaub. Peb tau nthuav tawm qhov cuam tshuam siv lub tsev qiv ntawv TFT. Peb kuj tseem siv qee yam khoom siv sib xws xws li lub rooj mov ci thiab ob peb lub xov hlau.

Kauj ruam 1: Kev thaiv kab

Txoj haujlwm tseem ceeb tshaj plaws yog txuas xov tooj ntawm OLED rau Arduino. Peb txuas GND thiab VCC rau cov tsheb thauj mus los ntawm lub rooj noj mov; SCL rau tus lej pin 13; SDA rau tus lej pin 11; RES rau tus lej pin 8; DC rau tus pin 9; CS rau tus lej pin 10 thiab thaum kawg BL rau 3.3V ntawm Arduino. Siv 5v thiab GND pins los ntawm Arduino peb muaj peev xwm ua kom muaj zog tag nrho lub rooj mov ci.

Kauj ruam 2: Suab nrov nrov

Tom qab pib qhov xav tau rau TFT zaub. Txhawm rau tsim cov suab nrov zoo, peb xub xav tau lub suab nrov ua haujlwm yooj yim. Qhov no rov ua tus lej sib piv ntawm 0 thiab 1 raws qhov x thiab y qhov tseem ceeb dhau los., yog li cov lej loj heev hauv kab zauv.

ntab nrov nrov (int x, int y) {int n; n = x + y * 57; n += (n << 13) ^ n; rov qab (1.0 - ((n * ((n * n * 15731) + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); }

Peb ces 'du' suab nrov nrog lwm txoj haujlwm. Qhov no ua tiav los ntawm kev tsim tus nqi raws li tsis tsuas yog tshwm sim los ntawm kev sib koom tes dhau mus rau hauv txoj haujlwm, tab sis kuj tseem nyob ib puag ncig. Raws li qhov tshwm sim ntawm qhov no, ua haujlwm nyob ze rau ib leeg ua rau muaj txiaj ntsig zoo ib yam.

float smoothNoise (ntab x, ntab y) {ntab fractX = x - (int) x; float fractY = y - (int) y; int x1 = ((int) (x) + noiseWidth) % noiseWidth; int y1 = ((int) (y) + suab nrov siab) % suab nrov Height; int x2 = (x1 + noiseWidth - 1) % noiseWidth; int y2 = (y1 + suab nrov Height - 1) % suab nrov Height; ntab tus nqi = 0.0f; tus nqi += fractX * fractY * suab nrov (x1, y1); tus nqi += (1 - fractX) * fractY * suab nrov (x2, y1); tus nqi += fractX * (1 - fractY) * suab nrov (x1, y2); tus nqi += (1 - fractX) * (1 - fractY) * suab nrov (x2, y2); rov qab tus nqi; }

Kauj Ruam 3: Teeb Meem Siv Lub Suab nrov

Teeb Meem Siv Lub Suab nrov
Teeb Meem Siv Lub Suab nrov

Nrog qhov no peb tsim ob qhov cuam tshuam. Txhawm rau ua qhov no, peb hloov pauv los ntawm txhua lub pixel ntawm OLED thiab coj tus nqi nrov nrov raws li x thiab y tswj hwm ntawm cov pixels no. Thawj qhov ntawm cov txiaj ntsig no peb tsim los ntawm kev siv tus nqi tsim los xaiv xim, thiab pleev xim lub pixel nrog cov lus hais los saum toj no. Qhov tshwm sim thib ob tau tsim tawm hauv txoj hauv kev zoo ib yam, tab sis peb kuj muab cov xim los ntawm cov suab nrov tsim tawm. Qhov no tau muab cov qauv piv rau cov duab ntxoov ntxoo ntau dua. Txoj cai siv yog qhia hauv qab no:

void Noise2n3 (bool Noisy) {rau (int y = 0; y <noiseHeight; y ++) {rau (int x = 0; x 8) absNoise = 8; yog (Noisy) setNoisyColour (xim [absNoise], suab nrov); lwm tus setBlockColour (xim [absNoise]); TFTscreen.point (x, y); }}} void setNoisyColour (Xim xim, suab nrov nrov) {TFTscreen.stroke (xim.red * suab nrov, xim xim ntsuab * suab nrov, xim.blue * suab nrov); } void setBlockColour (Xim xim) {TFTscreen.stroke (colour.red, colour.green, colour.blue); }

Kauj Ruam 4: Teeb Meem Random Gradient

Kev Nyuaj Siab Gradient Effects
Kev Nyuaj Siab Gradient Effects
Kev Nyuaj Siab Gradient Effects
Kev Nyuaj Siab Gradient Effects
Kev Nyuaj Siab Gradient Effects
Kev Nyuaj Siab Gradient Effects

Muaj ob qhov cuam tshuam uas ua rau muaj qhov sib txig sib luag. Thawj qhov tshwm sim tso cov pixels cuam tshuam nrog lawv cov xim rgb, maj mam ua tus qauv gradient rau lub vijtsam. Qhov thib ob siv tib lub xim xim ib yam li thawj zaug, tab sis tso lawv rau hauv qhov kev txiav txim ruaj khov, tsim kab pheeb ces kaum sib npaug ntawm qhov screen.

Nov yog thawj (raws li cov xim):

tsis muaj suab nrov 1 () {rau (int z = 0; z <3; z ++) {TFTscreen.background (0, 0, 0); int CurrentColour [3] [3] = {{64, 35, 26}, {24, 64, 34}, {20, 18, 64}}; R = CurrentColour [z] [0]; G = CurrentColour [z] [1]; B = CurrentColour [z] [2]; rau (int x = 0; x <128; x ++) {rau (int y = 0; y <128; y ++) {int R_Lower = R - ((x+y) / 4); yog (R_Lower = 255) {R_Higher = 254; } int R_Offset = random (R_Lower, R_Higher); int G_Lower = G - ((x + y) / 4); yog (G_Lower = 255) {G_Higher = 254; } int G_Offset = random (G_Lower, G_Higher); int B_Lower = B - ((x + y) / 4); yog (B_Lower <1) {B_Lower = 0; } int B_Higher = B + ((x + y) / 4); yog (B_Higher> = 255) {B_Higher = 254; } int B_Offset = random (B_Lower, B_Higher); int ntau = 2; yog (z == 1) mult = 1; TFTscreen.stroke (R_Offset * ntau, G_Offset * ntau, B_Offset * ntau); TFTscreen.point ((R_Offset * (B_Offset / 32)), (G_Offset * (B_Offset / 32))); TFTscreen.point ((G_Offset * (B_Offset / 32)), (R_Offset * (B_Offset / 32))); TFTscreen.point ((B_Offset * (G_Offset / 32)), (R_Offset * (G_Offset / 32))); }}}}

Thiab qhov thib ob (qhov ua tau zoo dua qub):

tsis muaj suab nrov 4 () {rau (int z = 0; z <3; z ++) {TFTscreen.background (0, 0, 0); int CurrentColour [3] [3] = {{64, 35, 26}, {24, 64, 34}, {20, 18, 64}}; R = CurrentColour [z] [0]; G = CurrentColour [z] [1]; B = CurrentColour [z] [2]; rau (int x = 0; x <128; x ++) {rau (int y = 0; y <128; y ++) {int R_Lower = R - ((x+y) / 4); yog (R_Lower = 255) {R_Higher = 254; } int R_Offset = random (R_Lower, R_Higher); int G_Lower = G - ((x + y) / 4); yog (G_Lower = 255) {G_Higher = 254; } int G_Offset = random (G_Lower, G_Higher); int B_Lower = B - ((x + y) / 4); yog (B_Lower <1) {B_Lower = 0; } int B_Higher = B + ((x + y) / 4); yog (B_Higher> = 255) {B_Higher = 254; } int B_Offset = random (B_Lower, B_Higher); int ntau = 2; yog (z == 1) mult = 1; TFTscreen.stroke (R_Offset * ntau, G_Offset * ntau, B_Offset * ntau); TFTscreen.point (x, y); }}}}

Kauj Ruam 5: Qhov Kawg

Thaum kawg, peb ua ke cov teebmeem no mus rau hauv ib hom 'swb swb' ntawm zaj sawv. Txhawm rau ua tiav qhov no, peb tsuas yog hu ua txhua txoj haujlwm tom qab lwm qhov hauv lub sijhawm luv:

thaum (muaj tseeb) {Lub suab nrov 2n3 (tsis tseeb); Suab nrov 2n3 (muaj tseeb); TFTscreen.background (0, 0, 0); Suab nrov 1 (); Suab nrov 4 (); }

Pom zoo: