ArduinoLED Ring
Dit is een ring van LED's. In deze variant zitten er 8 LED's in. De LED's zitten in een ronde ring. Dit is een leuk ding om effecten te maken. Rondjes draaien linksom en rechtsom. Langzaam vol laten lopen. Of als je een ring koopt met meer LED's erin, dan kun je hem ook als klok gebruiken. Maar ook met deze ring met 8 LED's zij veel leuke aandachttrekkende dingen te verzinnen.

Met de ring zijn leuke dingen te doen, vandaar dat er op deze pagina meerdere programma's staan, ieder met verschillende resultaten. De aansluiting blijft gelijk.
- Een dolle boel
- In rondjes
- Tegendraads
- Heen-en-weer
ArduinoBreadboard
Aansluiten is weer eenvoudig, hier heb ik geen schema van gemaakt.
- Din (of op sommige ringen DI), sluit deze aan op een digitale uitgang van de Arduino. Bijvoorbeeld 2.
- Power 5V van de Arduino kan op de 5V aansluiting op de ring
- Ground GND van de Arduino kan op de GND aansluiting op de ring
- Dout (of soms DO) gaan we nu niet gebruiken
ArduinoSource code
Op deze pagina staan een aantal programma's om te gebruiken met de LED ring. In al deze programma's gebruik ik de library FastLed. De ring moet digitaal worden aangesproken om helderheid, kleur en saturatie te definieren. De library zorgt hier voor.
De library is te downloaden op deze. In onderstaande programma's gebruik ik versie 3.3.2, waarschijnlijk/mogelijk zijn er latere versies als je dit leest. Mogelijk zijn die niet helemaal backwards compatibel met mijn versie van de library, zodat je de dan de code zult moet aanpassen. Of je neemt mijn versie en gebruikt de programmas zoals die hier staan.
ArduinoEen dolle boel
In dit programma doen we willekeurig LEDs aan met verschillende kleuren.
/* LED ring / Fun (C) copyright www.punthooft.nl 2019-2023 */ #include "FastLED.h" // Required is the FastLED library // Constants const int numberOfLeds = 8; // Number of LEDs in the ring const int dataPin = 2; // Datapin on the Arduino, connected to DIN on the ring // Variables CRGB ledArray[numberOfLeds]; // Array of LEDs hold the color byte colorHue = 0; // ColorHue changes every cycle to get rainbow effect int randomLed = 0; // Current random led // Setup function runs once when powerup the board and on reset void setup() { //Initialise LED in the library FastLED.addLeds<NEOPIXEL,dataPin>(ledArray, numberOfLeds); randomSeed(analogRead(A0)); // Randomize the random generator } // The loop function runs over and over again forever void loop() { // Pick a LED and activate it randomLed = random8(numberOfLeds); // Pick a random LED colorHue++; // Increase the color ledArray[randomLed].setHSV(colorHue,255,255); // Activate LED in color FastLED.show(); // Call library to update LED // Fade older LEDs for(int i=0; i<numberOfLeds; i++){ if (i != randomLed) { ledArray[i].fadeToBlackBy(255); // Fade the older LEDs } } FastLED.show(); // Display modified LED sequence // Wait 25 milsecs before looping delay(25); // Wait }
ArduinoIn rondjes
De LEDs lopen nu langzaam rond. Hierbij is er steeds een LED aan, deze veranderd door de kleuren van de regenboog. De LED erna is half aan. De achterliggende LEDs zijn uit.
/* LED ring / In circles www.punthooft.nl */ #include "FastLED.h" // Required is the FastLED library // Constants const int numberOfLeds = 8; // Number of LEDs in the ring const int dataPin = 2; // Datapin on the Arduino, connected to DIN on the ring // Variables CRGB ledArray[numberOfLeds]; // Array of LEDs hold the color int colorHue = 0; // ColorHue changes every cycle to get rainbow effect int currentLed = 0; // Current led int previousLed = 0; int oldestLed = 0; void setup() { //Initialise LED in the library FastLED.addLeds<NEOPIXEL,dataPin>(ledArray, numberOfLeds); randomSeed(analogRead(A0)); // Randomize the random generator } void loop() { // Pick a LED and activate it oldestLed = previousLed; previousLed = currentLed; currentLed++; if (currentLed >= 8) { currentLed=0; } colorHue+=16; // Increase the color if (colorHue > 255) { colorHue=0; } ledArray[currentLed].setHSV(colorHue,255,255); // Activate LED in color FastLED.show(); // Call library to update LED // Fade previous LED ledArray[previousLed].setHSV(colorHue,255,128); // Dim the previous LED FastLED.show(); // Call library to update LED // Turn off oldest LED ledArray[oldestLed].setHSV(colorHue,255,0); // Deactivate the oldest LED FastLED.show(); // Call library to update LED // Wait some milsecs before looping delay(500); // Wait }
ArduinoTegendraads
Nu hebben we 2 LEDs. De ene loopt met de klok mee en de ander tegen de klok in. De kleuren veranderen niet. Maar dat kun je nu zelf wel aanpassen.
/* LED ring / Opposite www.punthooft.nl */ #include "FastLED.h" // Required is the FastLED library // Constants const int numberOfLeds = 8; // Number of LEDs in the ring const int dataPin = 2; // Datapin on the Arduino, connected to DIN on the ring // Variables CRGB ledArray[numberOfLeds]; // Array of LEDs hold the color int colorHue = 0; // ColorHue changes every cycle to get rainbow effect int circle1LED = 0; // LED running clockwise int circle2LED = 0; // LED running counterclockwise void setup() { //Initialise LED in the library FastLED.addLeds<NEOPIXEL,dataPin>(ledArray, numberOfLeds); randomSeed(analogRead(A0)); // Randomize the random generator } void loop() { // Increment LED1, on overflow reset to 0 circle1LED++; if (circle1LED > 7) { circle1LED=0; } // Decrement LED2, on overflow reset to max circle2LED--; if (circle2LED < 0) { circle2LED=7; } // Display ledArray[circle1LED].setHSV(128,255,255); // Activate LED in aqua ledArray[circle2LED].setHSV(213,255,255); // Activate LED in purple FastLED.show(); // Call library to update LED // Wait some milsecs before looping delay(100); // Wait ledArray[circle1LED].setHSV(colorHue,255,0); // Activate LED in color ledArray[circle2LED].setHSV(colorHue,255,0); // Activate LED in color FastLED.show(); }
ArduinoHeen-en-weer
Tot slot een LED die niet weet wat ie wil. Deze blijft paniekerig links en rechtsom draaien ondertussen continue van kleur veranderend.
/* LED ring / Completely lost directions www.punthooft.nl */ #include "FastLED.h" // Required is the FastLED library // Constants const int numberOfLeds = 8; // Number of LEDs in the ring const int dataPin = 2; // Datapin on the Arduino, connected to DIN on the ring const int minDistance = 4; // Min distance is a half cycle const int maxDistance = 24; // Max distance is 3 cycles plus min // Variables CRGB ledArray[numberOfLeds]; // Array of LEDs hold the color int colorHue = 0; // Color int currentLed = 0; // Current LED int direction = 1; // Direction for filling/cleaning int distance = 0; // Distance running in a direction void setup() { //Initialise LED in the library FastLED.addLeds<NEOPIXEL,dataPin>(ledArray, numberOfLeds); randomSeed(analogRead(A0)); // Randomize the random generator distance = minDistance+random8(maxDistance); } void loop() { // Update color colorHue++; if (colorHue > 255) { colorHue=0; } // Update LED currentLed+=direction; if (currentLed > 7) { currentLed=0; } if (currentLed < 0) { currentLed=7; } // If distance is done, change direction distance--; if (distance == 0) { distance = minDistance+random8(maxDistance); direction*=-1; // Change direction } // Display ledArray[currentLed].setHSV(colorHue,255,255); // Activate LED in aqua FastLED.show(); // Call library to update LED // Wait some milsecs before looping delay(30); // Wait ledArray[currentLed].setHSV(colorHue,255,0); // Activate LED in color FastLED.show(); }
