Mundarija:

Potensiometrli cheksiz oyna soati: 3 qadam
Potensiometrli cheksiz oyna soati: 3 qadam

Video: Potensiometrli cheksiz oyna soati: 3 qadam

Video: Potensiometrli cheksiz oyna soati: 3 qadam
Video: ESP32 Tutorial 23 - Reading Voltage of potentiometer using ESP32 | SunFounder's ESP32 IoT kit 2024, Noyabr
Anonim
Potensiometrli Infinity oyna soati
Potensiometrli Infinity oyna soati

Men cheksiz oynani uchratdim va men uni juda zo'r deb topdim. Bu meni cheksiz oynani yaratishga ilhomlantirdi, lekin menga maqsad bo'lishi kerak edi. Shunday qilib, men ishlaydigan cheksiz oynali soat yasashga qaror qildim. Bu potentsiometrlar yordamida rejimlarni, tezlikni va ranglarni o'zgartirish imkonini beradigan cheksiz oyna. (E'tibor bering: men birinchi marta shunday narsa yasayapman)

Ta'minotlar

Keling, bu ishni qilish uchun sizga kerak bo'lgan narsalarga sho'ng'iymiz!

Sizga kerak bo'ladi…

1) 1 Arduino Uno

3) 1 ta non paneli

4) 1 slaydni almashtirish

5) 3 ta potentsiometr

6) 1 9V batareya

7) 5 metrli WS2811 LED tasmasi

8) o'tish kabeli simlari

9) Soat (men 12 dyuymli katta zamonaviy soat ishlatgan soat)

10) Moslashuvchan oynali varaq (men oynani ishlatardim)

11) Maxfiylik filmi (Men bir tomonlama oynani ishlatganman)

12) Lehimlash talab qilinishi mumkin, bu sizning materialingizga bog'liq

1 -qadam: simlarni ulash

Ulanish
Ulanish
Ulanish
Ulanish

Kabelni ulash juda oddiy

- SPST tugmasi LEDni yoqadi va o'chiradi (A0)

- Chap potansiyometr yorug'likni boshqaradi (A1)

O'rta potentsiometr rejimlarni boshqaradi (A2)

- To'g'ri potentsiometr tezlikni boshqaradi (A3)

2 -qadam: Kod

#qo'shing

#PIN kodni belgilang 6

#ta'rif NUM_LEDS 54

#A0 A0 ni aniqlang

#A1 A1 ni aniqlang

#A2 A2 ni aniqlang

#A3 A3 ni aniqlang

// 1 -parametr = chiziqdagi piksellar soni

// 2 -parametr = pin raqami (ko'plari to'g'ri)

// 3 -parametr = pikselli turdagi bayroqlar, kerak bo'lganda ularni qo'shing:

// NEO_KHZ800 800 KGts bit oqimi (WS2812 LEDli NeoPixel mahsulotlarining ko'pchiligi)

// NEO_KHZ400 400 KHz (klassik 'v1' (v2 emas) FLORA piksellari, WS2811 drayverlari)

// NEO_GRB piksellari GRB bitstream uchun ulangan (ko'pchilik NeoPixel mahsulotlari)

// NEO_RGB piksellari RGB bit oqimi uchun ulangan (v1 emas FLORA piksel, v2)

Adafruit_NeoPixel tasmasi = Adafruit_NeoPixel (NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

bo'sh o'rnatish () {

strip.begin ();

strip.show (); // Barcha piksellarni o'chirib qo'ying

}

void loop () {

agar (analogRead (A0)> = 512) {

agar (analogRead (A2)> = 768) {

agar (analogRead (A3)> = 768) {

RainbowCycle (80, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A3)> = 512) {

RainbowCycle (60, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A3)> = 256) {

RainbowCycle (40, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

boshqa {

RainbowCycle (20, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

} agar boshqa (analogRead (A2)> = 512) {

agar (analogRead (A1)> = 768) {

CylonBounce (tasodifiy (255), tasodifiy (255), tasodifiy (255), 4, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A1)> = 512) {

CylonBounce (tasodifiy (255), 0, 0, 4, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A1)> = 256) {

CylonBounce (0, tasodifiy (255), 0, 4, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

boshqa {

CylonBounce (0, 0, tasodifiy (255), 4, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

} agar boshqa (analogRead (A2)> = 256) {

agar (analogRead (A1)> = 768) {

bayt r, g, b;

r = tasodifiy (255);

g = tasodifiy (255);

b = tasodifiy (255);

meteorRain (r, g, b, 10, 20, rost, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A1)> = 512) {

bayt r, g, b;

r = tasodifiy (255);

g = 0;

b = 0;

meteorRain (r, g, b, 10, 20, rost, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A1)> = 256) {

bayt r, g, b;

r = 0;

g = tasodifiy (255);

b = 0;

meteorRain (r, g, b, 10, 20, rost, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

boshqa {

bayt r, g, b;

r = 0;

g = 0;

b = tasodifiy (255);

meteorRain (r, g, b, 10, 20, rost, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

}

boshqa {agar (analogRead (A1)> = 768) {

RunningLights (tasodifiy (255), tasodifiy (255), tasodifiy (255), analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A1)> = 512) {

RunningLights (tasodifiy (255), 1, 1, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

} agar boshqa (analogRead (A1)> = 256) {

RunningLights (1, tasodifiy (255), 1, analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

boshqa {

RunningLights (1, 1, tasodifiy (255), analogRead (A0), analogRead (A1), analogRead (A2), analogRead (A3));

}

}

} boshqa {

setAll (0, 0, 0);

}

}

bo'sh kamalak aylanishi (int SpeedDelay, int oldA0, int oldA1, int oldA2, int oldA3) {

bayt *c;

uint16_t i, j;

uchun (j = 0; j <256*5; j ++) {// g'ildirakdagi barcha ranglarning 5 tsikli

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

uchun (i = 0; i <NUM_LEDS; i ++) {

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

c = G'ildirak (((i * 256 / NUM_LEDS) + j) & 255);

setPixel (i, *c, *(c+1), *(c+2));

}

showStrip ();

kechikish (SpeedDelay);

}

}

bayt * G'ildirak (bayt WheelPos) {

statik bayt c [3];

agar (WheelPos <85) {

c [0] = WheelPos * 3;

c [1] = 255 - WheelPos * 3;

c [2] = 0;

} if if (WheelPos <170) {

WheelPos -= 85;

c [0] = 255 - WheelPos * 3;

c [1] = 0;

c [2] = WheelPos * 3;

} boshqa {

WheelPos -= 170;

c [0] = 0;

c [1] = WheelPos * 3;

c [2] = 255 - WheelPos * 3;

}

qaytish c;

}

bo'sh CylonBounce (bayt qizil, bayt yashil, ko'k bayt, int EyeSize, int oldA0, int oldA1, int eskiA2, int eskiA3) {

int SpeedDelay;

int ReturnDelay;

agar (analogRead (A3)> = 768) {SpeedDelay = 80; ReturnDelay = 120;}

aks holda (analogRead (A3)> = 512) {SpeedDelay = 60; ReturnDelay = 100;}

aks holda (analogRead (A3)> = 256) {SpeedDelay = 40; ReturnDelay = 80;}

boshqa {SpeedDelay = 20; ReturnDelay = 60;}

uchun (int i = 0; i <NUM_LEDS-EyeSize-2; i ++) {

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

setAll (0, 0, 0);

setPixel (i, qizil/10, yashil/10, ko'k/10);

uchun (int j = 1; j <= EyeSize; j ++) {

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

setPixel (i+j, qizil, yashil, ko'k);

}

setPixel (i+EyeSize+1, qizil/10, yashil/10, ko'k/10);

showStrip ();

kechikish (SpeedDelay);

}

kechikish (ReturnDelay);

uchun (int i = NUM_LEDS-EyeSize-2; i> 0; i--) {

setAll (0, 0, 0);

setPixel (i, qizil/10, yashil/10, ko'k/10);

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

uchun (int j = 1; j <= EyeSize; j ++) {

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

setPixel (i+j, qizil, yashil, ko'k);

}

setPixel (i+EyeSize+1, qizil/10, yashil/10, ko'k/10);

showStrip ();

kechikish (SpeedDelay);

}

kechikish (ReturnDelay);

}

bekor RunningLights (bayt qizil, bayt yashil, ko'k bayt, int oldA0, int oldA1, int eskiA2, int eskiA3) {

int pozitsiyasi = 0;

int WaveDelay;

agar (analogRead (A3)> = 768) {WaveDelay = 80;}

aks holda (analogRead (A3)> = 512) {WaveDelay = 60;}

aks holda (analogRead (A3)> = 256) {WaveDelay = 40;}

boshqa {WaveDelay = 20;}

uchun (int j = 0; j

{

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

Lavozim ++; // = 0; // Lavozim + Baho;

uchun (int i = 0; i

// sinus to'lqin, 3 ofset to'lqinlar kamalak qiladi!

// float darajasi = sin (i + Pozitsiya) * 127 + 128;

// setPixel (i, daraja, 0, 0);

// float darajasi = sin (i + Pozitsiya) * 127 + 128;

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

setPixel (i, ((gunoh (i + pozitsiya) * 127 + 128)/255) * qizil, ((gunoh (i + pozitsiya) * 127 + 128)/255) * yashil, ((gunoh (i + pozitsiya) * 127 + 128)/255) * ko'k);

}

showStrip ();

kechikish (WaveDelay);

}

}

bo'sh meteorRain (bayt qizil, bayt yashil, ko'k bayt, bayt meteorSize, bayt meteorTrailDecay, boolean meteorRandomDecay, int oldA0, int oldA1, int eskiA2, int eskiA3) {

setAll (0, 0, 0);

int SpeedDelay;

agar (analogRead (A3)> = 768) {SpeedDelay = 80;}

aks holda (analogRead (A3)> = 512) {SpeedDelay = 60;}

aks holda (analogRead (A3)> = 256) {SpeedDelay = 40;}

boshqa {SpeedDelay = 20;}

uchun (int i = 0; i <NUM_LEDS+NUM_LEDS; i ++) {

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

// barcha LEDlar bir qadamda yorqinligini yo'qotadi

uchun (int j = 0; j

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

agar ((! meteorRandomDecay) || (tasodifiy (10)> 5)) {

fadeToBlack (j, meteorTrailDecay);

}

}

// meteor chizish

uchun (int j = 0; j <meteorSize; j ++) {

agar (oldA0! = analogRead (A0) || ((oldA1-256)> analogRead (A1)) || ((oldA1+256) analogRead (A2)) || ((oldA2+256) analogRead (A3)) | | ((eskiA3+256)

tanaffus;

}

agar ((i-j = 0)) {

setPixel (i-j, qizil, yashil, ko'k);

}

}

showStrip ();

kechikish (SpeedDelay);

}

}

vade fadeToBlack (int ledNo, bayt fadeValue) {

#ifdef ADAFRUIT_NEOPIXEL_H

// NeoPixel

uint32_t oldColor;

uint8_t r, g, b;

int qiymati;

oldColor = strip.getPixelColor (ledNo);

r = (oldColor & 0x00ff0000UL) >> 16;

g = (oldColor & 0x0000ff00UL) >> 8;

b = (oldColor va 0x000000ffUL);

r = (r <= 10)? 0: (int) r- (r*fadeValue/256);

g = (g <= 10)? 0: (int) g- (g*fadeValue/256);

b = (b <= 10)? 0: (int) b- (b*fadeValue/256);

strip.setPixelColor (ledNo, r, g, b);

#endif

#ifndef ADAFRUIT_NEOPIXEL_H

// FastLED

leds [ledNo].fadeToBlackBy (fadeValue);

#endif

}

// *** BU YERGA QO'SHING ***

void showStrip () {

#ifdef ADAFRUIT_NEOPIXEL_H

// NeoPixel

strip.show ();

#endif

#ifndef ADAFRUIT_NEOPIXEL_H

// FastLED

FastLED.show ();

#endif

}

bo'sh setPixel (int Pixel, qizil bayt, yashil bayt, ko'k bayt) {

#ifdef ADAFRUIT_NEOPIXEL_H

// NeoPixel

strip.setPixelColor (Pixel, strip. Color (qizil, yashil, ko'k));

#endif

#ifndef ADAFRUIT_NEOPIXEL_H

// FastLED

LEDlar [Piksel].r = qizil;

LEDlar [Piksel].g = yashil;

LEDlar [Piksel].b = ko'k;

#endif

}

void setAll (bayt qizil, bayt yashil, ko'k bayt) {

uchun (int i = 0; i <NUM_LEDS; i ++) {

setPixel (i, qizil, yashil, ko'k);

}

showStrip ();

}

3 -qadam: soatni yaratish

Soat yaratish
Soat yaratish
Soat yaratish
Soat yaratish
Soat yaratish
Soat yaratish

Ichki qismi tekis bo'lgan shisha soatni olishni tavsiya qilaman. Men moslashuvchan oynani soatning ichki qismiga qo'llaganimda, soat ichidagi raqamlarning chiqib ketishi bilan bog'liq muammo paydo bo'ldi, ko'zgu egilib, cheksiz oynaga ta'sir qilmadi. Iloji boricha tekis bo'lishi uchun moslashuvchan oynali varaq va Maxfiylik filmi bo'lishi kerak. Agar sizda soat bo'lsa, LEDni muammosiz ichkariga qo'yishingizga ishonch hosil qiling.

1 -qadam: Soatni oching va old oynani oling

2 -qadam: Maxfiylik filmini old oynaga qo'ying (Bu video sizga buni qanday qilishni ko'rsatib beradi)

3 -qadam: Moslashuvchan oynani soatning ichki qismiga qo'llang (buni qilishdan oldin soat qo'llarini echib oling)

4 -qadam: O'rtada teshik qiling, soat qo'llarini joyiga qo'ying

5 -qadam: LED tasmasini soatning ichki devorlariga joylashtiring (men bu qadam uchun issiq yopishtiruvchi tabancadan foydalandim)

6 -qadam: LED chizig'ini yoqing va oynani soatning yuqori qismiga qo'ying, shunda cheksiz oynali effekt mavjudmi yoki yo'qmi

7 -qadam: Hammasi tugagach, soatni bir joyga qo'ying va simlar orqa tomondan o'tishiga ruxsat bering

8 -qadam: Sizni loyihani tugatganingiz bilan tabriklayman va hamma narsa yaxshi ishlashi kerak

Agar sizda biron bir savol bo'lsa, ularni quyida izohlang (bilingki, men javob bera olmayman, lekin men qo'limdan kelganicha harakat qilaman)

Tavsiya: