#include #define PIN 8 #define NUMPIXELS 5 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800); void setup() { Serial.begin(9600); Serial.println ("START"); pinMode(13, OUTPUT); digitalWrite(13, HIGH); // DIGITAL13を5Vとして使用 pixels.begin(); // This initializes the NeoPixel library. } // 過去最大音をLEDで表現 int max = 0; void loop() { int val = analogRead(0); Serial.println (val); if (val > max){ max = val; } if (max <= 10){ // 低い int c = (max + 1) * 20; pixels.setPixelColor(0, pixels.Color(0, 0, c)); // 青 } else if (max <= 20){ int c = (max-10+1) * 20; pixels.setPixelColor(0, pixels.Color(c, c, 0)); // 黄 } else { int c = (max-20+1) * 20; if (c > 255) c = 255; pixels.setPixelColor(0, pixels.Color(c, 0, 0)); // 赤 } pixels.show(); delay(10); }