Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- Servo myservo;
- int endpos = 0;
- int sensorwert;
- int temp = 180;
- int TMP36 = A3;
- int button = 4;
- int ledR = 0;
- int ledB = 2;
- int ledG = 1;
- void setup() {
- myservo.attach(3);
- pinMode (ledR, OUTPUT);
- pinMode (ledG, OUTPUT);
- pinMode (ledB, OUTPUT);
- RGB(0, 0, 0, 0);
- Serial.begin(9600);
- }
- void loop() {
- if (digitalRead(button) == HIGH) {
- sensorwert = analogRead(TMP36);
- temp = map(sensorwert, 0, 410, -50, 150);
- Serial.print(temp);
- Serial.print("-");
- temp=constrain(temp,-30,45);
- Serial.println(temp);
- endpos = map(temp, -30, 45, 180, 0);
- if (temp >= 35) {
- RGB(1, 0, 0, 200); // ROT
- RGB(0, 0, 0, 200); // AUS
- RGB(1, 0, 0, 200); // ROT
- RGB(0, 0, 0, 200); // AUS
- }
- if (temp < 35 && temp >= 30) {
- RGB(1, 0, 0, 0); // ROT
- }
- if (temp < 30 && temp >= 25) {
- RGB(1, 1, 0, 0); // GELB
- }
- if (temp < 25 && temp >= 20) {
- RGB(0, 1, 0, 0); // GRÜN
- }
- if (temp < 20 && temp >= 15) {
- RGB(1, 0, 1, 0); // TÜRKIS
- }
- if (temp < 15 && temp >= 10 ) {
- RGB(1, 1, 1, 0); // WEISS
- }
- if (temp < 10 && temp >= 5 ) {
- RGB(0, 1, 1, 0); // VIOLETT
- }
- if (temp < 5 && temp >= 0) {
- RGB(0, 0, 1, 0); // BLAU
- }
- if (temp < 0) {
- RGB(0, 0, 1, 200); // BLAU
- RGB(0, 0, 0, 200); // AUS
- RGB(0, 0, 1, 200); // BLAU
- RGB(0, 0, 0, 200); // AUS
- }
- myservo.write(0);
- for (int i = 0; i <= endpos; i += 1) {
- myservo.write(i);
- delay(15);
- }
- delay(5000);
- }
- else {
- RGB(0, 0, 0, 0);
- }
- }
- void RGB(int red, int green, int blue, int pause) {
- digitalWrite(ledR, red);
- digitalWrite(ledG, green );
- digitalWrite(ledB, blue);
- delay(pause);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement