Beispiel #1
0
int main (void)
{
  int pin ;
  int dataPtr ;
  int l, s, d ;

  printf ("Raspberry Pi - 6-LED Sequence\n") ;
  printf ("=============================\n") ;
  printf ("\n") ;
  printf ("  Use the 2 buttons to temporarily speed up the sequence\n") ;

  wiringPiSetupSys  () ;	// Not using the Pi's GPIO here
  drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ;

  for (pin = 0 ; pin < 6 ; ++pin)
    pinMode (pinMap [pin], OUTPUT) ;

  pinMode (GERT_BASE + 16, INPUT) ;	// Buttons
  pinMode (GERT_BASE + 17, INPUT) ;

  pullUpDnControl (GERT_BASE + 16, PUD_UP) ;
  pullUpDnControl (GERT_BASE + 17, PUD_UP) ;

  dataPtr = 0 ;

  for (;;)
  {
    l = data [dataPtr++] ;	// LED
    s = data [dataPtr++] ;	// State
    d = data [dataPtr++] ;	// Duration (10ths)

    if (s == 9)			// 9 -> End Marker
    {
      dataPtr = 0 ;
      continue ;
    }

    digitalWrite (pinMap [l], s) ;
    delay        (d * digitalRead (GERT_BASE + 16) * 15 + digitalRead (GERT_BASE + 17) * 20) ;
  }

  return 0 ;
}
Beispiel #2
0
int main (void)
{
    int pin ;
    int dataPtr ;
    int l, s, d ;

    printf ("Raspberry Pi - 12-LED Sequence\n") ;
    printf ("==============================\n") ;
    printf ("\n") ;
    printf ("Connect LEDs up to the first 4 Pi pins and 8 pins on the ATmega\n") ;
    printf ("    from PD2 through PB1 in that order,\n") ;
    printf ("  then sit back and watch the show!\n") ;

    wiringPiSetup  () ;
    drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ;

    for (pin = 0 ; pin < 12 ; ++pin)
        pinMode (pinMap [pin], OUTPUT) ;

    dataPtr = 0 ;

    for (;;)
    {
        l = data [dataPtr++] ;	// LED
        s = data [dataPtr++] ;	// State
        d = data [dataPtr++] ;	// Duration (10ths)

        if (s == 9)			// 9 -> End Marker
        {
            dataPtr = 0 ;
            continue ;
        }

        digitalWrite (pinMap [l], s) ;
        delay        (d * analogRead (GERT_BASE) / 4) ;
    }

    return 0 ;
}
Beispiel #3
0
static int doExtensionDrcS (char *progName, int pinBase, char *params)
{
  char *port ;
  int pins, baud ;

  if ((params = extractInt (progName, params, &pins)) == NULL)
    return FALSE ;

  if ((pins < 1) || (pins > 1000))
  {
    verbError ("%s: pins (%d) out of range (2-1000)", progName, pins) ;
    return FALSE ;
  }
  
  if ((params = extractStr (progName, params, &port)) == NULL)
    return FALSE ;

  if (strlen (port) == 0)
  {
    verbError ("%s: serial port device name required", progName) ;
    return FALSE ;
  }

  if ((params = extractInt (progName, params, &baud)) == NULL)
    return FALSE ;

  if ((baud < 1) || (baud > 4000000))
  {
    verbError ("%s: baud rate (%d) out of range", progName, baud) ;
    return FALSE ;
  }

  drcSetupSerial (pinBase, pins, port, baud) ;

  return TRUE ;
}