INHOUDSOPGAWE:
2025 Outeur: John Day | [email protected]. Laas verander: 2025-01-13 06:56
In hierdie artikel maak ek 'n rotasie -aanwyser van die potensiometer met behulp van RGB Nano pixelring.
Dus, hoeveel omwentelinge op die potensiometer sal op die RGB -ring vertoon word
Stap 1: Vereiste komponente
die komponente wat nodig is om dit te maak:
- Arduino Nano v.3
- RGB RING NeoPixels
- Potensiometer
- Jumper Wire
- USB mini
- Projekraad
Stap 2: Kringskema
Monteer alle komponente volgens die aftrekskema hierbo.
Arduino na Potensio en RGB -ring
+5V ==> 3. Potensio en VCC
GND ==> 1. Potensio & GND
A0 ==> 2. Potensio
D12 ==> IN
Stap 3: Programmering
Kopieer die onderstaande kode en plak dit in u skets
#include #ifdef _AVR_ #include // Vereis vir 16 MHz Adafruit Trinket #endif
#definieer PIN 12
#definieer NUMPIXELS 16
Adafruit_NeoPixel pixels (NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#definieer vertraging 10
ongeldige opstelling () {
#as gedefinieer (_ AVR_ATtiny85_) && (F_CPU == 16000000)
klok_preskaalstel (klok_div_1); #endif
pixels.begin ();
pixels.setBrightness (10);
Serial.begin (9600); }
leemte lus ()
{pixels.clear (); int val = analogRead (A0); val = kaart (val, 0, 1023, 0, 18);
as (val == 1) {for (int i = 0; i <1; i ++) {pixels.setPixelColor (i, pixels. Color (0, 225, 0)); vertraging (10); }}
as (val == 2)
{for (int i = 0; i <2; i ++) {pixels.setPixelColor (i, pixels. Color (32, 225, 0)); vertraging (10); }}
as (val == 3)
{for (int i = 0; i <3; i ++) {pixels.setPixelColor (i, pixels. Color (64, 225, 0)); vertraging (10); }}
as (val == 4)
{for (int i = 0; i <4; i ++) {pixels.setPixelColor (i, pixels. Color (96, 225, 0)); vertraging (10); }}
as (val == 5)
{for (int i = 0; i <5; i ++) {pixels.setPixelColor (i, pixels. Color (128, 225, 0)); vertraging (10); }}
as (val == 6)
{for (int i = 0; i <6; i ++) {pixels.setPixelColor (i, pixels. Color (160, 225, 0)); vertraging (10); }}
as (val == 7)
{for (int i = 0; i <7; i ++) {pixels.setPixelColor (i, pixels. Color (192, 225, 0)); vertraging (10); }}
as (val == 8)
{for (int i = 0; i <8; i ++) {pixels.setPixelColor (i, pixels. Color (225, 225, 0)); vertraging (10); }}
as (val == 9)
{for (int i = 0; i <9; i ++) {pixels.setPixelColor (i, pixels. Color (225, 225, 0)); vertraging (10); }}
as (val == 10)
{for (int i = 0; i <10; i ++) {pixels.setPixelColor (i, pixels. Color (225, 192, 0)); vertraging (10); }}
as (val == 11)
{for (int i = 0; i <11; i ++) {pixels.setPixelColor (i, pixels. Color (225, 160, 0)); vertraging (10); }}
as (val == 12)
{for (int i = 0; i <12; i ++) {pixels.setPixelColor (i, pixels. Color (225, 128, 0)); vertraging (10); }}
as (val == 13)
{for (int i = 0; i <13; i ++) {pixels.setPixelColor (i, pixels. Color (225, 96, 0)); vertraging (10); }}
as (val == 14)
{for (int i = 0; i <14; i ++) {pixels.setPixelColor (i, pixels. Color (225, 64, 0)); vertraging (10); }}
as (val == 15)
{for (int i = 0; i <15; i ++) {pixels.setPixelColor (i, pixels. Color (225, 32, 0)); vertraging (10); }}
as (val == 16)
{for (int i = 0; i <16; i ++) {pixels.setPixelColor (i, pixels. Color (225, 0, 0)); vertraging (10); }}
as (val == 17)
{for (int i = 0; i <17; i ++) {pixels.setPixelColor (i, pixels. Color (225, 0, 0)); vertraging (10); }}
as (val == 18)
{for (int i = 0; i <18; i ++) {pixels.setPixelColor (i, pixels. Color (225, 0, 0)); vertraging (10); }} pixels.show (); vertraging (DELAYVAL); }
Sketslêer kan hieronder afgelaai word:
Stap 4: Resultaat
U kan die resultate in die video hierbo sien.
Elke keer as die potensiometer gedraai word, sal die nommer en kleur van die LED's op die ring dan brand volgens die aantal draaie op die potensiometer.