Deokgyu Yang | 2c7e86b | 2020-04-28 10:56:11 +0900 | [diff] [blame] | 1 | /* |
| 2 | * blink12drcs.c: |
| 3 | * Simple sequence over the first 12 GPIO pins - LEDs |
| 4 | * Aimed at the Gertboard, but it's fairly generic. |
| 5 | * This version uses DRC totalk to the ATmega on the Gertboard |
| 6 | * |
| 7 | * Copyright (c) 2012-2013 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 | 0, 1, 2, 3, // Pi Native |
| 36 | GERT_BASE + 2, GERT_BASE + 3, GERT_BASE + 4, GERT_BASE + 5, |
| 37 | GERT_BASE + 6, GERT_BASE + 7, GERT_BASE + 8, GERT_BASE + 9, |
| 38 | } ; |
| 39 | |
| 40 | // Simple sequencer data |
| 41 | // Triplets of LED, On/Off and delay |
| 42 | |
| 43 | |
| 44 | int data [] = |
| 45 | { |
| 46 | 0, 1, 1, |
| 47 | 1, 1, 1, |
| 48 | 0, 0, 0, 2, 1, 1, |
| 49 | 1, 0, 0, 3, 1, 1, |
| 50 | 2, 0, 0, 4, 1, 1, |
| 51 | 3, 0, 0, 5, 1, 1, |
| 52 | 4, 0, 0, 6, 1, 1, |
| 53 | 5, 0, 0, 7, 1, 1, |
| 54 | 6, 0, 0, 8, 1, 1, |
| 55 | 7, 0, 0, 9, 1, 1, |
| 56 | 8, 0, 0, 10, 1, 1, |
| 57 | 9, 0, 0, 11, 1, 1, |
| 58 | 10, 0, 1, |
| 59 | 11, 0, 1, |
| 60 | |
| 61 | 0, 0, 1, // Extra delay |
| 62 | |
| 63 | // Back again |
| 64 | |
| 65 | 11, 1, 1, |
| 66 | 10, 1, 1, |
| 67 | 11, 0, 0, 9, 1, 1, |
| 68 | 10, 0, 0, 8, 1, 1, |
| 69 | 9, 0, 0, 7, 1, 1, |
| 70 | 8, 0, 0, 6, 1, 1, |
| 71 | 7, 0, 0, 5, 1, 1, |
| 72 | 6, 0, 0, 4, 1, 1, |
| 73 | 5, 0, 0, 3, 1, 1, |
| 74 | 4, 0, 0, 2, 1, 1, |
| 75 | 3, 0, 0, 1, 1, 1, |
| 76 | 2, 0, 0, 0, 1, 1, |
| 77 | 1, 0, 1, |
| 78 | 0, 0, 1, |
| 79 | |
| 80 | 0, 0, 1, // Extra delay |
| 81 | |
| 82 | 0, 9, 0, // End marker |
| 83 | |
| 84 | } ; |
| 85 | |
| 86 | |
| 87 | int main (void) |
| 88 | { |
| 89 | int pin ; |
| 90 | int dataPtr ; |
| 91 | int l, s, d ; |
| 92 | |
| 93 | printf ("Raspberry Pi - 12-LED Sequence\n") ; |
| 94 | printf ("==============================\n") ; |
| 95 | printf ("\n") ; |
| 96 | printf ("Connect LEDs up to the first 4 Pi pins and 8 pins on the ATmega\n") ; |
| 97 | printf (" from PD2 through PB1 in that order,\n") ; |
| 98 | printf (" then sit back and watch the show!\n") ; |
| 99 | |
| 100 | wiringPiSetup () ; |
| 101 | drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ; |
| 102 | |
| 103 | for (pin = 0 ; pin < 12 ; ++pin) |
| 104 | pinMode (pinMap [pin], OUTPUT) ; |
| 105 | |
| 106 | dataPtr = 0 ; |
| 107 | |
| 108 | for (;;) |
| 109 | { |
| 110 | l = data [dataPtr++] ; // LED |
| 111 | s = data [dataPtr++] ; // State |
| 112 | d = data [dataPtr++] ; // Duration (10ths) |
| 113 | |
| 114 | if (s == 9) // 9 -> End Marker |
| 115 | { |
| 116 | dataPtr = 0 ; |
| 117 | continue ; |
| 118 | } |
| 119 | |
| 120 | digitalWrite (pinMap [l], s) ; |
| 121 | delay (d * analogRead (GERT_BASE) / 4) ; |
| 122 | } |
| 123 | |
| 124 | return 0 ; |
| 125 | } |