0
我在許多#define值中獲得了RGB顏色(HEX)。我想循環每種顏色 - 我的意思是:顯示第一種顏色 - 延遲(1000) - 第二種顏色 - 延遲(1000) - 第三種顏色等。 是否有可能通過如此多的#define來實現?而如何做到這一點...循環「定義」值
#define AQUA "#00ffff"
#define AZURE "#f0ffff"
#define BEIGE "#f5f5dc"
#define BLACK "#000000"
#define BLUE "#0000ff"
#define BROWN "#a52a2a"
#define CYAN "#00ffff"
#define DARKBLUE "#00008b"
#define DARKCYAN "#008b8b"
#define DARKGREY "#a9a9a9"
#define DARKGREEN "#006400"
#define DARKKHAKI "#bdb76b"
#define DARKMAGENTA "#8b008b"
#define DARKOLIVEGREEN "#556b2f"
#define DARKORANGE "#ff8c00"
#define DARKORCHID "#9932cc"
#define DARKRED "#8b0000"
#define DARKSALMON "#e9967a"
#define DARKVIOLET "#9400d3"
#define FUCHSIA "#ff00ff"
#define GOLD "#ffd700"
#define GREEN "#008000"
#define KHAKI "#f0e68c"
#define LIGHTBLUE "#add8e6"
#define LIGHTCYAN "#e0ffff"
#define LIGHTGREEN "#90ee90"
#define LIGHTGREY "#d3d3d3"
#define LIGHTPINK "#ffb6c1"
#define LIGHTYELLOW "#ffffe0"
#define LIME "#00ff00"
#define MAGENTA "#ff00ff"
#define MAROON "#800000"
#define NAVY "#000080"
#define OLIVE "#808000"
#define ORANGE "#ffa500"
#define PINK "#ffc0cb"
#define PURPLE "#800080"
#define VIOLET "#800080"
#define RED "#ff0000"
#define SILVER "#c0c0c0"
#define WHITE "#ffffff"
#define YELLOW "#ffff00"
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
void setup() {
Serial.begin(9600);
}
void loop() {
String hexstring = AQUA;
long number = (long) strtol(&hexstring[1], NULL, 16);
int r = number >> 16;
int g = number >> 8 & 0xFF;
int b = number & 0xFF;
setColor(r,g,b);
Serial.print("red is ");
Serial.println(r);
Serial.print("green is ");
Serial.println(g);
Serial.print("blue is ");
Serial.println(b);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}