Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "DHT.h"
  2. #define LED1 18
  3. #define LED2 19
  4. #define BUT1 1
  5. #define BUT2 4
  6. #define PWM 11
  7. #define DHT1 2
  8.  
  9. DHT dht;
  10. int i=20;
  11. int buttonPressedCounter = 0;
  12. unsigned long current_time = 0;
  13.  
  14.  
  15. boolean up_direction = false;
  16. boolean lampMode = true;
  17.  
  18.  
  19.  
  20. void setup() {
  21.  
  22.   pinMode(7, OUTPUT);
  23.  
  24.   pinMode(LED1, OUTPUT);
  25.   pinMode(LED2, OUTPUT);
  26.  
  27.   pinMode(BUT1, INPUT_PULLUP);
  28.   pinMode(BUT2, INPUT_PULLUP);
  29.  
  30.   //czujnik temp
  31.   //dht.setup(DHT1);
  32.  
  33.   pinMode(PWM, OUTPUT);
  34.  
  35. }
  36.  
  37. void loop()
  38. {
  39.   if(digitalRead(BUT1)==HIGH)
  40.   {
  41.     if(buttonPressedCounter == 0)
  42.       buttonPressedCounter = 1;
  43.     else if(buttonPressedCounter == 1)
  44.       buttonPressedCounter = 2;
  45.     else if(buttonPressedCounter == 2)
  46.       buttonPressedCounter = 0;
  47.   }
  48.  
  49.   if(digitalRead(BUT2)==HIGH)
  50.   {
  51.     if(lampMode==true)
  52.       lampMode=false;
  53.     else if(lampMode==false)
  54.       lampMode=true;
  55.   }
  56.  
  57.    
  58.   if(lampMode == true)
  59.   {
  60.       if(millis() > current_time + 5)
  61.       {
  62.         current_time += 5;
  63.         if(up_direction == true)
  64.         {
  65.           i++;
  66.           if(i>250)
  67.             up_direction = false;
  68.         }
  69.         else
  70.         {
  71.           i--;
  72.           if(i<20)
  73.             up_direction = true;
  74.         }
  75.         analogWrite(11, i);
  76.       }
  77.   }
  78.   else if(lampMode == false)
  79.   {
  80.     analogWrite(11, 120);
  81.   }
  82.  
  83.   if(buttonPressedCounter == 0)
  84.     {
  85.       digitalWrite(LED1, LOW);
  86.       digitalWrite(LED2, LOW);
  87.     }
  88.   else if(buttonPressedCounter == 1)
  89.   {
  90.       digitalWrite(LED1, HIGH);
  91.       digitalWrite(LED2, LOW);
  92.   }
  93.   else if(buttonPressedCounter == 2)
  94.   {
  95.       digitalWrite(LED1, LOW);
  96.       digitalWrite(LED2, HIGH);
  97.   }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement