Advertisement
Guest User

Nerf Stampede Arduino

a guest
Jul 30th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.67 KB | None | 0 0
  1. /*
  2.  
  3.     N(erf)-OS V 1.0
  4.     May 2012
  5.     nerf@nilshaack.de
  6.     Free to use, modify, distribute for non-commercial use
  7.  
  8. */
  9.  
  10.  
  11. /*
  12.  
  13. The Graphics LCD Library that was used for this project ist located here:
  14. https://github.com/TCWORLD/gLCD-Library/downloads
  15. The Version used is v2.3
  16.  
  17. */
  18.  
  19. #include <gLCD.h>
  20.  
  21. /*
  22. ************************************************************
  23. ************************************************************
  24.  
  25.  BLASTER COFNFIGURATION
  26.  
  27. ************************************************************
  28. ************************************************************
  29. */
  30.  
  31.  
  32. int           buttonDelay     = 350;
  33. const double  irGateDistance  = 9.8;
  34. const int     triggerPause    = 0;
  35. const int     burst           = 3;
  36. int           burstSize       = 3;
  37. long          blasterCycleMax = 750000 ;     // timeout value for fire cycle
  38.  
  39. /*
  40. ********************************
  41. ********************************
  42.  
  43.  PIN CONFIGURATION
  44.  
  45. ********************************
  46. ********************************
  47. */
  48.  
  49. const int ledRed      = A0;
  50. const int ledYellow   = A1;
  51. const int ledGreen    = A2;
  52. //int unassignedOut1  = A3 (mit Vorwiederstand für LED beschaltet)
  53. //int unassignedIn1   = A4 (mit PullUp Resistor beschaltet)
  54. const int relais      = A5;
  55.  
  56. const int button1     =  0;
  57. const int button2     =  1;
  58. const int button3     =  2;
  59. const int irGateOne   =  5;
  60. const int checkLoaded =  6;
  61. const int tubePos     =  3;
  62. const int trigger     =  4;
  63. const int clip        =  7;
  64. const char RST        =  8; // Display
  65. const char CS         =  9; // Display
  66. int irGateTwo         = 10;
  67. const char Dat        = 11; // Display
  68. //int unassignedIn2   = 12 (unbeschaltet)
  69. const char Clk        = 13; // Display
  70.  
  71.  
  72.  
  73. /*
  74. ********************************
  75. ********************************
  76.  
  77.  Initialize Variables
  78.  
  79. ********************************
  80. ********************************
  81. */
  82.  
  83.  
  84. gLCD     graphic(RST,CS,Clk,Dat,1);
  85.  
  86. String   displaycontent, resulttext;
  87. String   blasterMessage[3];
  88. char     s[32];
  89. int      messagePosition                 = 0;
  90.  
  91. int      checkLoadedValue                = 0;
  92. int      checkLoadedValueLast            = 0;
  93.  
  94. int      checkClipValue                  = 0;
  95. int      checkClipValueLast              = 0;
  96.  
  97. int      checkTubePosValue               = 0;
  98. int      checkTubePosValueLast           = 0;
  99.  
  100. int      irGateOneValue                  = 0;
  101. int      irGateTwoValue                  = 0;
  102.  
  103. int      blasterClipSize                 = 0;
  104. int      blasterClipRemain               = 0;
  105.  
  106. int      triggerCountRunning             = 0;
  107. int      triggerCountSinceClipChange     = 0;
  108. int      triggerCountSinceCycleStart     = 0;
  109.  
  110. int      triggerValue                    = 0;
  111. int      triggerValueLast                = 0;
  112.  
  113. long     blasterCycleStart ;                            // storage for start timestamp of fire cycle
  114. long     blasterCycleElapsed ;                          // storage for "lap-time" of fire cycle
  115. long     blasterCycleSingleTime          = 0;
  116. long     blasterCycleMode                = 1 ;          // Which mode is the blaster running in
  117. boolean  blasterCycleRunning             = false;       // storage for current fire cycle status
  118. boolean  blasterCycleDriver              = 0;           // storage for current fire cycle status
  119.  
  120. double   dartspeed                       = 0;
  121. long     blasterGateOne ;                               // storage for timestamp of passing dart at Gate 1
  122. long     blasterGateTwo ;                               // storage for timestamp of passing dart at Gate 1
  123.  
  124. void setup() {
  125.  
  126.   //Serial.begin(9600);
  127.  
  128.   pinMode(button1,       INPUT);
  129.   pinMode(button2,       INPUT);
  130.   pinMode(button3,       INPUT);
  131.  
  132.   pinMode(clip,          INPUT);
  133.   pinMode(tubePos,       INPUT);
  134.   pinMode(trigger,       INPUT);
  135.  
  136.   pinMode(checkLoaded,   INPUT);
  137.   pinMode(irGateOne,     INPUT);
  138.   pinMode(irGateTwo,     INPUT);
  139.  
  140.   pinMode(ledRed,        OUTPUT);
  141.   pinMode(ledYellow,     OUTPUT);
  142.   pinMode(ledGreen,      OUTPUT);
  143.   pinMode(relais,        OUTPUT);
  144.  
  145.   // Initialize Display
  146.   graphic.Init(0,0,0,1,3); //Reversed X, Revesed Y direction.
  147.   graphic.Contrast(0x3C); // slightly stronger contrast
  148.  
  149.   // Do selfcheck if specific event on startup
  150.   if (digitalRead(button3) == LOW) {
  151.     selftest();
  152.   }
  153.  
  154.   digitalWrite(ledGreen,HIGH);
  155.   blasterCycleRunning = false;
  156.   blasterDisplayUpdate();
  157.  
  158.   checkLoadedValue = digitalRead(checkLoaded);
  159.   if (check_TubeQuick() == false || check_ClipQuick() == false || check_DartQuick() == false) {
  160.     if (check_ClipQuick() == false) {blasterDisplayClip(1);} else {blasterDisplayClip(0);}
  161.     if (check_DartQuick() == false) {blasterDisplayLoad(1);} else {blasterDisplayClip(0);}
  162.     blasterManageMessages("I'm not happy!",2);  
  163.   } else { blasterDisplayClip(0);blasterDisplayLoad(0);
  164.     blasterManageMessages("Welcome Player",3);
  165.   }  
  166.  
  167. }
  168.  
  169.  
  170.  
  171. /*
  172. ************************************************************
  173. Blaster Function: Blaster Cycle Manager
  174. ************************************************************
  175. */
  176.  
  177.  
  178. void blasterSTOP() {
  179.       digitalWrite(relais, LOW);
  180.       blasterCycleRunning = false;
  181.       triggerCountSinceCycleStart = 0;
  182. }
  183.  
  184. void blasterManagerCycleSemi () {
  185.  
  186.   triggerValue = digitalRead(trigger);
  187.   checkTubePosValue = digitalRead(tubePos);
  188.  
  189.  
  190.  
  191. }
  192.  
  193.  
  194. void blasterManagerCycleBurst () {
  195.  
  196.   triggerValue = digitalRead(trigger);
  197.   checkTubePosValue = digitalRead(tubePos);
  198.  
  199.  
  200. }
  201.  
  202. void blasterManagerCycleAuto () {
  203.  
  204.   triggerValue = digitalRead(trigger);
  205.   checkTubePosValue = digitalRead(tubePos);
  206.  
  207.  
  208. }
  209.  
  210. void blasterManageCycle () {
  211.   triggerValue = digitalRead(trigger);
  212.   checkTubePosValue = digitalRead(tubePos);
  213.  
  214.  /* if (checkTubePosValue == HIGH) {
  215.     digitalWrite(relais,LOW);
  216.   }
  217.   */
  218.   // Blaster not running
  219.   // Änderung State Trigger ... wird jetzt gedrückt
  220.  
  221.  
  222.   // The blaster is not within a shooting cycle (it is resting)
  223.   if (blasterCycleRunning == false) {  
  224.     if ((triggerValue == LOW && triggerValueLast == HIGH) || (triggerValue == LOW && triggerValueLast == LOW) ) {
  225.     //NEUE SCHUSS-SERIE    
  226.       if ( blasterCycleMode == -1 || (blasterCycleMode == 1 && triggerCountSinceCycleStart == 0) || (blasterCycleMode == burstSize && triggerCountSinceCycleStart <= burstSize-1)) {
  227.         if (check_DartQuick() == true && check_ClipQuick() == true && check_BarrelFree() == true && check_BlasterSafety() == true) {
  228.           blasterCycleStart = micros();
  229.           digitalWrite(relais, HIGH);
  230.           digitalWrite(ledGreen,LOW);
  231.           blasterCycleRunning = true;    
  232.         } else if (check_DartQuick() == false) {
  233.           blasterManageMessages("Check Dart",2);
  234.         } else if (check_ClipQuick() == false) {
  235.           blasterManageMessages("Load Status Confusing",0);      
  236.         }    
  237.       }
  238.       triggerValueLast = triggerValue;
  239.     } else if (triggerValue == HIGH && triggerValueLast == LOW) {
  240.       blasterSTOP();
  241.       digitalWrite(ledGreen, HIGH);  
  242.       triggerValueLast = triggerValue;
  243.     } else if (triggerValue == LOW) {
  244.      
  245.    
  246.     }
  247.   }
  248.  
  249.  
  250.  // The blaster is within a shooting cycle
  251.   if (blasterCycleRunning == true) {
  252.     // Do the following, when the blaster cycle is controlles event driven
  253.     if (blasterCycleDriver == 1) {
  254.       // if more than 150ms have passed and the tube is in resting position, close cycle
  255.       if ( micros() - blasterCycleStart >= 150000 && digitalRead(tubePos) == HIGH) {  
  256.         digitalWrite(relais, LOW);    
  257.       }
  258.     }
  259.      if (digitalRead(irGateOne) == LOW) {
  260.         blasterGateOne = micros();
  261.         dartspeed = 0;
  262.       }
  263.      if (digitalRead(irGateTwo) == LOW) {
  264.         blasterGateTwo = micros();
  265.         blasterCycleElapsed = (blasterGateTwo - blasterGateOne);
  266.         dartspeed = (irGateDistance/blasterCycleElapsed)*14400;
  267.         blasterCycleSingleTime = blasterGateTwo - blasterCycleStart;      
  268.         blasterGateOne = 0;
  269.         blasterGateTwo = 0;
  270.         triggerCountSinceCycleStart++;
  271.         triggerCountSinceClipChange++;
  272.         triggerCountRunning++;            
  273.         blasterCycleRunning = false;  
  274.         digitalWrite(ledGreen,HIGH);
  275.         digitalWrite(relais, LOW);
  276.         digitalWrite(ledYellow,LOW);    
  277.         digitalWrite(ledRed,LOW);      
  278.         blasterDisplayTriggerTime(dartspeed,blasterCycleSingleTime);
  279.         blasterDisplayLoadMessage();  
  280.         delay(triggerPause);
  281.       }
  282.       // Spätestens mit Timeout des Blasters
  283.       if ( micros() - blasterCycleStart >= blasterCycleMax && blasterCycleRunning == true) {
  284.         blasterSTOP();          
  285.         blasterDisplayTriggerTime(0,0);
  286.         blasterGateOne = 0;
  287.         blasterGateTwo = 0;
  288.         blasterManageMessages("TIMEOUT / SERVICE",0);
  289.       }
  290.      }
  291. }
  292.  
  293. /*
  294. ************************************************************
  295. The central system loop
  296. ************************************************************
  297. */
  298.  
  299. void loop() {
  300.   check_ClipSystem();
  301.   if (blasterCycleRunning == false) {  
  302.     check_DartLoad();
  303.     blasterMenuQuick();
  304.   }
  305.   blasterManageCycle();
  306. }
  307.  
  308.  
  309. /*
  310. ************************************************************
  311. ************************************************************
  312.  
  313.  Check Functions
  314.  
  315. ************************************************************
  316. ************************************************************
  317. */
  318.  
  319.  
  320. boolean check_TubeQuick() {
  321.   checkTubePosValue = digitalRead(clip);
  322.   checkTubePosValueLast = checkTubePosValue;
  323.   if (checkTubePosValue == HIGH) {return true;} else {return false;}
  324. }
  325.  
  326. boolean check_ClipQuick() {
  327.   checkClipValue = digitalRead(clip);
  328.   checkClipValueLast = checkClipValue;
  329.    if (checkClipValue == HIGH) {return true;} else {return false;}
  330. }
  331.  
  332. boolean check_ClipSystem() {  
  333.   checkClipValue = digitalRead(clip);  
  334.   if (checkClipValue == HIGH && checkClipValueLast == LOW) {
  335.       blasterManageMessages("CLIP SOLVED",3);  
  336.       blasterDisplayClip(0);
  337.       blasterClipSize = -1;
  338.       blasterClipRemain = -1;
  339.       triggerCountSinceClipChange = 0;
  340.       checkClipValueLast = checkClipValue;
  341.       return true;
  342.   } else
  343.    if(checkClipValue == LOW && checkClipValueLast == HIGH ) {
  344.       blasterManageMessages("CLIP Missing",1);  
  345.       checkClipValueLast = checkClipValue;
  346.       blasterDisplayClip(1);
  347.       return false;    
  348.    }
  349. }
  350.  
  351. boolean check_DartQuick() {
  352.   checkLoadedValue = digitalRead(checkLoaded);
  353.   checkLoadedValueLast = checkLoadedValue;
  354.    if (checkLoadedValue == LOW) {return true;} else {return false;}
  355. }
  356.  
  357. boolean check_DartLoad() {
  358.   checkLoadedValue = digitalRead(checkLoaded);
  359.   if (checkLoadedValue == LOW && checkLoadedValueLast == HIGH) {
  360.       blasterManageMessages("DART FOUND",3);  
  361.       blasterDisplayLoad(0);  
  362.       checkLoadedValueLast = checkLoadedValue;
  363.       return true;
  364.   } else
  365.    if(checkLoadedValue == HIGH && checkLoadedValueLast == LOW) {
  366.       blasterManageMessages("DART MISSING",0);  
  367.       blasterDisplayLoad(1);  
  368.       checkLoadedValueLast = checkLoadedValue;
  369.       return false;
  370.    }  
  371.    return false;
  372. }
  373.  
  374. boolean check_BarrelFree() {
  375.   irGateOneValue = digitalRead(irGateOne);
  376.   irGateTwoValue = digitalRead(irGateTwo);
  377.   if (irGateOneValue == HIGH && irGateTwoValue == HIGH) {
  378.       // blasterManageMessages("DART SOLVED",3);  
  379.       //checkLoadedValueLast = checkLoadedValue;
  380.       return true;
  381.   } else {
  382.     displaycontent = "Barrel-Safety: " + String(irGateOneValue) + " - " + String(irGateTwoValue);
  383.      blasterManageMessages(displaycontent,0);  
  384.      // checkLoadedValueLast = checkLoadedValue;    
  385.       return false;
  386.    }
  387.    return false;
  388. }
  389.  
  390. boolean check_BlasterSafety() {
  391.  
  392.     return true;
  393. }
  394.  
  395.  
  396. /*
  397. ************************************************************
  398. Blaster Function: Blaster Message Manager
  399. ************************************************************
  400. */
  401.  
  402. void blasterManageMessages(String incommingMessage,int priority) {
  403.  
  404.   if (incommingMessage != blasterMessage[0]) {
  405.    if (priority == 0) {
  406.     //  blasterSTOP();      
  407.       graphic.SetForeColour(15,0,0);      
  408.         digitalWrite(ledRed, HIGH);delay(100);digitalWrite(ledRed, LOW);delay(100);
  409.         digitalWrite(ledRed, HIGH);delay(100);digitalWrite(ledRed, LOW);delay(100);
  410.         digitalWrite(ledRed, HIGH);delay(100);digitalWrite(ledRed, LOW);delay(100);
  411.    } else if (priority == 1) {
  412.       graphic.SetForeColour(15,0,0);
  413.       digitalWrite(ledRed, HIGH);
  414.    } else if (priority == 2) {
  415.       digitalWrite(ledYellow, HIGH);
  416.       graphic.SetForeColour(8,8,0);  
  417.    } else if (priority == 3) {
  418.       graphic.SetForeColour(0,15,0);  
  419.       digitalWrite(ledRed, LOW);
  420.       digitalWrite(ledYellow, LOW);
  421.    }
  422.     blasterMessage[0] = incommingMessage;
  423.     graphic.SetBackColour(0,0,0);
  424.     graphic.Box(0,50,132,67,0);
  425.     graphic.Line(0,49,132,49,1);
  426.     graphic.Line(0,69,132,69,1);
  427.     messagePosition=(132-(incommingMessage.length()*6))/2;
  428.     graphic.Print(incommingMessage,messagePosition,52,2);    
  429.  
  430.   }
  431.  
  432.    if (priority == 0) {
  433.       digitalWrite(ledRed, HIGH); delay(300);digitalWrite(ledRed, LOW); delay(150);  digitalWrite(ledRed, HIGH); delay(300);digitalWrite(ledRed, LOW);delay(150);digitalWrite(ledRed, HIGH); delay(300);digitalWrite(ledRed, LOW);
  434.     }
  435.  
  436.  
  437. }
  438.  
  439. void blasterDisplayUpdate() {
  440.  graphic.SetBackColour(0,0,0);
  441.   graphic.Clear();
  442.   graphic.SetBackColour(15,15,15);
  443.   graphic.Box(0,11,132,49,0);
  444.   //graphic.SetBackColour(10,10,0);
  445.   //graphic.Box(0,50,132,68,0);
  446.   //Print out the test pattern.
  447.   graphic.SetForeColour(15,15,15);
  448.   graphic.Print("Nerf Operating System",3,2,0);
  449.   graphic.SetForeColour(0,0,0);
  450.   graphic.Print("Remain:   not known",3,15,2);
  451.   graphic.Print("Mode  :   Semi Auto",3,32,2);
  452.   graphic.SetForeColour(0,10,0);
  453.   graphic.Print("Clip Status   :   ---",3,72,0);
  454.   graphic.Print("Load Status   :   ---",3,82,0);
  455.   graphic.Print("Last Velocity :   ---",3,92,0);
  456.   graphic.Print("Cycle Time    :   ---",3,102,0);
  457.   graphic.Print("Trigger Sleep :  0.00",3,112,0);
  458.   graphic.SetForeColour(0,7,0);
  459.   graphic.Print("Cycle Mode    :  time",3,121,0);
  460.   graphic.SetBackColour(15,15,15);
  461. }
  462.  
  463.  
  464. void blasterDisplayClip(int toggle) {
  465.   graphic.SetBackColour(0,0,0);
  466.   graphic.Box(104,72,131,80,0);
  467.   if (toggle == 1) {
  468.     graphic.SetForeColour(15,0,0);
  469.     graphic.Print("miss",105,72,0);
  470.   } else {
  471.     graphic.SetForeColour(0,8,0);
  472.     graphic.Print("  ok",105,72,0);
  473.   }
  474. }
  475.  
  476. void blasterDisplayLoad(int toggle) {
  477.   graphic.SetBackColour(0,0,0);
  478.   graphic.Box(104,82,131,90,0);
  479.   if (toggle == 1) {
  480.     graphic.SetForeColour(15,0,0);
  481.     graphic.Print("miss",105,82,0);
  482.   } else {
  483.     graphic.SetForeColour(0,8,0);
  484.     graphic.Print("  ok",105,82,0);
  485.   }
  486. }
  487.  
  488. void blasterDisplayLoadMessage () {
  489.         graphic.SetBackColour(15,15,15); // white
  490.         graphic.SetForeColour(0,0,0); // black
  491.         graphic.Box(63,14,131,32,0);
  492.        
  493.         String clipSizeString;
  494.        
  495.         if (blasterClipRemain < 10) {displaycontent = "__";} else if (blasterClipRemain < 100) {displaycontent = "_";}
  496.         if (blasterClipSize < 10) {clipSizeString = "_";} else {clipSizeString = "";}
  497.            
  498.         if (blasterClipRemain > 0) {
  499.           blasterClipRemain--;
  500.           displaycontent = displaycontent + String(blasterClipRemain);
  501.           graphic.Print(displaycontent + " of " + clipSizeString + String(blasterClipSize),63,15,2);
  502.           if (blasterClipRemain <= 4 && blasterClipRemain > 1) {
  503.           blasterManageMessages("Prepare Reload",2);
  504.           } else if(blasterClipRemain <=1) {
  505.           blasterManageMessages("! RELOAD SOON !",2);          
  506.           }
  507.         } else if (blasterClipRemain == 0) {
  508.           displaycontent = displaycontent + String(triggerCountSinceClipChange);
  509.           graphic.Print(displaycontent + " total",63,15,2);          
  510.           blasterManageMessages("AMMO DEPLETED",2);        
  511.         } else if (triggerCountSinceClipChange <= 35) {
  512.           displaycontent = displaycontent + String(triggerCountSinceClipChange);
  513.           graphic.Print(displaycontent + " total",63,15,2);          
  514.           blasterManageMessages("~ SMOOTH ~",3);          
  515.         } else {
  516.           displaycontent = displaycontent + String(triggerCountSinceClipChange);
  517.           graphic.Print(displaycontent + " total",63,15,2);          
  518.           blasterManageMessages("GREEDY BASTARD",3);              
  519.         }
  520. }
  521.  
  522. void blasterDisplayTriggerTime(double velocity, double time) {
  523.   time = time/1000000;
  524.   graphic.SetBackColour(0,0,0);
  525.   graphic.Box(98,92,131,110,0);
  526.   graphic.SetForeColour(15,15,0);
  527.  
  528.   if (velocity < 10) {
  529.       graphic.Print(dtostrf(velocity,3,2,s),105,92,0);  
  530.   } else if (velocity < 100) {
  531.         graphic.Print(dtostrf(velocity,3,2,s),99,92,0);
  532.   } else {  
  533.       graphic.Print(dtostrf(velocity,3,2,s),93,92,0);
  534.   }
  535.  
  536.   graphic.Print(dtostrf(time,3,2,s),105,102,0);
  537. }
  538.  
  539. /*
  540. ************************************************************
  541. QUICK NENU
  542. ************************************************************
  543. */
  544.  
  545.  
  546. void blasterMenuQuick() {
  547. if (blasterCycleRunning == false) {
  548.  
  549.   // Quickbutton für Clipsize nach Clipwechsel
  550.   if (digitalRead(button1) == LOW ) {
  551.       if (blasterCycleMode == -1) {
  552.         displaycontent = "Semi Auto";
  553.         blasterCycleMode = 1;
  554.         triggerCountSinceCycleStart = 0;
  555.       } else if(blasterCycleMode == 1)  {
  556.         blasterCycleMode = burstSize;
  557.         displaycontent = String(burstSize) + "x - Burst";
  558.         triggerCountSinceCycleStart = 0;
  559.       }else if(blasterCycleMode == burstSize)  {
  560.         displaycontent = "Full Auto";
  561.         blasterCycleMode = -1;
  562.         triggerCountSinceCycleStart = 0;
  563.       }
  564.         //graphic.Print(displaycontent,3,70,0);
  565.         graphic.SetBackColour(15,15,15); // white
  566.         graphic.SetForeColour(0,0,0); // white
  567.         graphic.Box(62,32,131,48,0);
  568.         graphic.Print(displaycontent,63,32,2);
  569.         delay(buttonDelay);
  570.   }
  571.  
  572.   if (digitalRead(button3) == LOW ) {
  573.       if (blasterCycleDriver == 1) {
  574.         displaycontent = " time";
  575.         blasterCycleDriver = 0;
  576.       } else if(blasterCycleDriver == 0)  {
  577.         displaycontent = "event";
  578.         blasterCycleDriver = 1;
  579.       }
  580.         graphic.SetBackColour(0,0,0);
  581.         graphic.Box(98,121,131,129,0);
  582.         graphic.SetForeColour(15,15,0);
  583.         graphic.Print(displaycontent,99,121,0);
  584.         delay(buttonDelay);
  585.   }
  586.  
  587.   // Quickbutton für Clipsize nach Clipwechsel
  588.   if (digitalRead(button2) == LOW && triggerCountSinceClipChange <= 1) {
  589.       if (blasterClipSize == -1) {
  590.       blasterClipSize = 0;
  591.       blasterClipRemain = triggerCountSinceClipChange;
  592.       }
  593.       if (blasterClipSize == 0) {
  594.         blasterClipSize = 6;
  595.         blasterClipRemain = blasterClipSize - triggerCountSinceClipChange;
  596.       } else if(blasterClipSize == 6)  {
  597.         blasterClipSize = 18;
  598.         blasterClipRemain = blasterClipSize - triggerCountSinceClipChange;
  599.       }else if(blasterClipSize ==18)  {
  600.         blasterClipSize = 36;
  601.         blasterClipRemain = blasterClipSize - triggerCountSinceClipChange;
  602.       }else if(blasterClipSize ==36)  {
  603.         blasterClipSize = 6;
  604.         blasterClipRemain = blasterClipSize - triggerCountSinceClipChange;
  605.       }
  606.         graphic.SetBackColour(15,15,15); // white
  607.         graphic.SetForeColour(0,0,0);  //black
  608.         if (blasterClipRemain < 10) {displaycontent = "__";} else
  609.         if (blasterClipRemain < 100) {displaycontent = "_";}
  610.         String clipSizeString;
  611.         if (blasterClipSize < 10) {clipSizeString = "_";} else {clipSizeString = "";}
  612.        
  613.         displaycontent = displaycontent + String(blasterClipRemain);
  614.         graphic.Box(63,15,131,32,0);
  615.         graphic.Print(displaycontent + " of " + clipSizeString + String(blasterClipSize),63,15,2);
  616.         delay(buttonDelay);
  617.   }
  618. }
  619. }
  620.  
  621.  
  622. /*
  623. ************************************************************
  624. Blaster Function: Selftest
  625. ************************************************************
  626. */
  627.  
  628.  
  629.  
  630. void selftest() {
  631.  graphic.SetBackColour(0,0,0);
  632.   graphic.Clear();
  633.   graphic.SetForeColour(15,15,15);
  634.   graphic.Print("Initial Blaster Status Test",3,2,0);
  635.   if (digitalRead(clip) == LOW) {
  636.   graphic.Print("ClipLoad:   MISSING",3,12,0);
  637.   } else {
  638.   graphic.Print("ClipLoad:   ------",3,12,0);  
  639.   }
  640.   if (digitalRead(checkLoaded) == HIGH) {
  641.   graphic.Print("DartLoad:   MISSING",3,22,0);
  642.   } else {
  643.   graphic.Print("DartLoad:   ------",3,22,0);  
  644.   }
  645.   if (digitalRead(irGateOne) == HIGH) {
  646.   graphic.Print("irGate1 :   ------",3,32,0);
  647.   } else {
  648.   graphic.Print("irGate1 :   BLOCKED",3,32,0);  
  649.   }
  650.   if (digitalRead(irGateTwo) == HIGH) {
  651.   graphic.Print("irGate2 :   ------",3,42,0);
  652.   } else {
  653.   graphic.Print("irGate2 :   BLOCKED",3,42,0);  
  654.   }
  655.   if (digitalRead(button1) == HIGH) {
  656.   graphic.Print("Button1 :   ------",3,52,0);
  657.   } else {
  658.   graphic.Print("Button1 :   ACTIVE",3,52,0);  
  659.   }
  660.   if (digitalRead(button2) == HIGH) {
  661.   graphic.Print("Button2 :   ------",3,62,0);
  662.   } else {
  663.   graphic.Print("Button2 :   ACTIVE",3,62,0);  
  664.   }
  665.   if (digitalRead(button3) == HIGH) {
  666.   graphic.Print("Button3 :   ------",3,72,0);
  667.   } else {
  668.   graphic.Print("Button3 :   ACTIVE",3,72,0);  
  669.   }
  670.   if (digitalRead(trigger) == LOW) {
  671.   graphic.Print("Trigger :   ACTIVE",3,82,0);
  672.   } else {
  673.   graphic.Print("Trigger :   ------",3,82,0);  
  674.   }
  675.   if (digitalRead(tubePos) == LOW) {
  676.   graphic.Print("Tube Pos:   ACTIVE",3,92,0);
  677.   } else {
  678.   graphic.Print("Tube Pos:   ------",3,92,0);  
  679.   }
  680.  
  681.   graphic.Print("System  :   v1.0",3,120,0);
  682.   digitalWrite(ledGreen,HIGH);
  683.   digitalWrite(ledYellow,HIGH);
  684.   digitalWrite(ledRed,HIGH);
  685.   delay(buttonDelay);
  686.   digitalWrite(ledYellow,LOW);
  687.   digitalWrite(ledRed,LOW);
  688.   delay(1500);
  689. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement