===== Machine Mileage (Oil Change) Counter ===== * Need to add Mileage counter for every axis X, Y and Z. * Need to add Mileage Display with reset button for each axis * Need to add Service Led on the main screen if any of mileage value exceed Service value. The led should blink 1 time per second. We will add Oil change configuration into separated XML-include file for simple integration into different profiles. We take **1280M5** profile as based profile to add **Oil Change Counter **. {{mycnc:mycnc-oil-change--1.png}} main() { //touch global variables 6890,6891,6892 to save its values in cnc-variables.xml gvarset(6890,gvarget(6890)); gvarset(6891,gvarget(6891)); gvarset(6892,gvarget(6892)); //get initial machine coordinates for x,y,z pos_x=gvarget(5021); pos_y=gvarget(5022); pos_z=gvarget(5023); //initialize ticks counter ticks=0; //endless loop to handle Oil-Change Counter do{ //read limit Limit values for all axes x,y,x and arrange it to Meters limit_x=gvarget(6890)*1000; limit_y=gvarget(6891)*1000; limit_z=gvarget(6892)*1000; //X axis handler //Check if X position changed dx=pos_x-gvarget(5021); if (dx!=0) { pos_x=gvarget(5021);//update changes if (dx<0){dx=0-dx;};//get absoluet value of x moves //check move length does not exceed 10mm (to exclude possible error) //and add move length to variable #6090 if (dx<10){gvarset(6090,gvarget(6090)+dx); }; }; //Y axis handler dy=pos_y-gvarget(5022); if (dy!=0) { pos_y=gvarget(5022); if (dy<0){dy=0-dy;}; if (dy<10){gvarset(6091,gvarget(6091)+dy); }; }; //Z axis handler dz=pos_z-gvarget(5023); if (dy!=0) { pos_z=gvarget(5023); if (dz<0){dz=0-dz;}; if (dz<10){gvarset(6092,gvarget(6092)+dz); }; }; //Check is any axis mileage exceed limit alarm=0; if (gvarget(6090)>limit_x) { alarm=1; }; if (gvarget(6091)>limit_y) { alarm=1; }; if (gvarget(6092)>limit_z) { alarm=1; }; //In case Oil-Change event handle varaible #6085 blink 1 time per second if (alarm!=0) { ticks++; if (ticks<8) {gvarset(6085,0);} else {gvarset(6085,1);}; if (ticks>10) {ticks=0;}; }else { gvarset(6085,0);portclr(0); }; }while(1); exit(99); };