Mundarija:
2025 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2025-01-13 06:58
Ushbu maqolada men RGB Nano pikselli uzuk yordamida potansiyometrning aylanish ko'rsatkichini tuzaman.
Shunday qilib, potentsiometrda qilingan qancha inqilob RGB halqasida aks etadi
1 -qadam: kerakli komponentlar
ishlab chiqarish uchun zarur bo'lgan komponentlar:
- Arduino Nano v.3
- RGB Ring NeoPixels
- Potentsiometr
- Jumper simlari
- USB mini
- Loyiha kengashi
2 -qadam: O'chirish sxemasi
Yuqoridagi sxemaga muvofiq barcha komponentlarni yig'ing.
Arduino - Potensio va RGB halqalariga
+5V ==> 3. Potensio va VCC
GND ==> 1. Potensio va GND
A0 ==> 2. Potensio
D12 ==> IN
3 -qadam: dasturlash
Quyidagi kodni nusxa ko'chiring va eskizga joylashtiring
#include #ifdef _AVR_ #include // 16 MGtsli Adafruit Trinket uchun zarur #endif
#PIN 12ni aniqlang
#NUMPIXELS 16 ni aniqlang
Adafruit_NeoPixel piksellari (NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#kechiktirishni belgilang 10
bo'sh o'rnatish () {
#if aniqlangan (_ AVR_ATtiny85_) && (F_CPU == 16000000)
clock_prescale_set (clock_div_1); #endif
piksel.begin ();
piksel.setBrightness (10);
Serial.begin (9600); }
bo'sh halqa ()
{piksel.clear (); int val = analogRead (A0); val = xarita (val, 0, 1023, 0, 18);
if (val == 1) {for (int i = 0; i <1; i ++) {piksel.setPixelColor (i, piksellar. Color (0, 225, 0))); kechikish (10); }}
agar (val == 2)
{for (int i = 0; i <2; i ++) {piksel.setPixelColor (i, piksellar. Color (32, 225, 0))); kechikish (10); }}
agar (val == 3)
{for (int i = 0; i <3; i ++) {piksel.setPixelColor (i, piksellar. Color (64, 225, 0))); kechikish (10); }}
agar (val == 4)
{for (int i = 0; i <4; i ++) {piksel.setPixelColor (i, piksellar. Color (96, 225, 0))); kechikish (10); }}
agar (val == 5)
{for (int i = 0; i <5; i ++) {piksel.setPixelColor (i, piksellar. Color (128, 225, 0))); kechikish (10); }}
agar (val == 6)
{for (int i = 0; i <6; i ++) {piksel.setPixelColor (i, piksellar. Color (160, 225, 0))); kechikish (10); }}
agar (val == 7)
{for (int i = 0; i <7; i ++) {piksel.setPixelColor (i, piksellar. Color (192, 225, 0))); kechikish (10); }}
agar (val == 8)
{for (int i = 0; i <8; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 225, 0))); kechikish (10); }}
agar (val == 9)
{for (int i = 0; i <9; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 225, 0))); kechikish (10); }}
agar (val == 10)
{for (int i = 0; i <10; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 192, 0))); kechikish (10); }}
agar (val == 11)
{for (int i = 0; i <11; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 160, 0))); kechikish (10); }}
agar (val == 12)
{for (int i = 0; i <12; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 128, 0))); kechikish (10); }}
agar (val == 13)
{for (int i = 0; i <13; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 96, 0))); kechikish (10); }}
agar (val == 14)
{for (int i = 0; i <14; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 64, 0))); kechikish (10); }}
agar (val == 15)
{for (int i = 0; i <15; i ++) {piksel.setPixelColor (i, piksel. Color (225, 32, 0))); kechikish (10); }}
agar (val == 16)
{for (int i = 0; i <16; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 0, 0))); kechikish (10); }}
agar (val == 17)
{for (int i = 0; i <17; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 0, 0))); kechikish (10); }}
agar (val == 18)
{for (int i = 0; i <18; i ++) {piksel.setPixelColor (i, piksellar. Color (225, 0, 0))); kechikish (10); }} piksel.show (); kechikish (DELAYVAL); }
Sketch faylini quyida yuklab olish mumkin:
4 -qadam: Natija
Natijalarni yuqoridagi videoda ko'rish mumkin.
Potentsiometr har gal aylantirilganda, halqadagi LEDlarning soni va rangi potansiyometrda qilingan burilishlar soniga qarab yonadi.