Advertisement
Guest User

Sturing badkamer

a guest
Mar 14th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.24 KB | None | 0 0
  1. /*-----( Declare Constants and Pin Numbers )-----*/
  2.  
  3. #define keyboard_AnalogInput0 0
  4. #define keyboard_AnalogInput1 1
  5. #define keyboard_AnalogInput2 2
  6.  
  7. #define btnDouche 1
  8. #define btnLavabo 2
  9. #define btnVenti15 3
  10. #define btnSauna 4
  11. #define btnLicht 5
  12. #define btnWC 6
  13. #define btnAllesuit 7
  14. #define btnVenti5 8
  15. #define btnNONE0 10
  16. #define btnNONE1 11
  17. #define btnNONE2 12
  18.  
  19. /*-----( Declare Variables )-----*/
  20.  
  21. long lastToggledTime = 0;
  22. long ToggleTime = 50;
  23.  
  24. int Licht = 70;
  25. int LichtStatus = HIGH;
  26. int Lavabo = 71;
  27. int LavaboStatus = HIGH;
  28. int Douche = 72;
  29. int DoucheStatus = HIGH;
  30. int lastDoucheStatus = LOW;
  31. int WC = 73;
  32. int WCStatus = HIGH;
  33. int Venti = 74;
  34. int VentiStatus = HIGH;
  35. int Bezet = 75;
  36. int BezetStatus = HIGH;
  37. int Sauna = 76;
  38. int SaunaStatus = HIGH;
  39. int Allesuit;
  40. int AllesuitStatus = LOW;
  41.  
  42.  
  43. int adc_key_in0 = 0;
  44. int buttonPressed0;
  45. int adc_key_in1 = 0;
  46. int buttonPressed1;
  47. int adc_key_in2 = 0;
  48. int buttonPressed2;
  49.  
  50. void setup()
  51. {
  52.   Serial.begin(9600);
  53.   Serial.println("Sturing Badkamer");
  54.  
  55.   pinMode(Licht, OUTPUT);
  56.   digitalWrite(Licht, HIGH);
  57.   pinMode(Lavabo, OUTPUT);
  58.   digitalWrite(Lavabo, HIGH);
  59.   pinMode(Douche, OUTPUT);
  60.   digitalWrite(Douche, HIGH);
  61.   pinMode(WC, OUTPUT);
  62.   digitalWrite(WC, HIGH);
  63.   pinMode(Venti, OUTPUT);
  64.   digitalWrite(Venti, OUTPUT);
  65.   pinMode(Bezet, OUTPUT);
  66.   digitalWrite(Bezet, OUTPUT);
  67.   pinMode(Sauna, OUTPUT);
  68.   digitalWrite(Sauna, HIGH);
  69.  
  70.  
  71. }//--(end setup )---
  72.  
  73.  
  74. void loop()
  75. {
  76.   buttonPressed0 = read_keyboard0();
  77.   buttonPressed1 = read_keyboard1();
  78.   buttonPressed2 = read_keyboard2();
  79.  
  80.  
  81.   if (buttonPressed0 != btnNONE0 || buttonPressed1 != btnNONE1 || buttonPressed2 != btnNONE2)
  82.   {
  83.     Serial.print("OK - That looks like you pressed ");
  84.     Serial.println(buttonPressed0, DEC);
  85.     Serial.print("OK - That looks like you pressed ");
  86.     Serial.println(buttonPressed1, DEC);
  87.     Serial.print("OK - That looks like you pressed ");
  88.     Serial.println(buttonPressed2, DEC);
  89.  
  90.  
  91.   if (buttonPressed0 == 1 || buttonPressed2 == 1){
  92.        KeuzeDouche();
  93.  
  94.   }
  95.  
  96.  
  97.   if (buttonPressed0 == 2){
  98.        Serial.println("pressed btnLavabo");
  99.  
  100.   }
  101.  
  102.  
  103.   if (buttonPressed0 == 3){
  104.        Serial.println("pressed btnVenti15");
  105.  
  106.   }
  107.  
  108.  
  109.   if (buttonPressed0 == 4 || buttonPressed1 == 4){
  110.        Serial.println("pressed btnSauna");
  111.      
  112.   }
  113.  
  114.  
  115.     if (buttonPressed1 == 5){
  116.         Serial.println("pressed btnLicht");
  117.  
  118.   }
  119.  
  120.  
  121.   if (buttonPressed1 == 6){
  122.        Serial.println("pressed btnWC");
  123.  
  124.   }
  125.  
  126.  
  127.   if (buttonPressed1 == 7){
  128.        Serial.println("pressed btnAllesuit");
  129.    
  130.   }
  131.  
  132.  
  133.   if (buttonPressed2 == 8){
  134.        Serial.println("pressed btnVenti5");
  135.    
  136.   }  
  137.  
  138.   }
  139.  
  140. }//--(end main loop )---
  141.  
  142.  
  143.  
  144.  
  145. int read_keyboard0(){            // Read analog input 0    Viervoudige drukknop
  146.  
  147.   adc_key_in0 = analogRead(keyboard_AnalogInput0);
  148.  
  149.   if (adc_key_in0 > 1000) return btnNONE0;
  150.   if (adc_key_in0 < 100) return btnDouche;
  151.   if (adc_key_in0 < 380) return btnLavabo;
  152.   if (adc_key_in0 < 555) return btnVenti15;
  153.   if (adc_key_in0 < 800) return btnSauna;
  154.   return btnNONE0;
  155. }
  156.  
  157.  
  158. int read_keyboard1(){            // Read analog input 1    Zesvoudige drukknop 1 tot 4
  159.  
  160.   adc_key_in1 = analogRead(keyboard_AnalogInput1);
  161.  
  162.   if (adc_key_in1 > 1000) return btnNONE1;
  163.   if (adc_key_in1 < 100) return btnLicht;
  164.   if (adc_key_in1 < 380) return btnWC;
  165.   if (adc_key_in1 < 555) return btnSauna;
  166.   if (adc_key_in1 < 800) return btnAllesuit;
  167.   return btnNONE1;
  168. }
  169.  
  170.  
  171. int read_keyboard2(){            // Read analog input 2    Zesvoudige drukknop 5 en 6
  172.  
  173.   adc_key_in2 = analogRead(keyboard_AnalogInput2);
  174.  
  175.   if (adc_key_in2 > 1000) return btnNONE2;
  176.   if (adc_key_in2 < 500) return btnVenti5;
  177.   if (adc_key_in2 < 1000) return btnDouche;
  178.   return btnNONE2;
  179. }
  180.  
  181.  
  182. int KeuzeDouche(){
  183.         Serial.println("pressed btnDouche");
  184.    
  185.         if (lastDoucheStatus != DoucheStatus){
  186.           lastToggledTime = millis();
  187.           Serial.println("controlled time");
  188.         }
  189.      
  190.         if ((millis() - lastToggledTime) > ToggleTime){
  191.           lastDoucheStatus != DoucheStatus;
  192.                Serial.println("working");
  193.         }
  194.        
  195.  
  196.      
  197. }
  198.  
  199.  
  200. //*********( THE END )***********
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement