Advertisement
Phoxtane

function 4

Mar 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. int filamentTimeout(){
  2.  
  3. // if the filament has not moved in five minutes (300k ms) the filament must be stalled or jammed
  4. // sound the blinking alarm
  5.  
  6. static unsigned long previousMillis = 0; // store for next time function is called
  7. unsigned long currentMillis = millis(); // get current time elapsed
  8. const unsigned long timeoutInterval = 300000; // can be changed to make this function more or less 'sensitive'
  9.  
  10. double currentFilament = 0; // current amount of filament used
  11. static double previousFilament = 0; // check currentFilament against this to see if it's moving or not
  12.  
  13. currentFilament = filamentUsed(500); // call this function in order to see how much filament has been used
  14.  
  15. if(currentFilament > previousFilament){ // we can safely assume that the filament IS indeed moving
  16. previousFilament = currentFilament; // update to check against this value next time function is called
  17. return 0; // don't sound alarm
  18. }
  19. else{ // otherwise, filament might be jammed
  20. if(currentMillis - previousMillis >= timeoutInterval){ // has the timeout interval passed?
  21. return 1; // sound alarm - filament is not moving and timeout passed
  22. }
  23. else{
  24. previousMillis = currentMillis; // reset timeout if it hasn't passed
  25. return 0; // don't sound alarm
  26. }
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement