Ejemplo n.º 1
0
static void doGbr (int argc, char *argv [])
{
  int channel ;

  if (argc != 3)
  {
    fprintf (stderr, "Usage: %s gbr <channel>\n", argv [0]) ;
    exit (1) ;
  }

  channel = atoi (argv [2]) ;

  if ((channel < 0) || (channel > 1))
  {
    fprintf (stderr, "%s: gbr: Channel number must be 0 or 1\n", argv [0]) ;
    exit (1) ;
  }

  if (gertboardAnalogSetup (64) < 0)
  {
    fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
    exit (1) ;
  }

  printf ("%d\n", analogRead (64 + channel)) ;
}
Ejemplo n.º 2
0
static void doGbw (int argc, char *argv [])
{
  int channel, value ;

  if (argc != 4)
  {
    fprintf (stderr, "Usage: %s gbw <channel> <value>\n", argv [0]) ;
    exit (1) ;
  }

  channel = atoi (argv [2]) ;
  value   = atoi (argv [3]) ;

  if ((channel < 0) || (channel > 1))
  {
    fprintf (stderr, "%s: gbw: Channel number must be 0 or 1\n", argv [0]) ;
    exit (1) ;
  }

  if ((value < 0) || (value > 255))
  {
    fprintf (stderr, "%s: gbw: Value must be from 0 to 255\n", argv [0]) ;
    exit (1) ;
  }

  if (gertboardAnalogSetup (64) < 0)
  {
    fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
    exit (1) ;
  }

  analogWrite (64 + channel, value) ;
}
Ejemplo n.º 3
0
int main ()
{
    int x1, x2 ;
    double v1, v2 ;

    printf ("\n") ;
    printf ("Gertboard demo: Simple Voltmeters\n") ;
    printf ("=================================\n") ;

    // Always initialise wiringPi. Use wiringPiSys() if you don't need
    //	(or want) to run as root

    wiringPiSetupSys () ;

    // Initialise the Gertboard analog hardware at pin 100

    gertboardAnalogSetup (100) ;

    printf ("\n") ;
    printf ("| Channel 0 | Channel 1 |\n") ;

    for (;;)
    {

        // Read the 2 channels:

        x1 = analogRead (100) ;
        x2 = analogRead (101) ;

        // Convert to a voltage:

        v1 = (double)x1 / 1023.0 * 3.3 ;
        v2 = (double)x2 / 1023.0 * 3.3 ;

        // Print

        printf ("|    %6.3f |    %6.3f |\r", v1, v2) ;
        fflush (stdout) ;
    }

    return 0 ;
}