Advertisement
jakopotamus

LED light strip, oscillating adjustable speed and brightness

May 30th, 2024 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define NUM_LEDS 60 //The amount of LEDs on your ARGB LED Strip that you wish to use
  4. #define DATA_PIN 7 //The Digital Pin on Arduino that connects to the LED Strip's Data Pin (DIN)
  5.  
  6. int intensityredPin = A0;
  7. int intensitygreenPin = A1;
  8. int intensitybluePin = A2;
  9. int speedPin = A3;
  10. int speed;
  11. int intensityred;
  12. int intensitygreen;
  13. int intensityblue;
  14.  
  15. CRGB leds[NUM_LEDS];
  16. //Set an array length the same as the total LEDs on your strip
  17. //so each LED can be addressed separately in setup/loop
  18. //e.g. leds[0] for the first one, leds[1] for the second one and so on
  19.  
  20.  
  21. void setup() {
  22. FastLED.addLeds<WS2812, DATA_PIN>(leds, NUM_LEDS);
  23. //Initialise the LED strip with the correct strip type (e.g. WS2812 is common),
  24. //Arduino Digital Pin and no. of LEDs to use
  25.  
  26. pinMode(speedPin, INPUT);
  27. pinMode(intensityredPin, INPUT);
  28. pinMode(intensitygreenPin, INPUT);
  29. pinMode(intensitybluePin, INPUT);
  30. Serial.begin(9600);
  31. }
  32.  
  33.  
  34. void loop() {
  35.  
  36.  
  37. green_led();
  38. revgreen_led();
  39.  
  40. }
  41.  
  42. void green_led() {
  43. for (int i = 0; i < NUM_LEDS; i++) {
  44. intensityred = map(analogRead(intensityredPin),0,1023,0,255);
  45. intensitygreen = map(analogRead(intensitygreenPin),0,1023,0,255);
  46. intensityblue = map(analogRead(intensitybluePin),0,1023,0,255);
  47. leds[i] = CRGB(intensityred,intensitygreen,intensityblue);
  48. FastLED.show();
  49. speed = map(analogRead(speedPin),0,1023,0,255);
  50. //Serial.println(speed);
  51. Serial.println(intensityred);
  52. Serial.println(intensitygreen);
  53. Serial.println(intensityblue);
  54. delay(speed);
  55. FastLED.clear();
  56. }
  57. }
  58.  
  59. void revgreen_led() {
  60. for (int i = NUM_LEDS - 1; i >= 0; i--) {
  61. intensityred = map(analogRead(intensityredPin),0,1023,0,255);
  62. intensitygreen = map(analogRead(intensitygreenPin),0,1023,0,255);
  63. intensityblue = map(analogRead(intensitybluePin),0,1023,0,255);
  64. leds[i] = CRGB(intensityred,intensitygreen,intensityblue);
  65. FastLED.show();
  66. speed = map(analogRead(speedPin),0,1023,0,255);
  67. //Serial.println(speed);
  68. Serial.println(intensityred);
  69. Serial.println(intensitygreen);
  70. Serial.println(intensityblue);
  71. delay(speed);
  72. FastLED.clear();
  73. }
  74. }
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement