Advertisement
Drakkheen

Untitled

Jan 18th, 2022
1,278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2. Servo myservo;
  3. int endpos = 0;
  4. int sensorwert;
  5. int temp = 180;
  6.  
  7. int TMP36 = A3;
  8. int button = 4;
  9. int ledR = 0;
  10. int ledB = 2;
  11. int ledG = 1;
  12.  
  13.  
  14. void setup() {
  15.   myservo.attach(3);
  16.   pinMode (ledR, OUTPUT);
  17.   pinMode (ledG, OUTPUT);
  18.   pinMode (ledB, OUTPUT);
  19.  
  20.   RGB(0, 0, 0, 0);
  21.   Serial.begin(9600);
  22.  
  23. }
  24.  
  25. void loop() {
  26.   if (digitalRead(button) == HIGH) {
  27.  
  28.     sensorwert = analogRead(TMP36);
  29.     temp = map(sensorwert, 0, 410, -50, 150);
  30.     Serial.print(temp);
  31.     Serial.print("-");
  32.     temp=constrain(temp,-30,45);
  33.     Serial.println(temp);
  34.    
  35.     endpos = map(temp, -30, 45, 180, 0);
  36.  
  37.     if (temp >= 35)   {
  38.       RGB(1, 0, 0, 200); // ROT
  39.       RGB(0, 0, 0, 200); // AUS
  40.       RGB(1, 0, 0, 200); // ROT
  41.       RGB(0, 0, 0, 200); // AUS
  42.     }
  43.     if (temp < 35 && temp >= 30)   {
  44.       RGB(1, 0, 0, 0); // ROT
  45.     }
  46.     if (temp < 30 && temp >= 25) {
  47.       RGB(1, 1, 0, 0); // GELB
  48.     }
  49.  
  50.     if (temp < 25 && temp >= 20) {
  51.       RGB(0, 1, 0, 0); // GRÜN
  52.     }
  53.  
  54.     if (temp < 20 && temp >= 15)  {
  55.       RGB(1, 0, 1, 0); // TÜRKIS
  56.     }
  57.  
  58.     if (temp < 15 && temp >= 10 )  {
  59.       RGB(1, 1, 1, 0); // WEISS
  60.     }
  61.  
  62.     if (temp < 10 && temp >= 5 ) {
  63.       RGB(0, 1, 1, 0); // VIOLETT
  64.     }
  65.  
  66.     if (temp < 5 && temp >= 0)   {
  67.       RGB(0, 0, 1, 0); // BLAU
  68.     }
  69.  
  70.     if (temp < 0)  {
  71.  
  72.       RGB(0, 0, 1, 200); // BLAU
  73.       RGB(0, 0, 0, 200); // AUS
  74.       RGB(0, 0, 1, 200); // BLAU
  75.       RGB(0, 0, 0, 200); // AUS
  76.     }
  77.     myservo.write(0);
  78.     for (int i = 0; i <= endpos; i += 1) {
  79.       myservo.write(i);
  80.       delay(15);
  81.     }
  82.     delay(5000);
  83.   }
  84.   else {
  85.     RGB(0, 0, 0, 0);
  86.   }
  87. }
  88.  
  89. void RGB(int red, int green, int blue, int pause) {
  90.   digitalWrite(ledR, red);
  91.   digitalWrite(ledG, green );
  92.   digitalWrite(ledB, blue);
  93.   delay(pause);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement