Panel Cookies
Rainbow - Code
12/11/2022 | Views: 13297 | Arduino | by: ELECTRONOOBS      


This code is for the Arduino NANO and it will create a rainbow color on those 6 addressabe LEDs. You will need the adafruit library which you could download from this link.





Arduino Rainbow code 12/11/2022

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif


#define PIN 6       //Digital pin for the LED strip
#define AMOUNT 7    //Amount of LEDs taht the strip has

Adafruit_NeoPixel strip = Adafruit_NeoPixel(AMOUNT, PIN, NEO_GRB + NEO_KHZ800);

void setup() {  
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  rainbow(20); 
}




//////////////////////Functions//////////////////////
void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}







Last tutorials

All about Arduino PWM frequencies
Homemade Best Two Hand Multimeter with Arduino
Homemade Baby White Noise Generator
Measure AC RMS with Arduino
10 Stage Coilgun - Version 2

ADVERTISERS



>

Affiliate Disclosure

ADVERTISERS



PCBWAY PCB service





Curso Arduino Online nivel bajo