/* square wave beeper for loudspeaker attached to LED usleep has a minimum delay that is too long - so simple FOR loops are used tested with LED 0, the power led - this one is earthed - connect an amplifier to the positive end of the diode */ #include #include #include #include #include #include int main(int argc, char** argv) { int led_fd = 0; int f_status = 1; int i; int j; int led_nr; int ontime; /* these are microseconds */ int offtime; int loops; int count; /* this counts up to value of loops*/ int k; /* for the delay loops - usleep has a minimum delay! */ if (argc != 5) { printf("Error. usage: %s lednumber ontime offtime loops\n", argv[0]); f_status = 0; } /* led_nr is the first number after the program name */ led_nr = atoi(argv[1]); /* set the pulse on time (ontime)*/ ontime = atoi(argv[2]); /* set the base line off time (offtime)*/ offtime = atoi(argv[3]); /* set the total number of pulses to be output within the beep */ loops = atoi(argv[4]); for (count = 1;count <= loops;count = count + 1) { led_fd = open("/dev/gpio0",O_RDWR); if (led_fd == -1) { printf("fopen failed, errno %d\n", errno); f_status = 0; } if (f_status) { /* positive pulse */ ioctl(led_fd, 0, led_nr); for (k = 1;k <= ontime;k = k + 1) { /* put something here to take time? */ } /* zero volts time */ ioctl(led_fd, 1, led_nr); for (k = 1;k <= offtime;k = k + 1) { /* put something here to take time? */ } close (led_fd); } } return 0; }