Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int filamentTimeout(){
- // if the filament has not moved in five minutes (300k ms) the filament must be stalled or jammed
- // sound the blinking alarm
- static unsigned long previousMillis = 0; // store for next time function is called
- unsigned long currentMillis = millis(); // get current time elapsed
- const unsigned long timeoutInterval = 300000; // can be changed to make this function more or less 'sensitive'
- double currentFilament = 0; // current amount of filament used
- static double previousFilament = 0; // check currentFilament against this to see if it's moving or not
- currentFilament = filamentUsed(500); // call this function in order to see how much filament has been used
- if(currentFilament > previousFilament){ // we can safely assume that the filament IS indeed moving
- previousFilament = currentFilament; // update to check against this value next time function is called
- return 0; // don't sound alarm
- }
- else{ // otherwise, filament might be jammed
- if(currentMillis - previousMillis >= timeoutInterval){ // has the timeout interval passed?
- return 1; // sound alarm - filament is not moving and timeout passed
- }
- else{
- previousMillis = currentMillis; // reset timeout if it hasn't passed
- return 0; // don't sound alarm
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement