Код:
byte mode;
byte repeated;
byte r1;
byte r2;
byte r3;
byte r4;
unsigned long last_time;
unsigned long last_time1;
unsigned long last_time2;
unsigned long last_time3;
unsigned long last_time4;
unsigned long last_time5;
unsigned long last_time6;
unsigned long last_time7;
unsigned long last_time8;
unsigned long last_time9;
unsigned long last_time10;
unsigned long last_time11;
unsigned long last_time12;
unsigned long last_time13;
unsigned long last_time14;
unsigned long last_time15;
unsigned long last_time16;
unsigned long last_time17;
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
pinMode(A3, INPUT_PULLUP);
mode = 1;
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (!digitalRead(A3) == 1) {
delay(500);
if (!digitalRead(A3) == 0) {
mode = mode + 1;
if (mode==5) {
mode = 1;
}
}
if (!digitalRead(A3) == 1) {
if(mode== 0) {
mode = 1;
}
else {
mode = 0;
}
}
}
if(mode==1) {
digitalWrite(3, 1); //Зажигаем красный светодиод
if (millis() - last_time > 100) {
last_time = millis();
for(int i=0;i<=255;i++) { // Плавно добавляем зелёный
analogWrite(6, i);
delay(10);
}
}
if (millis() - last_time1 > 100) {
last_time1 = millis();
for(int i=255;i>=0;i--) { //Плавно выключаем красный
analogWrite(3, i);
delay(10);
}
}
if (millis() - last_time2 > 100) {
last_time2 = millis();
for(int i=0;i<=255;i++) { //Плавно добавляем синий
analogWrite(9, i);
delay(10);
}
}
if (millis() - last_time3 > 100) {
last_time3 = millis();
for(int i=255;i>=0;i--) { //Плавно выключаем зелёный
analogWrite(6, i);
delay(10);
}
}
if (millis() - last_time4 > 100) {
last_time4 = millis();
for(int i=0;i<=255;i++) { //Плавно Включаем красный
analogWrite(3, i);
delay(10);
}
}
if (millis() - last_time5 > 100) {
last_time5 = millis();
for(int i=255;i>=0;i--) { //Плавно выключаем синий
analogWrite(9, i);
delay(10);
}
}
if (millis() - last_time6 > 100) {
last_time6 = millis();
}
}
if(mode==2) {
digitalWrite(3, 1);
if (millis() - last_time7 > 100) {
last_time7 = millis();
digitalWrite(3,0);
digitalWrite(6,1);
}
if (millis() - last_time8 > 100) {
last_time8 = millis();
digitalWrite(6,0);
digitalWrite(9,1);
}
if (millis() - last_time9 > 100) {
last_time9 = millis();
digitalWrite(9,0);
}
if (millis() - last_time10 > 100) {
last_time10 = millis();
}
}
if(mode==3) {
int led = random(1,4);
Serial.print(led);
if(led==1) {
digitalWrite(3, 1);
if (millis() - last_time11 > 1000) {
last_time11 = millis();
digitalWrite(3, 0);
}
}
if(led==2) {
digitalWrite(6, 1);
if (millis() - last_time12 > 1000) {
last_time12 = millis();
digitalWrite(6, 0);
}
}
if(led==3) {
digitalWrite(9, 1);
if (millis() - last_time13 > 1000) {
last_time13 = millis();
digitalWrite(9, 0);
}
}
}
if(mode==4) {
for(int i=0;i<=255;i++) { //Плавно выключаем синий
analogWrite(3, i);
analogWrite(6, i);
analogWrite(9, i);
delay(5);
}
for(int i=255;i>=0;i--) { //Плавно выключаем синий
analogWrite(3, i);
analogWrite(6, i);
analogWrite(9, i);
delay(5);
}
}
}
При нажатии кнопки ничего не меняется, кнопка подключена к GND и A3