Advertisement
SuperBrainAK

master control 0_4_5 teensy multi-meter

Feb 24th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.93 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.  monitors the voltage and current has a selector for high current and low current (changes the resistance to calculate with) ABSOLUTE MAX OF LESS THAN 21.5v ON ALL INPUTS!
  4.  created by SuperBrainAK
  5.  */
  6. #include <IRremote.h>                                       //includes libraries.
  7. //const pin assignments
  8. const byte irin = 27;
  9. const byte temp = 45;
  10. const byte vlts = 38;
  11. const byte ain = 39;
  12. const byte aout = 40;
  13. const byte pbox = 0;
  14. const byte red = 17;
  15. const byte green = 13;
  16. const byte v5 = 21;
  17. const byte v9 = 22;
  18. const byte fan1 = 26;
  19. //const byte fan2 = 25;
  20. const byte Button1 = 1;
  21. const byte Button2 = 2;
  22. const byte Button3 = 3;
  23. const byte Button4 = 4;
  24. const byte Button5 = 5;
  25. const byte Button6 = 7;
  26. const byte Button7 = 8;
  27.  
  28.  
  29. IRrecv irrecv(irin);                                        //ir recv stuff.
  30. decode_results results;
  31.  
  32. void setup () {
  33.   pinMode(pbox, OUTPUT);                                    //pin modes
  34.   pinMode(red, OUTPUT);
  35.   pinMode(green, OUTPUT);
  36.   pinMode(v5, OUTPUT);
  37.   pinMode(v9, OUTPUT);
  38.   pinMode(fan1, OUTPUT);
  39.   //pinMode(fan2, OUTPUT);
  40.   pinMode(temp, INPUT);
  41.   pinMode(vlts, INPUT);
  42.   pinMode(ain, INPUT);
  43.   pinMode(aout, INPUT);
  44.   pinMode(Button1, INPUT);
  45.   pinMode(Button2, INPUT);
  46.   pinMode(Button3, INPUT);
  47.   pinMode(Button4, INPUT);
  48.   pinMode(Button5, INPUT);
  49.   pinMode(Button6, INPUT);
  50.   pinMode(Button7, INPUT);
  51.   Serial.begin(9600);
  52.   irrecv.enableIRIn();
  53. }
  54. unsigned long last = millis();                              //declares millis var?
  55. byte startup = 0;                                           //runs startup sequence if=0.
  56. byte power = 0;                                             //main power state.
  57. byte p5v = 0;                                               //5V power state.
  58. byte p9v = 0;                                               //9V power state.
  59. byte start1 = 0;                                            //startup for fan1.
  60. int speed1 = 0;                                             //speed of fan1.
  61. //int speed2 = 0;                                             //speed of fan2.
  62. int lspeed1 = 0;                                            //last speed of fan1.
  63. //int lspeed2 = 0;                                            //last speed of fan2.
  64. int tval = 0;                                               //temperature value.
  65. int ltval = 0;                                              //last temperature value.
  66. float volts = 0;                                            //voltage metering.
  67. float vampin = 0;                                           //voltage before the current resistor.
  68. float vampout = 0;                                          //voltage after the current resistor.
  69. byte amp = 0;                                               //0=low current, 1=high current.
  70. float amps = 0;                                             //calculated amps.
  71.  
  72. void loop() {
  73.   if (startup == 0){                                        //sets the states of my sensitive outputs.
  74.     digitalWrite(red, HIGH);
  75.     digitalWrite(pbox, HIGH);
  76.     digitalWrite(v5, LOW);
  77.     digitalWrite(v9, LOW);
  78.     startup = 1;
  79.   }
  80.   if (speed1 != lspeed1){                                   //writes the speed of fan1 if change.
  81.     delay (100);
  82.     lspeed1 = speed1;
  83.     if (speed1 <= 14){                                      //puts start1 if fan1 gets to slow to run.
  84.       start1 = 0;
  85.     }
  86.     if (start1 != 2){
  87.       if (start1 == 0){                                     //notices when to startup the fan.
  88.         if (37 > speed1 && speed1 > 14){
  89.           start1 = 1;
  90.         }
  91.       }
  92.     }
  93.     if (start1 == 1){                                       //starts the fan to access low speeds.
  94.       Serial.println("starting fan1");
  95.       analogWrite(fan1, 70);
  96.       start1 = 2;
  97.       delay (100);
  98.     }
  99.     if (speed1 > 14){
  100.       analogWrite(fan1, speed1);
  101.       Serial.print("fan1 speed is:");                       //says the fan1 speed.
  102.       Serial.println(speed1);
  103.     }
  104.     else {
  105.       Serial.print("fan1 unable to sustain: ");
  106.       Serial.println(speed1);
  107.       analogWrite(fan1, 0);
  108.     }
  109.   }
  110.   /*if (speed2 != lspeed2){                                   //writes the speed of fan2 if change.
  111.    delay (100);
  112.    lspeed2 = speed2;
  113.    analogWrite(fan2, speed2);
  114.    Serial.print("fan2 speed is:");                          //says the fan2 speed.
  115.    Serial.println(speed2);
  116.    }*/
  117.   byte pbutton = 0;                                         //temporary power variable state.
  118.   byte p5 = 0;                                              //temporary 5V variable state.
  119.   byte p9 = 0;                                              //temporary 9V variable state.
  120.   byte crnt = 0;                                            //temporary current variable state.
  121.   if (millis() - last > 1000) {                             //only recieves an input every second.
  122.     if (irrecv.decode(&results)) {                          //recieves the ir signal.
  123.       if (results.value == 0xd87245ba) {                    //power button.
  124.         Serial.println("power button");
  125.         pbutton = !pbutton;
  126.       }
  127.       else if (results.value == 0xffc03f){
  128.         Serial.println("display/setup");
  129.       }
  130.       else if (results.value == 0xff807f){
  131.         Serial.println("zoom");
  132.       }
  133.       else if (results.value == 0xff609f){
  134.         Serial.println("SUB");
  135.       }
  136.       else if (results.value == 0xff906f){
  137.         Serial.println("back");
  138.       }
  139.       else if (results.value == 0xfff807){
  140.         Serial.println("skip");
  141.       }
  142.       else if (results.value == 0xffb04f){
  143.         Serial.println("A-B");
  144.       }
  145.       else if (results.value == 0xffa857){                  //changes the current ranges.
  146.         Serial.println("1/all");
  147.         crnt = !crnt;
  148.       }
  149.       else if (results.value == 0xd872748b){
  150.         Serial.println("up");
  151.         speed1 += 5;                                        //fan1 speed +5.
  152.       }
  153.       else if (results.value == 0xd872b44b){
  154.         Serial.println("down");
  155.         speed1 -= 5;                                        //fan1 speed -5.
  156.       }
  157.       else if (results.value == 0xd872f807){
  158.         Serial.println("left");
  159.         //speed2 -= 5;                                        //fan2 speed -5.
  160.       }
  161.       else if (results.value == 0xd87204fb){
  162.         Serial.println("right");
  163.         //speed2 += 5;                                        //fan2 speed +5.
  164.       }
  165.       else if (results.value == 0xd8720cf3){
  166.         Serial.println("select");
  167.       }
  168.       else if (results.value == 0xffe817){
  169.         Serial.println("play/pause");
  170.       }
  171.       else if (results.value == 0xff6897){
  172.         Serial.println("stop");
  173.       }
  174.       else if (results.value == 0xffb24d){
  175.         Serial.println("menu");
  176.       }
  177.       else if (results.value == 0xd872649b){
  178.         Serial.println("input");
  179.       }
  180.       else if (results.value == 0xff58a7){
  181.         Serial.println("angle");
  182.       }
  183.       else if (results.value == 0xff40bf){
  184.         Serial.println("lcd mode");
  185.       }
  186.       else if (results.value == 0xffa05f){
  187.         Serial.println("title");
  188.       }
  189.       else if (results.value == 0xd872d02f){
  190.         Serial.println("1");
  191.       }
  192.       else if (results.value == 0xd872906f){
  193.         Serial.println("2");
  194.       }
  195.       else if (results.value == 0xd872f00f){
  196.         Serial.println("3");
  197.       }
  198.       else if (results.value == 0xd872b04f){
  199.         Serial.println("4");
  200.       }
  201.       else if (results.value == 0xd87252ad){                  //5v power button.
  202.         Serial.println("5");
  203.         p5 = !p5;
  204.       }
  205.       else if (results.value == 0xd872d02f){
  206.         Serial.println("6");
  207.       }
  208.       else if (results.value == 0xd872708f){
  209.         Serial.println("7");
  210.       }
  211.       else if (results.value == 0xd872609f){
  212.         Serial.println("8");
  213.       }
  214.       else if (results.value == 0xd872a05f){                  //9v power button.
  215.         Serial.println("9");
  216.         p9 = !p9;
  217.       }
  218.       else if (results.value == 0xd87240bf){
  219.         Serial.println("0");
  220.       }
  221.       else {                                                  //tells you any unknown signal.
  222.         if (results.decode_type == NEC) {
  223.           Serial.print("Decoded NEC: ");
  224.         }
  225.         else if (results.decode_type == SONY) {
  226.           Serial.print("Decoded SONY: ");
  227.         }
  228.         else if (results.decode_type == RC5) {
  229.           Serial.print("Decoded RC5: ");
  230.         }
  231.         else if (results.decode_type == RC6) {
  232.           Serial.print("Decoded RC6: ");
  233.         }
  234.         Serial.println(results.value, HEX);
  235.       }
  236.     }
  237.     irrecv.resume();
  238.     tval = analogRead(temp);                                  //updates the temperature.
  239.     if (tval > 450){                                          //cold temperature turns fan off if not already off.
  240.       if (speed1 != 0){
  241.         speed1 = 0;
  242.       }
  243.     }
  244.     if (450 >= tval && tval >= 300){                          //medium temperature auto equalize the fan.
  245.       if (tval > ltval){                                      //if the temp. falls slow down the fan.
  246.         speed1 --;
  247.       }
  248.       if (tval < ltval){
  249.         speed1 ++;                                            //if the temp. rises speed up the fan.
  250.       }
  251.     }
  252.     if (tval < 300){                                          //rather hot turns fan to max.
  253.       speed1 = 70;
  254.     }
  255.     if (tval < 250){                                          //hot and hotter tells you so.
  256.       Serial.println("heat sink is hot!");
  257.       digitalWrite(red, HIGH);
  258.       digitalWrite(green, HIGH);
  259.     }
  260.     Serial.print("temp value is:");                           //says the temp value.
  261.     ltval = tval;                                             //updates the last temperature.
  262.     Serial.println(tval);
  263.     (((analogRead(vlts)/5120.0f)*5*42500)/9750) == volts;     //reads the voltage.
  264.     Serial.print("voltage is");
  265.     Serial.println(volts);                                    //tells you the voltage.
  266.     (((analogRead(ain)/5120.0f)*5*42320)/9720) == vampin;     //reads the voltage in.
  267.     (((analogRead(aout)/5120.0f)*5*42890)/9890) == vampout;   //reads the voltage out.
  268.     Serial.print("voltage in is");
  269.     Serial.println(vampin);                                   //tells you the voltage in.*
  270.     Serial.print("voltage out is");
  271.     Serial.println(vampout);                                  //tells you the voltage out.*i will comment hese out as they are just for debugging
  272.     Serial.print("voltage drop is");
  273.     Serial.println(vampin - vampout);                         //tells you the voltage drop.
  274.     if (amp){                                                 //calculates for high current.
  275.       ((vampin - vampout)/.22) == amps;
  276.     }
  277.     else {
  278.       ((vampin - vampout)/.22) == amps;                       //calculates for low current.
  279.     }
  280.     Serial.print("amperage is ");
  281.     if (amp){
  282.       Serial.println("high:");
  283.     }
  284.     else {
  285.       Serial.println("low:");
  286.     }
  287.     Serial.println(amps);                                     //tells you the amperage.
  288.     if (digitalRead(Button1) == LOW){                         //reads the button1 state.
  289.       Serial.println("button1");
  290.       pbutton = !pbutton;
  291.     }
  292.     if (digitalRead(Button2) == LOW){                         //reads the button2 state.
  293.       Serial.println("button2");
  294.       p5 = !p5;
  295.     }
  296.     if (digitalRead(Button3) == LOW){                         //reads the button3 state.
  297.       Serial.println("button3");
  298.       p9 = !p9;
  299.     }
  300.     if (digitalRead(Button4) == LOW){                         //reads the button4 state.
  301.       Serial.println("button4");
  302.       crnt = !crnt;
  303.     }
  304.     if (pbutton == 1){                                        //toggles my power outputs.
  305.       Serial.println("power");
  306.       power = !power;
  307.       if (power){
  308.         Serial.println("on");
  309.       }
  310.       else {
  311.         Serial.println("off");
  312.       }
  313.       digitalWrite(pbox, power ? LOW : HIGH);
  314.       digitalWrite(green, power ? HIGH : LOW);
  315.       digitalWrite(v5, power ? HIGH : LOW);
  316.       digitalWrite(v9, power ? HIGH : LOW);
  317.       digitalWrite(red, power ? LOW : HIGH);
  318.     }
  319.     if (p5 == 1){                                             //toggles my 5V output.
  320.       Serial.println("5v power");
  321.       p5v = !p5v;
  322.       if (p5v){
  323.         Serial.println("on");
  324.       }
  325.       else {
  326.         Serial.println("off");
  327.       }
  328.       digitalWrite(v5, p5v ? HIGH : LOW);
  329.     }
  330.     if (p9 == 1){                                             //toggles my 9V output.
  331.       Serial.println("9v power");
  332.       p9v = !p9v;
  333.       if (p9v){
  334.         Serial.println("on");
  335.       }
  336.       else {
  337.         Serial.println("off");
  338.       }
  339.       digitalWrite(v9, p9v ? HIGH : LOW);
  340.     }
  341.     if (crnt == 1){                                           //changes the resistance to use for current calculation.
  342.       Serial.println("changed resistance");
  343.       amp = !amp;
  344.     }
  345.     last = millis();
  346.   }                                                           //end of every second things.
  347.   /*if (digitalRead(Button4) == LOW){                           //change speeds of fans.
  348.     speed1 -= 1;
  349.     delay (100);
  350.   }
  351.   if (digitalRead(Button5) == LOW){
  352.     speed1 += 1;
  353.     delay (100);
  354.   }*/
  355.   /*if (digitalRead(Button6) == LOW){
  356.    speed2 -= 1;
  357.    delay (100);
  358.    }
  359.    if (digitalRead(Button7) == LOW){
  360.    speed2 += 1;
  361.    delay (100);
  362.    }*/
  363.   if (speed1 < 0){                                            //limits range of speeds.
  364.     Serial.println("fan1 low");
  365.     speed1 = 0;
  366.   }
  367.   if (speed1 > 70){
  368.     Serial.println("fan1 high");
  369.     speed1 = 70;
  370.   }
  371.   /*if (speed2 < 0){
  372.    Serial.println("fan2 low");
  373.    speed2 = 0;
  374.    }
  375.    if (speed2 > 100){
  376.    Serial.println("fan2 high");
  377.    speed2 = 100;
  378.    }*/
  379. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement