Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #include <assert.h>
- /*
- Compile this with "gcc M102.c -o M102" to build an M102 executable
- program in the emc/programs/ directory. M102 in your G code program
- will execute this code, passing the P and Q variables as command
- line arguments.
- */
- #define SCALEFACTOR1 2.5
- #define SCALEFACTOR2 2.5
- int main(int argc, char *argv[])
- {
- double p = 0.0, q = 0.0;
- /* process the P and Q command line args we will be given */
- if (argc > 1) {
- sscanf(argv[1], "%lf", &p);
- }
- if (argc > 2) {
- sscanf(argv[2], "%lf", &q);
- }
- assert(0 <= p && p <= 1);
- int usec_white = (int) (p * SCALEFACTOR1 * 1000000);
- int usec_black = (int) ((1 - p) * SCALEFACTOR2 * 1000000);
- /*
- printf("%d w\n", usec_w);
- printf("%d b\n", usec_b);
- */
- if(usec_w > 0)
- printf("M64 P0\n"); // enable w dispenser
- if(usec_black > 0)
- printf("M64 P1\n"); // enable b dispenser
- if(usec_white < usec_b) {
- usleep(usec_w);
- printf("M65 P0\n");
- usleep(usec_b - usec_w);
- printf("M65 P1\n");
- } else {
- usleep(usec_b);
- printf("M65 P1\n");
- usleep(usec_w - usec_b);
- printf("M65 P0\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement