c_cpp Arduino草图通过色谱循环RGB LED。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp Arduino草图通过色谱循环RGB LED。相关的知识,希望对你有一定的参考价值。

const int redPin = 8;
const int greenPin = 9;
const int bluePin = 10;
#define LDR 0

void setup() {
  // Start off with the LED off.
  setColourRgb(0,0,0);
  Serial.begin(9600);
    unsigned int rgbColour[3];

  // Start off with red.
  rgbColour[0] = 255;
  rgbColour[1] = 0;
  rgbColour[2] = 0;  

  // Choose the colours to increment and decrement.
  for (int decColour = 0; decColour < 3; decColour += 1) {
    int incColour = decColour == 2 ? 0 : decColour + 1;

    // cross-fade the two colours.
    for(int i = 0; i < 255; i += 1) {
      rgbColour[decColour] -= 1;
      rgbColour[incColour] += 1;
      
      setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
      delay(5);
    }
  }
}

void loop() {

}

void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);
  Serial.print("rgb(");
  Serial.print( red );
    Serial.print(",");
  Serial.print( green );
    Serial.print(",");
  Serial.print( blue );
  Serial.print(") -");
  Serial.print( analogRead( LDR ) );
  Serial.print("-");
    Serial.println();
 }

以上是关于c_cpp Arduino草图通过色谱循环RGB LED。的主要内容,如果未能解决你的问题,请参考以下文章

通过 Processing/Arduino 控制 Spotify

合并 Arduino 草图 (MIDI)

Arduino草图,多定义错误

草图大师中“HLS”“HSB”“RGB”代表啥?

new-Operator 大幅增加了 Arduino 草图的大小 - 为啥?

图形化编程娱乐于教,Kittenblock arduino实例,RGB灯带