LED Strip Code
i downloaded code. here have several single leds flashing music microphone. in project, instead of single rgb leds, have 5 rgb led strips. need change in code? led strip 10m supernight rgb strip cut 5 equal strips.
// arduino pin numbers
const int do_pin = 2;
const int ao_pin = 0;
int sound;
int led1 = 8;
int led2 = 9;
int led3 = 10;
int led4 = 11;
int led5 = 12;
void setup() {
pinmode(do_pin, input);
pinmode(led1, output);
pinmode(led2, output);
pinmode(led3, output);
pinmode(led4, output);
pinmode(led5, output);
serial.begin(9600);
}
void loop() {
if (sound > 31) {
digitalwrite(led1, high);
}
if (sound < 31) {
digitalwrite(led1, low);
}
if (sound > 35) {
digitalwrite(led2, high);
}
if (sound < 35) {
digitalwrite(led2, low);
}
if (sound > 40) {
digitalwrite(led3, high);
}
if (sound < 40) {
digitalwrite(led3, low);
}
if (sound > 45) {
digitalwrite(led4, high);
}
if (sound < 45) {
digitalwrite(led4, low);
}
if (sound > 50) {
digitalwrite(led5, high);
}
if (sound < 50) {
digitalwrite(led5, low);
}
sound = analogread(ao_pin);
serial.print(digitalread(do_pin));
serial.print("-");
serial.println(analogread(ao_pin));
// arduino pin numbers
const int do_pin = 2;
const int ao_pin = 0;
int sound;
int led1 = 8;
int led2 = 9;
int led3 = 10;
int led4 = 11;
int led5 = 12;
void setup() {
pinmode(do_pin, input);
pinmode(led1, output);
pinmode(led2, output);
pinmode(led3, output);
pinmode(led4, output);
pinmode(led5, output);
serial.begin(9600);
}
void loop() {
if (sound > 31) {
digitalwrite(led1, high);
}
if (sound < 31) {
digitalwrite(led1, low);
}
if (sound > 35) {
digitalwrite(led2, high);
}
if (sound < 35) {
digitalwrite(led2, low);
}
if (sound > 40) {
digitalwrite(led3, high);
}
if (sound < 40) {
digitalwrite(led3, low);
}
if (sound > 45) {
digitalwrite(led4, high);
}
if (sound < 45) {
digitalwrite(led4, low);
}
if (sound > 50) {
digitalwrite(led5, high);
}
if (sound < 50) {
digitalwrite(led5, low);
}
sound = analogread(ao_pin);
serial.print(digitalread(do_pin));
serial.print("-");
serial.println(analogread(ao_pin));
well can learn how use else part of if statement , make code shorter.
Arduino Forum > Using Arduino > Project Guidance > LED Strip Code
arduino
Comments
Post a Comment