3 * Record some audio via the Gertboard
5 * Copyright (c) 2013 Gordon Henderson
6 ***********************************************************************
13 #include <gertboard.h>
20 struct timeval tStart, tEnd, tTaken ;
21 unsigned char buffer [B_SIZE] ;
24 printf ("Gertboard demo: Recorder\n") ;
25 printf ("========================\n") ;
27 // Always initialise wiringPi. Use wiringPiSys() if you don't need
28 // (or want) to run as root
32 // Initialise the Gertboard analog hardware at pin 100
34 gertboardAnalogSetup (100) ;
36 gettimeofday (&tStart, NULL) ;
38 for (i = 0 ; i < B_SIZE ; ++i)
39 buffer [i] = analogRead (100) >> 2 ;
41 gettimeofday (&tEnd, NULL) ;
43 timersub (&tEnd, &tStart, &tTaken) ;
45 printf ("Time taken for %d reads: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;
47 gettimeofday (&tStart, NULL) ;
49 for (i = 0 ; i < B_SIZE ; ++i)
50 analogWrite (100, buffer [i]) ;
52 gettimeofday (&tEnd, NULL) ;
54 timersub (&tEnd, &tStart, &tTaken) ;
56 printf ("Time taken for %d writes: %ld.%ld\n", B_SIZE, tTaken.tv_sec, tTaken.tv_usec) ;