Advertisement
SuperBrainAK

master control 0_4_5

Feb 23rd, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.98 KB | None | 0 0
  1. /*this is controlling my powerbox, 3050, 3090 and fans W/PWM.takes the temp of 3050/3090 to enable auto fan speed.
  2.  fan1 is a small computer fan, fan2 is the xbox fans.(no longer connected)remote cox universal aux 0820.
  3.  */
  4. #include <IRremote.h>                                       //includes libraries.
  5. #include <IRremoteInt.h>
  6. //const pin assignments
  7. const byte irin = 27;
  8. const byte temp = 45;
  9. const byte pbox = 0;
  10. const byte red = 17;
  11. const byte green = 13;
  12. const byte v5 = 21;
  13. const byte v9 = 22;
  14. const byte fan1 = 26;
  15. //const byte fan2 = 25;
  16. const byte Button1 = 1;
  17. const byte Button2 = 2;
  18. const byte Button3 = 3;
  19. const byte Button4 = 4;
  20. const byte Button5 = 5;
  21. const byte Button6 = 7;
  22. const byte Button7 = 8;
  23.  
  24.  
  25. IRrecv irrecv(irin);                                        //ir recv stuff.
  26. decode_results results;
  27.  
  28. void setup () {
  29.   pinMode(pbox, OUTPUT);                                    //pin modes
  30.   pinMode(red, OUTPUT);
  31.   pinMode(green, OUTPUT);
  32.   pinMode(v5, OUTPUT);
  33.   pinMode(v9, OUTPUT);
  34.   pinMode(fan1, OUTPUT);
  35.   //pinMode(fan2, OUTPUT);
  36.   pinMode(temp, INPUT);
  37.   pinMode(Button1, INPUT);
  38.   pinMode(Button2, INPUT);
  39.   pinMode(Button3, INPUT);
  40.   pinMode(Button4, INPUT);
  41.   pinMode(Button5, INPUT);
  42.   pinMode(Button6, INPUT);
  43.   pinMode(Button7, INPUT);
  44.   Serial.begin(9600);
  45.   irrecv.enableIRIn();
  46. }
  47. unsigned long last = millis();                              //declares millis var?
  48. byte startup = 0;                                           //runs startup sequence if=0.
  49. byte power = 0;                                             //my main power state.
  50. byte p5v = 0;                                               //my 5V power state.
  51. byte p9v = 0;                                               //my 9V power state.
  52. byte start1 = 0;                                            //startup for fan1.
  53. int speed1 = 0;                                             //speed of fan1.
  54. //int speed2 = 0;                                             //speed of fan2.
  55. int lspeed1 = 0;                                            //last speed of fan1.
  56. //int lspeed2 = 0;                                            //last speed of fan2.
  57. int tval = 5;                                               //temperature value.
  58. int ltval = 4;                                              //last temp. value.
  59.  
  60. void loop() {
  61.   if (startup == 0){                                        //sets the states of my sensitive outputs.
  62.     digitalWrite(red, HIGH);
  63.     digitalWrite(v5, LOW);
  64.     digitalWrite(v9, LOW);
  65.     startup = 1;
  66.   }
  67.   if (speed1 != lspeed1){                                   //writes the speed of fan1 if change.
  68.     delay (100);
  69.     lspeed1 = speed1;
  70.     if (speed1 <= 14){                                      //puts start1 if fan1 gets to slow to run.
  71.       start1 = 0;
  72.     }
  73.     if (start1 == 0){
  74.      
  75.     }
  76.     if (start1 == 1){                                       //starts the fan to access low speeds.
  77.       Serial.println("starting fan1");
  78.       analogWrite(fan1, 70);
  79.       start1 = 2;
  80.       delay (100);
  81.     }
  82.     if (speed1 > 14){
  83.       analogWrite(fan1, speed1);
  84.       Serial.print("fan1 speed is:");                       //says the fan1 speed.
  85.       Serial.println(speed1);
  86.     }
  87.     else {
  88.       Serial.print("fan1 unable to sustain: ");
  89.       Serial.println(speed1);
  90.       analogWrite(fan1, 0);
  91.     }
  92.   }
  93.   /*if (speed2 != lspeed2){                                   //writes the speed of fan2 if change.
  94.    delay (100);
  95.    lspeed2 = speed2;
  96.    analogWrite(fan2, speed2);
  97.    Serial.print("fan2 speed is:");                         //says the fan2 speed.
  98.    Serial.println(speed2);
  99.    }*/
  100.   byte pbutton = 0;                                         //temporary power variable state.
  101.   byte p5 = 0;                                              //temporary 5V variable state.
  102.   byte p9 = 0;                                              //temporary 9V variable state.
  103.   if (millis() - last > 1000) {                             //only recieves an input every second.
  104.     if (irrecv.decode(&results)) {                          //recieves the ir signal.
  105.       if (results.value == 0xd87245ba) {                    //power button.
  106.         Serial.println("power button");
  107.         pbutton = !pbutton;
  108.       }
  109.       else if (results.value == 0xffc03f){
  110.         Serial.println("display/setup");
  111.       }
  112.       else if (results.value == 0xff807f){
  113.         Serial.println("zoom");
  114.       }
  115.       else if (results.value == 0xff609f){
  116.         Serial.println("SUB");
  117.       }
  118.       else if (results.value == 0xff906f){
  119.         Serial.println("back");
  120.       }
  121.       else if (results.value == 0xfff807){
  122.         Serial.println("skip");
  123.       }
  124.       else if (results.value == 0xffb04f){
  125.         Serial.println("A-B");
  126.       }
  127.       else if (results.value == 0xffa857){
  128.         Serial.println("1/all");
  129.       }
  130.       else if (results.value == 0xd872748b){
  131.         Serial.println("up");
  132.         speed1 += 5;                                        //fan1 speed +5.
  133.       }
  134.       else if (results.value == 0xd872b44b){
  135.         Serial.println("down");
  136.         speed1 -= 5;                                        //fan1 speed -5.
  137.       }
  138.       else if (results.value == 0xd872f807){
  139.         Serial.println("left");
  140.         //speed2 -= 5;                                        //fan2 speed -5.
  141.       }
  142.       else if (results.value == 0xd87204fb){
  143.         Serial.println("right");
  144.         //speed2 += 5;                                        //fan2 speed +5.
  145.       }
  146.       else if (results.value == 0xd8720cf3){
  147.         Serial.println("select");
  148.         start1 = 2;                                         //tests the start1.
  149.       }
  150.       else if (results.value == 0xffe817){
  151.         Serial.println("play/pause");
  152.       }
  153.       else if (results.value == 0xff6897){
  154.         Serial.println("stop");
  155.       }
  156.       else if (results.value == 0xffb24d){
  157.         Serial.println("menu");
  158.       }
  159.       else if (results.value == 0xd872649b){
  160.         Serial.println("input");
  161.       }
  162.       else if (results.value == 0xff58a7){
  163.         Serial.println("angle");
  164.       }
  165.       else if (results.value == 0xff40bf){
  166.         Serial.println("lcd mode");
  167.       }
  168.       else if (results.value == 0xffa05f){
  169.         Serial.println("title");
  170.       }
  171.       else if (results.value == 0xd872d02f){
  172.         Serial.println("1");
  173.       }
  174.       else if (results.value == 0xd872906f){
  175.         Serial.println("2");
  176.       }
  177.       else if (results.value == 0xd872f00f){
  178.         Serial.println("3");
  179.       }
  180.       else if (results.value == 0xd872b04f){
  181.         Serial.println("4");
  182.       }
  183.       else if (results.value == 0xd87252ad){                //5v power button.
  184.         Serial.println("5");
  185.         p5 = !p5;
  186.       }
  187.       else if (results.value == 0xd872d02f){
  188.         Serial.println("6");
  189.       }
  190.       else if (results.value == 0xd872708f){
  191.         Serial.println("7");
  192.       }
  193.       else if (results.value == 0xd872609f){
  194.         Serial.println("8");
  195.       }
  196.       else if (results.value == 0xd872a05f){                //9v power button.
  197.         Serial.println("9");
  198.         p9 = !p9;
  199.       }
  200.       else if (results.value == 0xd87240bf){
  201.         Serial.println("0");
  202.       }
  203.       else {                                                //tells you any unknown signal.
  204.         if (results.decode_type == NEC) {
  205.           Serial.print("Decoded NEC: ");
  206.         }
  207.         else if (results.decode_type == SONY) {
  208.           Serial.print("Decoded SONY: ");
  209.         }
  210.         else if (results.decode_type == RC5) {
  211.           Serial.print("Decoded RC5: ");
  212.         }
  213.         else if (results.decode_type == RC6) {
  214.           Serial.print("Decoded RC6: ");
  215.         }
  216.         Serial.println(results.value, HEX);
  217.       }
  218.     }
  219.     irrecv.resume();
  220.     tval = analogRead(temp);                                //updates the temperature.
  221.     if (tval > 450){                                        //cold temperature turns fan off if not already off.
  222.       if (speed1 != 0){
  223.         speed1 = 0;
  224.       }
  225.     }
  226.     if (450 >= tval && tval >= 300){                        //medium temperature auto equalize the fan.
  227.       if (tval > ltval){                                    //if the temp. falls slow down the fan.
  228.         speed1 --;
  229.       }
  230.       if (tval < ltval){
  231.         speed1 ++;                                          //if the temp. rises speed up the fan.
  232.       }
  233.     }
  234.     if (tval < 300){                                        //rather hot turns fan to max.
  235.       speed1 = 70;
  236.     }
  237.     if (tval < 250){                                        //hot and hotter tells you so.
  238.       Serial.println("heat sink is hot!");
  239.       digitalWrite(red, HIGH);
  240.       digitalWrite(green, HIGH);
  241.     }
  242.     if (tval != ltval){                                     //if temperature changes update value.
  243.       ltval = tval;
  244.       Serial.print(ltval);
  245.       Serial.print("temp value is:");
  246.       Serial.println(tval);
  247.     }
  248.     if (digitalRead(Button1) == LOW){                                    //reads the button1 state.
  249.       Serial.println("button1");
  250.       pbutton = !pbutton;
  251.     }
  252.     if (digitalRead(Button2) == LOW){                                    //reads the button2 state.
  253.       Serial.println("button2");
  254.       p5 = !p5;
  255.     }
  256.     if (digitalRead(Button3) == LOW){                                    //reads the button3 state.
  257.       Serial.println("button3");
  258.       p9 = !p9;
  259.     }
  260.     if (pbutton == 1){                                      //toggles my power outputs.
  261.       Serial.println("power");
  262.       power = !power;
  263.       digitalWrite(pbox, power ? HIGH : LOW);
  264.       digitalWrite(green, power ? HIGH : LOW);
  265.       digitalWrite(v5, power ? HIGH : LOW);
  266.       digitalWrite(v9, power ? HIGH : LOW);
  267.       digitalWrite(red, power ? LOW : HIGH);
  268.     }
  269.     if (p5 == 1){                                           //toggles my 5V output.
  270.       Serial.println("5v power");
  271.       p5v = !p5v;
  272.       digitalWrite(v5, p5v ? HIGH : LOW);
  273.     }
  274.     if (p9 == 1){                                           //toggles my 9V output.
  275.       Serial.println("9v power");
  276.       p9v = !p9v;
  277.       digitalWrite(v9, p9v ? HIGH : LOW);
  278.     }
  279.     last = millis();
  280.   }                                                         //end of every second things.
  281.   /*if (digitalRead(Button4) == LOW){                         //change speeds of fans.
  282.     speed1 -= 1;
  283.     delay (100);
  284.   }
  285.   if (digitalRead(Button5) == LOW){
  286.     speed1 += 1;
  287.     delay (100);
  288.   }*/
  289.   /*if (digitalRead(Button6) == LOW){
  290.    speed2 -= 1;
  291.    delay (100);
  292.    }
  293.    if (digitalRead(Button7) == LOW){
  294.    speed2 += 1;
  295.    delay (100);
  296.    }*/
  297.   if (speed1 < 0){                                          //limits range of speeds.
  298.     Serial.println("fan1 low");
  299.     speed1 = 0;
  300.   }
  301.   if (speed1 > 70){
  302.     Serial.println("fan1 high");
  303.     speed1 = 70;
  304.   }
  305.   /*if (speed2 < 0){
  306.    Serial.println("fan2 low");
  307.    speed2 = 0;
  308.    }
  309.    if (speed2 > 100){
  310.    Serial.println("fan2 high");
  311.    speed2 = 100;
  312.    }*/
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement