3 * Using the Quick 2 wire 16-bit GPIO expansion board to output
6 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
7 ***********************************************************************
8 * This file is part of wiringPi:
9 * https://projects.drogon.net/raspberry-pi/wiringpi/
11 * wiringPi is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * wiringPi is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
23 ***********************************************************************
36 // Enable the on-goard GPIO
40 // Add in the mcp23017 on the q2w board
42 mcp23017Setup (Q2W_BASE, 0x20) ;
44 printf ("Raspberry Pi - quite2Wire MCP23017 Test\n") ;
46 // On-board button Input:
50 // First 10 pins on q2w board as outputs:
52 for (i = 0 ; i < 10 ; ++i)
53 pinMode (Q2W_BASE + i, OUTPUT) ;
55 // Last pin as an input with the internal pull-up enabled
57 pinMode (Q2W_BASE + 15, INPUT) ;
58 pullUpDnControl (Q2W_BASE + 15, PUD_UP) ;
60 // Loop, outputting a binary number,
61 // Go faster with the button, or stop if the
62 // on-board button is pushed
66 for (i = 0 ; i < 1024 ; ++i)
68 for (bit = 0 ; bit < 10 ; ++bit)
69 digitalWrite (Q2W_BASE + bit, i & (1 << bit)) ;
71 while (digitalRead (0) == HIGH) // While pushed
74 if (digitalRead (Q2W_BASE + 15) == HIGH) // Not Pushed