//////////////////////////////////////////////////////////////////////////// // counter.cc // // Paul McCartney, Winter 1995 // // Copyright 1995, Washington University Computer Science Department // All Rights Reserved // // RCS: $Id: framegen.cc,v 1.1 1995/10/27 22:38:34 paul Exp paul $ // // This module is a counter, incrementing an integer value within // a range, at a certain rate. When the maximum value is reached, // the counter is reset to the minimum value. // // PLAYGROUND VARIABLES: // // num (output) - current counter value // rate (input) - rate at which to count, i.e. number of frames per second // min (input) - minimum value // max (input) - maximum value //////////////////////////////////////////////////////////////////////////// #include "PG.hh" PGint num = 0; PGint rate = 4; PGint min = 0; PGint max = 31; int main() { PG::initialize("Counter"); num.publish("num", PG::READ); rate.publish("f/sec", PG::WRITE); min.publish("min", PG::WRITE); max.publish("max", PG::WRITE); while (1) { if (num < max) { num = num + 1; } else { num = min; } if (rate > 1) { PG::sleep(0, (int)(1000 / rate)); } else if (rate == 1) { PG::sleep(1); } while (rate == 0) { PG::sleep(1); } } PG::terminate(); return 0; }