Arduino2 LED ringen

Dit is eigenlijk een voorbereiding op het volgende project, waarin ik deze 2 ringen ga gebruiken die om elkaar heen draaien.

De hoofdrolspelers zijn hier 2 LED ringen, een met 8 LEDs en eentje met 12 LEDs. In dit project gaan we ze beide rondjes laten draaien. De ene met de klok mee, de ander tegengesteld.



ArduinoBreadboard

Zet de 2 ringen op je breadboard. Sluit voor beide ringen de 5V aan. Dan voor beide ringen de GND. Sluit dan de DI van de grote ring aan op poort 2 van de Arduino. En de DI van de kleine ring op poort 3 van de Arduino.



ArduinoSource code
/*
  Double LED ring

  (C) copyright www.punthooft.nl 2019-2024 
*/
#include "FastLED.h"  // Required is the FastLED library

// Constants
const int numberOfLeds1 = 12; // Number of LEDs in the ring
const int numberOfLeds2 = 8;
const int dataPin1 = 2;       // Datapin on the Arduino, connected to DIN on the big ring
const int dataPin2 = 3;       // Datapin on the Arduino, connected to DIN on the small ring

// Variables
CRGB led1Array[numberOfLeds1]; // Array of LEDs hold the color
CRGB led2Array[numberOfLeds2];

int colorHue;             // Color
int current1Led;          // Current led
int current2Led;          // Current led

// Setup function runs once when powerup the board and on reset 
void setup() { 

  //Initialise LED in the library
  FastLED.addLeds(led1Array, numberOfLeds1);
  FastLED.addLeds(led2Array, numberOfLeds2);

  // Set variables
  colorHue = 70;
  current1Led = 0;
  current2Led = 0;
}

// The loop function runs over and over again forever
void loop() {  

   // Change LED ring1
   current1Led++;
   if (current1Led >= numberOfLeds1) {
     current1Led = 0;
   }

   // Change LED ring2
   current2Led--;
   if (current2Led < 0) {
     current2Led = numberOfLeds2-1;
   }
   
   led1Array[current1Led].setHSV(colorHue,255,255);   // Activate LED in  color
   led2Array[current2Led].setHSV(colorHue,255,255);   // Activate LED in  color
   FastLED.show();                                    // Call library to update LED

   // Wait 50 milsecs before looping
   delay(50);                                         // Wait
   
   led1Array[current1Led].setHSV(colorHue,0,0);       // Deactivate LED in  color
   led2Array[current2Led].setHSV(colorHue,0,0);       // Deactivate LED in  color
   FastLED.show();                                    // Call library to update LED
} 



Categorie menu

Copyright 2024 www.punthooft.nl
We do not collect cookies for advertisement. Your data is never send to third parties.