2025 Avtor: John Day | [email protected]. Nazadnje spremenjeno: 2025-01-13 06:58
V tem članku bom naredil indikator vrtenja potenciometra z uporabo obroča RGB Nano Pixel.
Torej, koliko vrtljajev na potenciometru bo prikazanih na obroču RGB
Korak: Potrebne komponente
komponente, potrebne za njegovo izdelavo:
- Arduino Nano v.3
- RGB RIng NeoPixels
- Potenciometer
- Mostična žica
- Mini mini USB
- Projektni odbor
2. korak: Shema vezja
Vse komponente sestavite v skladu z zgornjo shemo črpanja.
Arduino na Potensio in RGB Ring
+5V ==> 3. Potensio in VCC
GND ==> 1. Potensio & GND
A0 ==> 2. Potenzio
D12 ==> IN
3. korak: Programiranje
Kopirajte spodnjo kodo in jo prilepite v skico
#include #ifdef _AVR_ #include // Potrebno za 16 MHz Adafruit Trinket #endif
#define PIN 12
#define NUMPIXELS 16
Slikovne pike Adafruit_NeoPixel (NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 10
void setup () {
#if definirano (_ AVR_ATtiny85_) && (F_CPU == 16000000)
nastavitev_časov_predmetov (ura_div_1); #endif
pixels.begin ();
pixels.setBrightness (10);
Serial.begin (9600); }
void loop ()
{pixels.clear (); int val = analogRead (A0); val = zemljevid (val, 0, 1023, 0, 18);
if (val == 1) {for (int i = 0; i <1; i ++) {pixels.setPixelColor (i, piksli. Color (0, 225, 0)); zamuda (10); }}
če (val == 2)
{for (int i = 0; i <2; i ++) {pixels.setPixelColor (i, pixels. Color (32, 225, 0)); zamuda (10); }}
če (val == 3)
{for (int i = 0; i <3; i ++) {pixels.setPixelColor (i, pixels. Color (64, 225, 0)); zamuda (10); }}
če (val == 4)
{for (int i = 0; i <4; i ++) {pixels.setPixelColor (i, pixels. Color (96, 225, 0)); zamuda (10); }}
če (val == 5)
{for (int i = 0; i <5; i ++) {pixels.setPixelColor (i, pixels. Color (128, 225, 0)); zamuda (10); }}
če (val == 6)
{for (int i = 0; i <6; i ++) {pixels.setPixelColor (i, pixels. Color (160, 225, 0)); zamuda (10); }}
če (val == 7)
{for (int i = 0; i <7; i ++) {pixels.setPixelColor (i, pixels. Color (192, 225, 0)); zamuda (10); }}
če (val == 8)
{for (int i = 0; i <8; i ++) {pixels.setPixelColor (i, pixels. Color (225, 225, 0)); zamuda (10); }}
če (val == 9)
{for (int i = 0; i <9; i ++) {pixels.setPixelColor (i, pixels. Color (225, 225, 0)); zamuda (10); }}
če (val == 10)
{for (int i = 0; i <10; i ++) {pixels.setPixelColor (i, pixels. Color (225, 192, 0)); zamuda (10); }}
če (val == 11)
{for (int i = 0; i <11; i ++) {pixels.setPixelColor (i, pixels. Color (225, 160, 0)); zamuda (10); }}
če (val == 12)
{for (int i = 0; i <12; i ++) {pixels.setPixelColor (i, pixels. Color (225, 128, 0)); zamuda (10); }}
če (val == 13)
{for (int i = 0; i <13; i ++) {pixels.setPixelColor (i, pixels. Color (225, 96, 0)); zamuda (10); }}
če (val == 14)
{for (int i = 0; i <14; i ++) {pixels.setPixelColor (i, pixels. Color (225, 64, 0)); zamuda (10); }}
če (val == 15)
{for (int i = 0; i <15; i ++) {pixels.setPixelColor (i, pixels. Color (225, 32, 0)); zamuda (10); }}
če (val == 16)
{for (int i = 0; i <16; i ++) {pixels.setPixelColor (i, pixels. Color (225, 0, 0)); zamuda (10); }}
če (val == 17)
{for (int i = 0; i <17; i ++) {pixels.setPixelColor (i, pixels. Color (225, 0, 0)); zamuda (10); }}
če (val == 18)
{for (int i = 0; i <18; i ++) {pixels.setPixelColor (i, pixels. Color (225, 0, 0)); zamuda (10); }} slikovnih pik.show (); zamuda (DELAYVAL); }
Sketch datoteko lahko prenesete spodaj:
4. korak: Rezultat
Rezultate si lahko ogledate v zgornjem videu.
Tako se vsakič, ko potenciometer zavrtite, zasveti število in barva LED na obroču glede na število obratov na potenciometru.