Skip to content

Instantly share code, notes, and snippets.

@meikuam
Created June 29, 2021 16:54
Show Gist options
  • Save meikuam/ff21a160a37df78e88be3045c0fe1f27 to your computer and use it in GitHub Desktop.
Save meikuam/ff21a160a37df78e88be3045c0fe1f27 to your computer and use it in GitHub Desktop.
int led_pins[6] = {3, 5, 6, 9, 10, 11};
byte led_values[6] = {128, 128, 128, 128, 128, 128};
int button0_pin = 2;
int button0_state = 0;
void setup_leds() {
// вроде как это не обязательно при использовании analogWrite
for (int i = 0; i < 6; i++) {
pinMode(led_pins[i], OUTPUT);
}
}
void set_leds() {
for (int i = 0; i < 6; i++) {
analogWrite(led_pins[i], led_values[i]);
}
}
int led_id = 0;
int delta = -1;
void setup() {
Serial.begin(9600);
pinMode(button0_pin, INPUT);
setup_leds();
set_leds();
randomSeed(analogRead(0));
}
void loop() {
// можно считывать что-нибудь с кнопки
// button0_state = digitalRead(button0_pin);
// if (button0_state == 1) {
// Serial.println("button pressed");
// delay(300);
// }
// тестовый пример, моргаем светодиодами
for (int i = 0; i < 128; i++) {
for (int j = 0; j < 6; j++) {
led_values[j] = led_values[j] - 1;
}
set_leds();
delay(10);
}
delay(1000);
for (int i = 0; i < 128; i++) {
for (int j = 0; j < 6; j++) {
led_values[j] = led_values[j] + 1;
}
set_leds();
delay(10);
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment