Statistics
| Branch: | Revision:

ddr4s / fw / wiringPi / examples / blink6drcs.c @ 32:cadb9025f1e0

History | View | Annotate | Download (2.85 KB)

1
/*
2
 * blink6drcs.c:
3
 *        Simple sequence over 6 pins on a remote DRC board.
4
 *        Aimed at the Gertduino, but it's fairly generic.
5
 *        This version uses DRC to talk to the ATmega on the Gertduino
6
 *
7
 * Copyright (c) 2012-2014 Gordon Henderson. <projects@drogon.net>
8
 ***********************************************************************
9
 * This file is part of wiringPi:
10
 *        https://projects.drogon.net/raspberry-pi/wiringpi/
11
 *
12
 *    wiringPi is free software: you can redistribute it and/or modify
13
 *    it under the terms of the GNU Lesser General Public License as published by
14
 *    the Free Software Foundation, either version 3 of the License, or
15
 *    (at your option) any later version.
16
 *
17
 *    wiringPi is distributed in the hope that it will be useful,
18
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 *    GNU Lesser General Public License for more details.
21
 *
22
 *    You should have received a copy of the GNU Lesser General Public License
23
 *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
24
 ***********************************************************************
25
 */
26

    
27
#include <stdio.h>
28
#include <wiringPi.h>
29
#include <drcSerial.h>
30

    
31
#define        GERT_BASE        100
32

    
33
static int pinMap [] =
34
{
35
  GERT_BASE + 6, GERT_BASE + 5, GERT_BASE + 3, GERT_BASE + 10, GERT_BASE + 9, GERT_BASE + 13,
36
} ;
37

    
38
// Simple sequencer data
39
//        Triplets of LED, On/Off and delay
40

    
41

    
42
int data [] =
43
{
44
               0, 1, 1,
45
               1, 1, 1,
46
   0, 0, 0,    2, 1, 1,
47
   1, 0, 0,    3, 1, 1,
48
   2, 0, 0,    4, 1, 1,
49
   3, 0, 0,    5, 1, 1,
50
   4, 0, 1,
51
   5, 0, 1,
52

    
53
   0, 0, 1,        // Extra delay
54

    
55
// Back again
56

    
57
               5, 1, 1,
58
               4, 1, 1,
59
   5, 0, 0,    3, 1, 1,
60
   4, 0, 0,    2, 1, 1,
61
   3, 0, 0,    1, 1, 1,
62
   2, 0, 0,    0, 1, 1,
63
   1, 0, 1,
64
   0, 0, 1,
65

    
66
   0, 0, 1,        // Extra delay
67

    
68
   0, 9, 0,        // End marker
69

    
70
} ;
71

    
72

    
73
int main (void)
74
{
75
  int pin ;
76
  int dataPtr ;
77
  int l, s, d ;
78

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

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

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

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

    
93
  pullUpDnControl (GERT_BASE + 16, PUD_UP) ;
94
  pullUpDnControl (GERT_BASE + 17, PUD_UP) ;
95

    
96
  dataPtr = 0 ;
97

    
98
  for (;;)
99
  {
100
    l = data [dataPtr++] ;        // LED
101
    s = data [dataPtr++] ;        // State
102
    d = data [dataPtr++] ;        // Duration (10ths)
103

    
104
    if (s == 9)                        // 9 -> End Marker
105
    {
106
      dataPtr = 0 ;
107
      continue ;
108
    }
109

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

    
114
  return 0 ;
115
}