Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.6 kB
4
Indexable
Never
#include <iarduino_MultiServo.h>  
#include <Wire.h>  
iarduino_MultiServo MSS;
uint32_t prevMillis = 0; 
int r = 0;
int g = 0;
int b = 0;
int w = 0;
int rpoint = 1024;
int gpoint = 2048;
int bpoint = 3072;
int wpoint = 4096;
int FadeTime = 100;
bool sun_flag = 1; 

int redled = 0; 
int greenled = 1; 
int blueled = 2; 
int whiteled = 3; 

void setup() {
Serial.begin(115200);
Wire.begin(D1,D2);
MSS.begin(0x40, 1000); 
Serial.println ("руский ваенний карабль пашол нахуй");

}

void loop() {
  if(sun_flag == 1){
  sunrise();
  }
  else if(sun_flag == 0){
  sunset();  
  }
 
}

void sunrise(){
 if (sun_flag && millis()-prevMillis>FadeTime) 
 {
 if (r < rpoint) r++;
 if (g < gpoint) g++; 
 if (b < bpoint) b++; 
 if (w < wpoint) w++;
 if (r == rpoint && g == gpoint && b == bpoint && w == wpoint) {
 sun_flag = !sun_flag;
 Serial.println ("настав день йопти");
 Serial.println (sun_flag);
 }
  MSS.digitalWrite(redled, r);
  MSS.digitalWrite(greenled, g);
  MSS.digitalWrite(blueled, b);
  MSS.digitalWrite(whiteled, w);
 prevMillis = millis();
 
 }}
 
 void sunset(){
 if (!sun_flag && millis()-prevMillis>FadeTime) 
 {
 if (r > 0) r--;
 if (g > 0) g--; 
 if (b > 0) b--; 
 if (w > 0) w--;
 if (r == 0 && g == 0 && b == 0 && w == 0) {
 sun_flag = !sun_flag;
 Serial.println ("настала комендатська година");
 }
  MSS.digitalWrite(redled, r);
  MSS.digitalWrite(greenled, g);
  MSS.digitalWrite(blueled, b);
  MSS.digitalWrite(whiteled, w);
  prevMillis = millis(); 
}}