int main(void) { uint8_t n; unsigned long int nval; TCCR0B = (1<<CS01); // /8 prescaler TIMSK = (1<<TOIE0); // enable interrupt on TOF PORT_LEDS = PORT_LEDS & ~MASK_LEDS; // turn off all LEDs DDR_LEDS = DDR_LEDS | MASK_LEDS; // make all LED drive lines outputs for (n=0; n<NUM_LEDS; n++) { bright[n] = 0; // start with all brightness values at 0 assignpwm(n); // make it so delays[n] = 200; // start with an arbitray delay value } sei(); // turn on interrupts while (1) // main loop { for (n=0; n<NUM_LEDS; n++) // for each LED { if (readtics(n) == 0) // if done with current delay for this LED... { nval = rnd(20) + 11; bright[n] = nval & 0xff; // update the brightness assignpwm(n); nval = rnd(750) + 250; // calc a random delay writetics(n, nval & 0xffff); } } } return 0; }
int gr_init(double *xlims, double *ylims, /* The size of the screen. */ char *xname, char *plotname, /* What to label things. */ char *hcopy, /* The raster file. */ int nplots, /* How many plots there will be. */ double xdelta, double ydelta, /* Line increments for the scale. */ GRIDTYPE gridtype, /* The grid type */ PLOTTYPE plottype, /* and the plot type. */ char *xlabel, char *ylabel, /* Labels for axes. */ int xtype, int ytype, /* The types of the data graphed. */ char *pname, char *commandline) /* For xi_zoomdata() */ { GRAPH *graph; wordlist *wl; char *comb_title; NG_IGNORE(nplots); if ((graph = NewGraph()) == NULL) return (FALSE); /* The global currentgraph will always be the current graph. */ SetGraphContext(graph->graphid); graph->onevalue = (xname ? FALSE : TRUE); /* communicate filename to plot 5 driver */ if (hcopy) graph->devdep = hcopy; cur.plotno = 0; /* note: should do only once, maybe in gr_init_once */ if (!cp_getvar("pointchars", CP_STRING, pointchars, sizeof(pointchars))) (void) strcpy(pointchars, DEFPOINTCHARS); if (!cp_getvar("ticmarks", CP_NUM, &graph->ticmarks, 0)) { if (cp_getvar("ticmarks", CP_BOOL, NULL, 0)) graph->ticmarks = 10; else graph->ticmarks = 0; } if (cp_getvar("ticlist", CP_LIST, ticlist, 0)) { wl = vareval("ticlist"); ticlist = wl_flatten(wl); graph->ticdata = readtics(ticlist); } else { graph->ticdata = NULL; } if (!xlims || !ylims) { internalerror("gr_init: no range specified"); return (FALSE); } /* save upper and lower limits */ graph->data.xmin = xlims[0]; graph->data.xmax = xlims[1]; graph->data.ymin = ylims[0]; graph->data.ymax = ylims[1]; /* get title into plot window */ if (!pname) pname = "(unknown)"; if (!plotname) plotname = "(unknown)"; comb_title = tprintf("%s: %s", pname, plotname); graph->plotname = comb_title; /* note: have enum here or some better convention */ if (NewViewport(graph) == 1) { /* note: where is the error message generated? */ /* note: undo tmallocs */ fprintf(cp_err, "Can't open viewport for graphics.\n"); return (FALSE); } /* layout decisions */ /* note: have to do before gr_fixgrid and after NewViewport */ graph->viewportxoff = graph->fontwidth * 8; /* 8 lines on left */ graph->viewportyoff = graph->fontheight * 4; /* 4 on bottom */ DevClear(); graph->grid.gridtype = gridtype; graph->plottype = plottype; graph->grid.xdatatype = xtype; graph->grid.ydatatype = ytype; graph->grid.xdelta = xdelta; graph->grid.ydelta = ydelta; graph->grid.ysized = 0; graph->grid.xsized = 0; if (!graph->onevalue) { if (xlabel) graph->grid.xlabel = xlabel; else graph->grid.xlabel = xname; if (ylabel) graph->grid.ylabel = ylabel; } else { if (xlabel) graph->grid.xlabel = xlabel; else graph->grid.xlabel = "real"; if (ylabel) graph->grid.ylabel = ylabel; else graph->grid.ylabel = "imag"; } gr_resize_internal(graph); gr_redrawgrid(graph); /* Set up colors and line styles. */ if (dispdev->numlinestyles == 1) cur.linestyle = 0; /* Use the same one all the time. */ else cur.linestyle = 1; /* XXX Special exception for SMITH */ if (dispdev->numcolors > 2 && (graph->grid.gridtype == GRID_SMITH || graph->grid.gridtype == GRID_SMITHGRID)) { cur.color = 3; } else { cur.color = 1; } graph->commandline = copy(commandline); return (TRUE); }