Initial Commit from upstream - v1.4

This commit is contained in:
Will Bradley 2019-07-04 09:23:44 -07:00
commit 833823dbeb
30 changed files with 5391 additions and 0 deletions

File diff suppressed because it is too large Load Diff

22
README.txt Normal file
View File

@ -0,0 +1,22 @@
Instructions:
1. Place the .ino and .h files in a directory under your Arduino sketeches folder named "Open_Access_Control_v4_std" .
2. Place the remaining directories in your Arduino libraries area (usually C:\Program Files (x86)\Arduino\libraries for Windows)
3. Restart the Arduino software if libraries were just added.
4. Connect up the Open Access v4. Allow the system to detect the USB/Serial port. Select "Arduino Duemillanove" from the
list of boards.
5. Change the privilege password in user.h and check other settings as needed.
6. Compile and upload the program.
Changes:
10/15/2013 (Version 1.40)
Ported libraries to work on Arduino Software 1.5 and higher
Removed "Superuser" functions
Removed unused test cases from reader function to save memory.
10/23/2013 (Version 1.36)
Updated the lockall() function to fix bug when relocking all doors (I/O pins high instead of low)
Updated reader code to allow user to define whether or not a reader has a keypad from user.h file
Updated superuser code to disable superusers by default.

View File

@ -0,0 +1,230 @@
/***************************************************
This is a library for the MCP23017 i2c port expander
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include <avr/pgmspace.h>
#include "Adafruit_MCP23017.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
// minihelper
static inline void wiresend(uint8_t x) {
#if ARDUINO >= 100
Wire.write((uint8_t)x);
#else
Wire.send(x);
#endif
}
static inline uint8_t wirerecv(void) {
#if ARDUINO >= 100
return Wire.read();
#else
return Wire.receive();
#endif
}
////////////////////////////////////////////////////////////////////////////////
void Adafruit_MCP23017::begin(uint8_t addr) {
if (addr > 7) {
addr = 7;
}
i2caddr = addr;
Wire.begin();
// set defaults!
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(MCP23017_IODIRA);
wiresend(0xFF); // all inputs on port A
Wire.endTransmission();
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(MCP23017_IODIRB);
wiresend(0xFF); // all inputs on port B
Wire.endTransmission();
}
void Adafruit_MCP23017::begin(void) {
begin(0);
}
void Adafruit_MCP23017::pinMode(uint8_t p, uint8_t d) {
uint8_t iodir;
uint8_t iodiraddr;
// only 16 bits!
if (p > 15)
return;
if (p < 8)
iodiraddr = MCP23017_IODIRA;
else {
iodiraddr = MCP23017_IODIRB;
p -= 8;
}
// read the current IODIR
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(iodiraddr);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 1);
iodir = wirerecv();
// set the pin and direction
if (d == INPUT) {
iodir |= 1 << p;
} else {
iodir &= ~(1 << p);
}
// write the new IODIR
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(iodiraddr);
wiresend(iodir);
Wire.endTransmission();
}
uint16_t Adafruit_MCP23017::readGPIOAB() {
uint16_t ba = 0;
uint8_t a;
// read the current GPIO output latches
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(MCP23017_GPIOA);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 2);
a = wirerecv();
ba = wirerecv();
ba <<= 8;
ba |= a;
return ba;
}
void Adafruit_MCP23017::writeGPIOAB(uint16_t ba) {
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(MCP23017_GPIOA);
wiresend(ba & 0xFF);
wiresend(ba >> 8);
Wire.endTransmission();
}
void Adafruit_MCP23017::digitalWrite(uint8_t p, uint8_t d) {
uint8_t gpio;
uint8_t gpioaddr, olataddr;
// only 16 bits!
if (p > 15)
return;
if (p < 8) {
olataddr = MCP23017_OLATA;
gpioaddr = MCP23017_GPIOA;
} else {
olataddr = MCP23017_OLATB;
gpioaddr = MCP23017_GPIOB;
p -= 8;
}
// read the current GPIO output latches
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(olataddr);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 1);
gpio = wirerecv();
// set the pin and direction
if (d == HIGH) {
gpio |= 1 << p;
} else {
gpio &= ~(1 << p);
}
// write the new GPIO
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(gpioaddr);
wiresend(gpio);
Wire.endTransmission();
}
void Adafruit_MCP23017::pullUp(uint8_t p, uint8_t d) {
uint8_t gppu;
uint8_t gppuaddr;
// only 16 bits!
if (p > 15)
return;
if (p < 8)
gppuaddr = MCP23017_GPPUA;
else {
gppuaddr = MCP23017_GPPUB;
p -= 8;
}
// read the current pullup resistor set
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(gppuaddr);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 1);
gppu = wirerecv();
// set the pin and direction
if (d == HIGH) {
gppu |= 1 << p;
} else {
gppu &= ~(1 << p);
}
// write the new GPIO
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(gppuaddr);
wiresend(gppu);
Wire.endTransmission();
}
uint8_t Adafruit_MCP23017::digitalRead(uint8_t p) {
uint8_t gpioaddr;
// only 16 bits!
if (p > 15)
return 0;
if (p < 8)
gpioaddr = MCP23017_GPIOA;
else {
gpioaddr = MCP23017_GPIOB;
p -= 8;
}
// read the current GPIO
Wire.beginTransmission(MCP23017_ADDRESS | i2caddr);
wiresend(gpioaddr);
Wire.endTransmission();
Wire.requestFrom(MCP23017_ADDRESS | i2caddr, 1);
return (wirerecv() >> p) & 0x1;
}

View File

@ -0,0 +1,63 @@
/***************************************************
This is a library for the MCP23017 i2c port expander
These displays use I2C to communicate, 2 pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#ifndef _Adafruit_MCP23017_H_
#define _Adafruit_MCP23017_H_
// Don't forget the Wire library
class Adafruit_MCP23017 {
public:
void begin(uint8_t addr);
void begin(void);
void pinMode(uint8_t p, uint8_t d);
void digitalWrite(uint8_t p, uint8_t d);
void pullUp(uint8_t p, uint8_t d);
uint8_t digitalRead(uint8_t p);
void writeGPIOAB(uint16_t);
uint16_t readGPIOAB();
private:
uint8_t i2caddr;
};
#define MCP23017_ADDRESS 0x20
// registers
#define MCP23017_IODIRA 0x00
#define MCP23017_IPOLA 0x02
#define MCP23017_GPINTENA 0x04
#define MCP23017_DEFVALA 0x06
#define MCP23017_INTCONA 0x08
#define MCP23017_IOCONA 0x0A
#define MCP23017_GPPUA 0x0C
#define MCP23017_INTFA 0x0E
#define MCP23017_INTCAPA 0x10
#define MCP23017_GPIOA 0x12
#define MCP23017_OLATA 0x14
#define MCP23017_IODIRB 0x01
#define MCP23017_IPOLB 0x03
#define MCP23017_GPINTENB 0x05
#define MCP23017_DEFVALB 0x07
#define MCP23017_INTCONB 0x09
#define MCP23017_IOCONB 0x0B
#define MCP23017_GPPUB 0x0D
#define MCP23017_INTFB 0x0F
#define MCP23017_INTCAPB 0x11
#define MCP23017_GPIOB 0x13
#define MCP23017_OLATB 0x15
#endif

View File

@ -0,0 +1,15 @@
This is a library for the MCP23017 I2c Port Expander
These chips use I2C to communicate, 2 pins required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_MCP23017. Check that the Adafruit_MCP23017 folder contains Adafruit_MCP23017.cpp and Adafruit_MCP23017.h
Place the Adafruit_MCP23017 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

View File

@ -0,0 +1,800 @@
<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# githubog: http://ogp.me/ns/fb/githubog#">
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Adafruit-MCP23017-Arduino-Library/examples/button/button.pde at 17ab72f32b9128e00a21bac6c2b95d10681b1b39 · adafruit/Adafruit-MCP23017-Arduino-Library · GitHub</title>
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub" />
<link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta content="authenticity_token" name="csrf-param" />
<meta content="20oxv6eC4aSobAuC3hsjpq59jHVUWctdH3mtP82iLP0=" name="csrf-token" />
<link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-155c2209391eb161778b9fc77d8611dd195aec97.css" media="screen" rel="stylesheet" type="text/css" />
<link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github2-aba0359243b65d422540acc0425402ad487a2acd.css" media="screen" rel="stylesheet" type="text/css" />
<script src="https://a248.e.akamai.net/assets.github.com/javascripts/bundles/frameworks-e417ea70cc7daa9aad62382cb6b5d0c94acfb8f4.js" type="text/javascript"></script>
<script defer="defer" src="https://a248.e.akamai.net/assets.github.com/javascripts/bundles/github-51a20e4f1a41a77997473c2a54c4d4cc374d5e59.js" type="text/javascript"></script>
<link rel='permalink' href='/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/button/button.pde'>
<meta property="og:title" content="Adafruit-MCP23017-Arduino-Library"/>
<meta property="og:type" content="githubog:gitrepository"/>
<meta property="og:url" content="https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library"/>
<meta property="og:image" content="https://a248.e.akamai.net/assets.github.com/images/gravatars/gravatar-140.png?1329920549"/>
<meta property="og:site_name" content="GitHub"/>
<meta property="og:description" content="Adafruit-MCP23017-Arduino-Library hosted on GitHub"/>
<meta name="description" content="Adafruit-MCP23017-Arduino-Library hosted on GitHub" />
<link href="https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/commits/17ab72f32b9128e00a21bac6c2b95d10681b1b39.atom" rel="alternate" title="Recent Commits to Adafruit-MCP23017-Arduino-Library:17ab72f32b9128e00a21bac6c2b95d10681b1b39" type="application/atom+xml" />
</head>
<body class="logged_out page-blob windows vis-public env-production " data-blob-contribs-enabled="yes">
<div id="wrapper">
<div id="header" class="true clearfix">
<div class="container clearfix">
<a class="site-logo" href="https://github.com/">
<!--[if IE]>
<img alt="GitHub" class="github-logo" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7.png?1329920549" />
<img alt="GitHub" class="github-logo-hover" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7-hover.png?1329920549" />
<![endif]-->
<img alt="GitHub" class="github-logo-4x" height="30" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x.png?1337118065" />
<img alt="GitHub" class="github-logo-4x-hover" height="30" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x-hover.png?1337118065" />
</a>
<!--
make sure to use fully qualified URLs here since this nav
is used on error pages on other domains
-->
<ul class="top-nav logged_out">
<li class="pricing"><a href="https://github.com/plans">Signup and Pricing</a></li>
<li class="explore"><a href="https://github.com/explore">Explore GitHub</a></li>
<li class="features"><a href="https://github.com/features">Features</a></li>
<li class="blog"><a href="https://github.com/blog">Blog</a></li>
<li class="login"><a href="https://github.com/login?return_to=%2Fadafruit%2FAdafruit-MCP23017-Arduino-Library%2Fblob%2F17ab72f32b9128e00a21bac6c2b95d10681b1b39%2Fexamples%2Fbutton%2Fbutton.pde">Login</a></li>
</ul>
</div>
</div>
<div class="site hfeed" itemscope itemtype="http://schema.org/WebPage">
<div class="container hentry">
<div class="pagehead repohead instapaper_ignore readability-menu">
<div class="title-actions-bar">
<ul class="pagehead-actions">
<li>
<span class="watch-button"><a href="/login?return_to=%2Fadafruit%2FAdafruit-MCP23017-Arduino-Library" class="minibutton btn-watch js-toggler-target entice tooltipped leftwards" title="You must be logged in to use this feature" rel="nofollow"><span><span class="icon"></span> Watch</span></a><a class="social-count js-social-count" href="/adafruit/Adafruit-MCP23017-Arduino-Library/watchers">5</a></span>
</li>
<li>
<a href="/login?return_to=%2Fadafruit%2FAdafruit-MCP23017-Arduino-Library" class="minibutton btn-fork js-toggler-target fork-button entice tooltipped leftwards" title="You must be logged in to use this feature" rel="nofollow"><span><span class="icon"></span>Fork</span></a><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/network" class="social-count">2</a>
</li>
</ul>
<h1 itemscope itemtype="http://data-vocabulary.org/Breadcrumb" class="entry-title">
<span class="repo-label"><span class="public">public</span></span>
<span class="mega-icon public-repo"></span>
<span class="author vcard">
<a href="/adafruit" class="url fn" itemprop="url" rel="author"> <span itemprop="title">adafruit</span>
</a></span> /
<strong><a href="/adafruit/Adafruit-MCP23017-Arduino-Library" class="js-current-repository">Adafruit-MCP23017-Arduino-Library</a></strong>
</h1>
</div>
<ul class="tabs">
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/" class="selected" highlight="repo_sourcerepo_downloadsrepo_commitsrepo_tagsrepo_branches">Code</a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/network" highlight="repo_network">Network</a>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/pulls" highlight="repo_pulls">Pull Requests <span class='counter'>0</span></a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/issues" highlight="repo_issues">Issues <span class='counter'>0</span></a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/graphs" highlight="repo_graphsrepo_contributors">Graphs</a></li>
</ul>
<div class="frame frame-center tree-finder" style="display:none"
data-tree-list-url="/adafruit/Adafruit-MCP23017-Arduino-Library/tree-list/17ab72f32b9128e00a21bac6c2b95d10681b1b39"
data-blob-url-prefix="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39"
>
<div class="breadcrumb">
<span class="bold"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library">Adafruit-MCP23017-Arduino-Library</a></span> /
<input class="tree-finder-input js-navigation-enable" type="text" name="query" autocomplete="off" spellcheck="false">
</div>
<div class="octotip">
<p>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/dismiss-tree-finder-help" class="dismiss js-dismiss-tree-list-help" title="Hide this notice forever" rel="nofollow">Dismiss</a>
<span class="bold">Octotip:</span> You've activated the <em>file finder</em>
by pressing <span class="kbd">t</span> Start typing to filter the
file list. Use <span class="kbd badmono">↑</span> and
<span class="kbd badmono">↓</span> to navigate,
<span class="kbd">enter</span> to view files.
</p>
</div>
<table class="tree-browser" cellpadding="0" cellspacing="0">
<tr class="js-header"><th>&nbsp;</th><th>name</th></tr>
<tr class="js-no-results no-results" style="display: none">
<th colspan="2">No matching files</th>
</tr>
<tbody class="js-results-list js-navigation-container">
</tbody>
</table>
</div>
<div id="jump-to-line" style="display:none">
<h2>Jump to Line</h2>
<form accept-charset="UTF-8">
<input class="textfield" type="text">
<div class="full-button">
<button type="submit" class="classy">
<span>Go</span>
</button>
</div>
</form>
</div>
<div class="subnav-bar">
<ul class="actions subnav">
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tags" class="blank" highlight="repo_tags">Tags <span class="counter">0</span></a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/downloads" class="blank downloads-blank" highlight="repo_downloads">Downloads <span class="counter">0</span></a></li>
</ul>
<ul class="scope">
<li class="switcher">
<div class="context-menu-container js-menu-container js-context-menu">
<a href="#"
class="minibutton bigger switcher js-menu-target js-commitish-button btn-tree repo-tree"
data-hotkey="w"
data-master-branch="master"
data-ref="">
<span><span class="icon"></span><i>tree:</i> 17ab72f32b</span>
</a>
<div class="context-pane commitish-context js-menu-content">
<a href="javascript:;" class="close js-menu-close"><span class="mini-icon remove-close"></span></a>
<div class="context-title">Switch Branches/Tags</div>
<div class="context-body pane-selector commitish-selector js-navigation-container">
<div class="filterbar">
<input type="text" id="context-commitish-filter-field" class="js-navigation-enable" placeholder="Filter branches/tags" data-filterable />
<ul class="tabs">
<li><a href="#" data-filter="branches" class="selected">Branches</a></li>
<li><a href="#" data-filter="tags">Tags</a></li>
</ul>
</div>
<div class="js-filter-tab js-filter-branches" data-filterable-for="context-commitish-filter-field">
<div class="no-results js-not-filterable">Nothing to show</div>
<div class="commitish-item branch-commitish selector-item js-navigation-item js-navigation-target">
<h4>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/examples/button/button.pde" class="js-navigation-open" data-name="master" rel="nofollow">master</a>
</h4>
</div>
</div>
<div class="js-filter-tab js-filter-tags" style="display:none" data-filterable-for="context-commitish-filter-field">
<div class="no-results js-not-filterable">Nothing to show</div>
</div>
</div>
</div><!-- /.commitish-context-context -->
</div>
</li>
</ul>
<ul class="subnav with-scope">
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/" class="selected" highlight="repo_source">Files</a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/commits/" highlight="repo_commits">Commits</a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/branches" class="" highlight="repo_branches" rel="nofollow">Branches <span class="counter">1</span></a></li>
</ul>
</div>
</div><!-- /.repohead -->
<!-- block_view_fragment_key: views8/v8/blob:v21:5cd9cdce42430e380a991d8081c53f3f -->
<div id="slider">
<div class="breadcrumb" data-path="examples/button/button.pde/">
<b itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/17ab72f32b9128e00a21bac6c2b95d10681b1b39" class="js-rewrite-sha" itemprop="url"><span itemprop="title">Adafruit-MCP23017-Arduino-Library</span></a></b> / <span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples" class="js-rewrite-sha" itemscope="url"><span itemprop="title">examples</span></a></span> / <span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/button" class="js-rewrite-sha" itemscope="url"><span itemprop="title">button</span></a></span> / <strong class="final-path">button.pde</strong> <span class="js-clippy mini-icon clippy " data-clipboard-text="examples/button/button.pde" data-copied-hint="copied!" data-copy-hint="copy to clipboard"></span>
</div>
<div class="commit file-history-tease" data-path="examples/button/button.pde/">
<img class="main-avatar" height="24" src="https://secure.gravatar.com/avatar/3f7ca151e1f7f7dead8b2db60aa744c1?s=140&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png" width="24" />
<span class="author"><a href="/ladyada">ladyada</a></span>
<time class="js-relative-date" datetime="2012-02-14T09:15:20-08:00" title="2012-02-14 09:15:20">February 14, 2012</time>
<div class="commit-title">
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/commit/6eb6038bd7eacf825b89383ac3d4cd047851ca2d" class="message">Examples for inputs and outputs</a>
</div>
<div class="participation">
<p class="quickstat"><a href="#blob_contributors_box" rel="facebox"><strong>1</strong> contributor</a></p>
</div>
<div id="blob_contributors_box" style="display:none">
<h2>Users on GitHub who have contributed to this file</h2>
<ul class="facebox-user-list">
<li>
<img height="24" src="https://secure.gravatar.com/avatar/3f7ca151e1f7f7dead8b2db60aa744c1?s=140&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png" width="24" />
<a href="/ladyada">ladyada</a>
</li>
</ul>
</div>
</div>
<div class="frames">
<div class="frame frame-center" data-path="examples/button/button.pde/" data-permalink-url="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/button/button.pde" data-title="Adafruit-MCP23017-Arduino-Library/examples/button/button.pde at master · adafruit/Adafruit-MCP23017-Arduino-Library · GitHub" data-type="blob">
<div id="files" class="bubble">
<div class="file">
<div class="meta">
<div class="info">
<span class="icon"><b class="mini-icon text-file"></b></span>
<span class="mode" title="File Mode">100644</span>
<span>31 lines (21 sloc)</span>
<span>0.844 kb</span>
</div>
<ul class="button-group actions">
<li>
<a class="grouped-button file-edit-link minibutton bigger lighter js-rewrite-sha" href="/adafruit/Adafruit-MCP23017-Arduino-Library/edit/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/button/button.pde" data-method="post" rel="nofollow" data-hotkey="e"><span>Edit this file</span></a>
</li>
<li>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/raw/master/examples/button/button.pde" class="minibutton btn-raw grouped-button bigger lighter" id="raw-url"><span><span class="icon"></span>Raw</span></a>
</li>
<li>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/blame/master/examples/button/button.pde" class="minibutton btn-blame grouped-button bigger lighter"><span><span class="icon"></span>Blame</span></a>
</li>
<li>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/commits/master/examples/button/button.pde" class="minibutton btn-history grouped-button bigger lighter" rel="nofollow"><span><span class="icon"></span>History</span></a>
</li>
</ul>
</div>
<div class="data type-java">
<table cellpadding="0" cellspacing="0" class="lines">
<tr>
<td>
<pre class="line_numbers"><span id="L1" rel="#L1">1</span>
<span id="L2" rel="#L2">2</span>
<span id="L3" rel="#L3">3</span>
<span id="L4" rel="#L4">4</span>
<span id="L5" rel="#L5">5</span>
<span id="L6" rel="#L6">6</span>
<span id="L7" rel="#L7">7</span>
<span id="L8" rel="#L8">8</span>
<span id="L9" rel="#L9">9</span>
<span id="L10" rel="#L10">10</span>
<span id="L11" rel="#L11">11</span>
<span id="L12" rel="#L12">12</span>
<span id="L13" rel="#L13">13</span>
<span id="L14" rel="#L14">14</span>
<span id="L15" rel="#L15">15</span>
<span id="L16" rel="#L16">16</span>
<span id="L17" rel="#L17">17</span>
<span id="L18" rel="#L18">18</span>
<span id="L19" rel="#L19">19</span>
<span id="L20" rel="#L20">20</span>
<span id="L21" rel="#L21">21</span>
<span id="L22" rel="#L22">22</span>
<span id="L23" rel="#L23">23</span>
<span id="L24" rel="#L24">24</span>
<span id="L25" rel="#L25">25</span>
<span id="L26" rel="#L26">26</span>
<span id="L27" rel="#L27">27</span>
<span id="L28" rel="#L28">28</span>
<span id="L29" rel="#L29">29</span>
<span id="L30" rel="#L30">30</span>
<span id="L31" rel="#L31">31</span>
</pre>
</td>
<td width="100%">
<div class="highlight"><pre><div class='line' id='LC1'><span class="err">#</span><span class="n">include</span> <span class="o">&lt;</span><span class="n">Wire</span><span class="o">.</span><span class="na">h</span><span class="o">&gt;</span></div><div class='line' id='LC2'><span class="err">#</span><span class="n">include</span> <span class="s">&quot;Adafruit_MCP23017.h&quot;</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="c1">// Basic pin reading and pullup test for the MCP23017 I/O expander</span></div><div class='line' id='LC5'><span class="c1">// public domain!</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'><span class="c1">// Connect pin #12 of the expander to Analog 5 (i2c clock)</span></div><div class='line' id='LC8'><span class="c1">// Connect pin #13 of the expander to Analog 4 (i2c data)</span></div><div class='line' id='LC9'><span class="c1">// Connect pins #15, 16 and 17 of the expander to ground (address selection)</span></div><div class='line' id='LC10'><span class="c1">// Connect pin #9 of the expander to 5V (power)</span></div><div class='line' id='LC11'><span class="c1">// Connect pin #10 of the expander to ground (common ground)</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'><span class="c1">// Input #0 is on pin 21 so connect a button or switch from there to ground</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'><span class="n">Adafruit_MCP23017</span> <span class="n">mcp</span><span class="o">;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;</div><div class='line' id='LC17'><span class="kt">void</span> <span class="nf">setup</span><span class="o">()</span> <span class="o">{</span> </div><div class='line' id='LC18'>&nbsp;&nbsp;<span class="n">mcp</span><span class="o">.</span><span class="na">begin</span><span class="o">();</span> <span class="c1">// use default address 0</span></div><div class='line' id='LC19'><br/></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="n">mcp</span><span class="o">.</span><span class="na">pinMode</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">INPUT</span><span class="o">);</span></div><div class='line' id='LC21'>&nbsp;&nbsp;<span class="n">mcp</span><span class="o">.</span><span class="na">pullUp</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">HIGH</span><span class="o">);</span> <span class="c1">// turn on a 100K pullup internally</span></div><div class='line' id='LC22'><br/></div><div class='line' id='LC23'>&nbsp;&nbsp;<span class="n">pinMode</span><span class="o">(</span><span class="mi">13</span><span class="o">,</span> <span class="n">OUTPUT</span><span class="o">);</span> <span class="c1">// use the p13 LED as debugging</span></div><div class='line' id='LC24'><span class="o">}</span></div><div class='line' id='LC25'><br/></div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'><br/></div><div class='line' id='LC28'><span class="kt">void</span> <span class="nf">loop</span><span class="o">()</span> <span class="o">{</span></div><div class='line' id='LC29'>&nbsp;&nbsp;<span class="c1">// The LED will &#39;echo&#39; the button</span></div><div class='line' id='LC30'>&nbsp;&nbsp;<span class="n">digitalWrite</span><span class="o">(</span><span class="mi">13</span><span class="o">,</span> <span class="n">mcp</span><span class="o">.</span><span class="na">digitalRead</span><span class="o">(</span><span class="mi">0</span><span class="o">));</span></div><div class='line' id='LC31'><span class="o">}</span></div></pre></div>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="frame frame-loading large-loading-area" style="display:none;" data-tree-list-url="/adafruit/Adafruit-MCP23017-Arduino-Library/tree-list/17ab72f32b9128e00a21bac6c2b95d10681b1b39" data-blob-url-prefix="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39">
<img src="https://a248.e.akamai.net/assets.github.com/images/spinners/octocat-spinner-64.gif?1329920549" height="64" width="64">
</div>
</div>
<div class="context-overlay"></div>
</div>
<div id="footer-push"></div><!-- hack for sticky footer -->
</div><!-- end of wrapper - hack for sticky footer -->
<!-- footer -->
<div id="footer" >
<div class="upper_footer">
<div class="container clearfix">
<!--[if IE]><h4 id="blacktocat_ie">GitHub Links</h4><![endif]-->
<![if !IE]><h4 id="blacktocat">GitHub Links</h4><![endif]>
<ul class="footer_nav">
<h4>GitHub</h4>
<li><a href="https://github.com/about">About</a></li>
<li><a href="https://github.com/blog">Blog</a></li>
<li><a href="https://github.com/features">Features</a></li>
<li><a href="https://github.com/contact">Contact &amp; Support</a></li>
<li><a href="https://github.com/training">Training</a></li>
<li><a href="http://enterprise.github.com/">GitHub Enterprise</a></li>
<li><a href="http://status.github.com/">Site Status</a></li>
</ul>
<ul class="footer_nav">
<h4>Tools</h4>
<li><a href="http://get.gaug.es/">Gauges: Analyze web traffic</a></li>
<li><a href="http://speakerdeck.com">Speaker Deck: Presentations</a></li>
<li><a href="https://gist.github.com">Gist: Code snippets</a></li>
<li><a href="http://mac.github.com/">GitHub for Mac</a></li>
<li><a href="http://mobile.github.com/">Issues for iPhone</a></li>
<li><a href="http://jobs.github.com/">Job Board</a></li>
</ul>
<ul class="footer_nav">
<h4>Extras</h4>
<li><a href="http://shop.github.com/">GitHub Shop</a></li>
<li><a href="http://octodex.github.com/">The Octodex</a></li>
</ul>
<ul class="footer_nav">
<h4>Documentation</h4>
<li><a href="http://help.github.com/">GitHub Help</a></li>
<li><a href="http://developer.github.com/">Developer API</a></li>
<li><a href="http://github.github.com/github-flavored-markdown/">GitHub Flavored Markdown</a></li>
<li><a href="http://pages.github.com/">GitHub Pages</a></li>
</ul>
</div><!-- /.site -->
</div><!-- /.upper_footer -->
<div class="lower_footer">
<div class="container clearfix">
<!--[if IE]><div id="legal_ie"><![endif]-->
<![if !IE]><div id="legal"><![endif]>
<ul>
<li><a href="https://github.com/site/terms">Terms of Service</a></li>
<li><a href="https://github.com/site/privacy">Privacy</a></li>
<li><a href="https://github.com/security">Security</a></li>
</ul>
<p>&copy; 2012 <span title="0.04830s from fe15.rs.github.com">GitHub</span> Inc. All rights reserved.</p>
</div><!-- /#legal or /#legal_ie-->
<div class="sponsor">
<a href="http://www.rackspace.com" class="logo">
<img alt="Dedicated Server" height="36" src="https://a248.e.akamai.net/assets.github.com/images/modules/footer/rackspaces_logo.png?1329920549" width="38" />
</a>
Powered by the <a href="http://www.rackspace.com ">Dedicated
Servers</a> and<br/> <a href="http://www.rackspacecloud.com">Cloud
Computing</a> of Rackspace Hosting<span>&reg;</span>
</div>
</div><!-- /.site -->
</div><!-- /.lower_footer -->
</div><!-- /#footer -->
<div id="keyboard_shortcuts_pane" class="instapaper_ignore readability-extra" style="display:none">
<h2>Keyboard Shortcuts <small><a href="#" class="js-see-all-keyboard-shortcuts">(see all)</a></small></h2>
<div class="columns threecols">
<div class="column first">
<h3>Site wide shortcuts</h3>
<dl class="keyboard-mappings">
<dt>s</dt>
<dd>Focus site search</dd>
</dl>
<dl class="keyboard-mappings">
<dt>?</dt>
<dd>Bring up this help dialog</dd>
</dl>
</div><!-- /.column.first -->
<div class="column middle" style='display:none'>
<h3>Commit list</h3>
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>c <em>or</em> o <em>or</em> enter</dt>
<dd>Open commit</dd>
</dl>
<dl class="keyboard-mappings">
<dt>y</dt>
<dd>Expand URL to its canonical form</dd>
</dl>
</div><!-- /.column.first -->
<div class="column last" style='display:none'>
<h3>Pull request list</h3>
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o <em>or</em> enter</dt>
<dd>Open issue</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="platform-mac">⌘</span><span class="platform-other">ctrl</span> <em>+</em> enter</dt>
<dd>Submit comment</dd>
</dl>
</div><!-- /.columns.last -->
</div><!-- /.columns.equacols -->
<div style='display:none'>
<div class="rule"></div>
<h3>Issues</h3>
<div class="columns threecols">
<div class="column first">
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>x</dt>
<dd>Toggle selection</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o <em>or</em> enter</dt>
<dd>Open issue</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="platform-mac">⌘</span><span class="platform-other">ctrl</span> <em>+</em> enter</dt>
<dd>Submit comment</dd>
</dl>
</div><!-- /.column.first -->
<div class="column last">
<dl class="keyboard-mappings">
<dt>c</dt>
<dd>Create issue</dd>
</dl>
<dl class="keyboard-mappings">
<dt>l</dt>
<dd>Create label</dd>
</dl>
<dl class="keyboard-mappings">
<dt>i</dt>
<dd>Back to inbox</dd>
</dl>
<dl class="keyboard-mappings">
<dt>u</dt>
<dd>Back to issues</dd>
</dl>
<dl class="keyboard-mappings">
<dt>/</dt>
<dd>Focus issues search</dd>
</dl>
</div>
</div>
</div>
<div style='display:none'>
<div class="rule"></div>
<h3>Issues Dashboard</h3>
<div class="columns threecols">
<div class="column first">
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o <em>or</em> enter</dt>
<dd>Open issue</dd>
</dl>
</div><!-- /.column.first -->
</div>
</div>
<div style='display:none'>
<div class="rule"></div>
<h3>Network Graph</h3>
<div class="columns equacols">
<div class="column first">
<dl class="keyboard-mappings">
<dt><span class="badmono">←</span> <em>or</em> h</dt>
<dd>Scroll left</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="badmono">→</span> <em>or</em> l</dt>
<dd>Scroll right</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="badmono">↑</span> <em>or</em> k</dt>
<dd>Scroll up</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="badmono">↓</span> <em>or</em> j</dt>
<dd>Scroll down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>t</dt>
<dd>Toggle visibility of head labels</dd>
</dl>
</div><!-- /.column.first -->
<div class="column last">
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">←</span> <em>or</em> shift h</dt>
<dd>Scroll all the way left</dd>
</dl>
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">→</span> <em>or</em> shift l</dt>
<dd>Scroll all the way right</dd>
</dl>
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">↑</span> <em>or</em> shift k</dt>
<dd>Scroll all the way up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">↓</span> <em>or</em> shift j</dt>
<dd>Scroll all the way down</dd>
</dl>
</div><!-- /.column.last -->
</div>
</div>
<div >
<div class="rule"></div>
<div class="columns threecols">
<div class="column first" >
<h3>Source Code Browsing</h3>
<dl class="keyboard-mappings">
<dt>t</dt>
<dd>Activates the file finder</dd>
</dl>
<dl class="keyboard-mappings">
<dt>l</dt>
<dd>Jump to line</dd>
</dl>
<dl class="keyboard-mappings">
<dt>w</dt>
<dd>Switch branch/tag</dd>
</dl>
<dl class="keyboard-mappings">
<dt>y</dt>
<dd>Expand URL to its canonical form</dd>
</dl>
</div>
</div>
</div>
<div style='display:none'>
<div class="rule"></div>
<div class="columns threecols">
<div class="column first">
<h3>Browsing Commits</h3>
<dl class="keyboard-mappings">
<dt><span class="platform-mac">⌘</span><span class="platform-other">ctrl</span> <em>+</em> enter</dt>
<dd>Submit comment</dd>
</dl>
<dl class="keyboard-mappings">
<dt>escape</dt>
<dd>Close form</dd>
</dl>
<dl class="keyboard-mappings">
<dt>p</dt>
<dd>Parent commit</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o</dt>
<dd>Other parent commit</dd>
</dl>
</div>
</div>
</div>
</div>
<div id="markdown-help" class="instapaper_ignore readability-extra">
<h2>Markdown Cheat Sheet</h2>
<div class="cheatsheet-content">
<div class="mod">
<div class="col">
<h3>Format Text</h3>
<p>Headers</p>
<pre>
# This is an &lt;h1&gt; tag
## This is an &lt;h2&gt; tag
###### This is an &lt;h6&gt; tag</pre>
<p>Text styles</p>
<pre>
*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__
*You **can** combine them*
</pre>
</div>
<div class="col">
<h3>Lists</h3>
<p>Unordered</p>
<pre>
* Item 1
* Item 2
* Item 2a
* Item 2b</pre>
<p>Ordered</p>
<pre>
1. Item 1
2. Item 2
3. Item 3
* Item 3a
* Item 3b</pre>
</div>
<div class="col">
<h3>Miscellaneous</h3>
<p>Images</p>
<pre>
![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)
</pre>
<p>Links</p>
<pre>
http://github.com - automatic!
[GitHub](http://github.com)</pre>
<p>Blockquotes</p>
<pre>
As Kanye West said:
> We're living the future so
> the present is our past.
</pre>
</div>
</div>
<div class="rule"></div>
<h3>Code Examples in Markdown</h3>
<div class="col">
<p>Syntax highlighting with <a href="http://github.github.com/github-flavored-markdown/" title="GitHub Flavored Markdown" target="_blank">GFM</a></p>
<pre>
```javascript
function fancyAlert(arg) {
if(arg) {
$.facebox({div:'#foo'})
}
}
```</pre>
</div>
<div class="col">
<p>Or, indent your code 4 spaces</p>
<pre>
Here is a Python code example
without syntax highlighting:
def foo:
if not bar:
return true</pre>
</div>
<div class="col">
<p>Inline code for comments</p>
<pre>
I think you should use an
`&lt;addr&gt;` element here instead.</pre>
</div>
</div>
</div>
</div>
<div class="ajax-error-message">
<p><span class="mini-icon exclamation"></span> Something went wrong with that request. Please try again. <a href="javascript:;" class="ajax-error-dismiss">Dismiss</a></p>
</div>
<div id="logo-popup">
<h2>Looking for the GitHub logo?</h2>
<ul>
<li>
<h4>GitHub Logo</h4>
<a href="http://github-media-downloads.s3.amazonaws.com/GitHub_Logos.zip"><img alt="Github_logo" src="https://a248.e.akamai.net/assets.github.com/images/modules/about_page/github_logo.png?1329920549" /></a>
<a href="http://github-media-downloads.s3.amazonaws.com/GitHub_Logos.zip" class="minibutton btn-download download"><span><span class="icon"></span>Download</span></a>
</li>
<li>
<h4>The Octocat</h4>
<a href="http://github-media-downloads.s3.amazonaws.com/Octocats.zip"><img alt="Octocat" src="https://a248.e.akamai.net/assets.github.com/images/modules/about_page/octocat.png?1329920549" /></a>
<a href="http://github-media-downloads.s3.amazonaws.com/Octocats.zip" class="minibutton btn-download download"><span><span class="icon"></span>Download</span></a>
</li>
</ul>
</div>
<span id='server_response_time' data-time='0.05066' data-host='fe15'></span>
</body>
</html>

View File

@ -0,0 +1,31 @@
#include <Wire.h>
#include "Adafruit_MCP23017.h"
// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!
// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Input #0 is on pin 21 so connect a button or switch from there to ground
Adafruit_MCP23017 mcp;
void setup() {
mcp.begin(); // use default address 0
mcp.pinMode(0, INPUT);
mcp.pullUp(0, HIGH); // turn on a 100K pullup internally
pinMode(13, OUTPUT); // use the p13 LED as debugging
}
void loop() {
// The LED will 'echo' the button
digitalWrite(13, mcp.digitalRead(0));
}

View File

@ -0,0 +1,803 @@
<!DOCTYPE html>
<html>
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# githubog: http://ogp.me/ns/fb/githubog#">
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Adafruit-MCP23017-Arduino-Library/examples/toggle/toggle.pde at 17ab72f32b9128e00a21bac6c2b95d10681b1b39 · adafruit/Adafruit-MCP23017-Arduino-Library · GitHub</title>
<link rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml" title="GitHub" />
<link rel="fluid-icon" href="https://github.com/fluidicon.png" title="GitHub" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta content="authenticity_token" name="csrf-param" />
<meta content="20oxv6eC4aSobAuC3hsjpq59jHVUWctdH3mtP82iLP0=" name="csrf-token" />
<link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-155c2209391eb161778b9fc77d8611dd195aec97.css" media="screen" rel="stylesheet" type="text/css" />
<link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github2-aba0359243b65d422540acc0425402ad487a2acd.css" media="screen" rel="stylesheet" type="text/css" />
<script src="https://a248.e.akamai.net/assets.github.com/javascripts/bundles/frameworks-e417ea70cc7daa9aad62382cb6b5d0c94acfb8f4.js" type="text/javascript"></script>
<script defer="defer" src="https://a248.e.akamai.net/assets.github.com/javascripts/bundles/github-51a20e4f1a41a77997473c2a54c4d4cc374d5e59.js" type="text/javascript"></script>
<link rel='permalink' href='/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/toggle/toggle.pde'>
<meta property="og:title" content="Adafruit-MCP23017-Arduino-Library"/>
<meta property="og:type" content="githubog:gitrepository"/>
<meta property="og:url" content="https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library"/>
<meta property="og:image" content="https://a248.e.akamai.net/assets.github.com/images/gravatars/gravatar-140.png?1329920549"/>
<meta property="og:site_name" content="GitHub"/>
<meta property="og:description" content="Adafruit-MCP23017-Arduino-Library hosted on GitHub"/>
<meta name="description" content="Adafruit-MCP23017-Arduino-Library hosted on GitHub" />
<link href="https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library/commits/17ab72f32b9128e00a21bac6c2b95d10681b1b39.atom" rel="alternate" title="Recent Commits to Adafruit-MCP23017-Arduino-Library:17ab72f32b9128e00a21bac6c2b95d10681b1b39" type="application/atom+xml" />
</head>
<body class="logged_out page-blob windows vis-public env-production " data-blob-contribs-enabled="yes">
<div id="wrapper">
<div id="header" class="true clearfix">
<div class="container clearfix">
<a class="site-logo" href="https://github.com/">
<!--[if IE]>
<img alt="GitHub" class="github-logo" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7.png?1329920549" />
<img alt="GitHub" class="github-logo-hover" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7-hover.png?1329920549" />
<![endif]-->
<img alt="GitHub" class="github-logo-4x" height="30" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x.png?1337118065" />
<img alt="GitHub" class="github-logo-4x-hover" height="30" src="https://a248.e.akamai.net/assets.github.com/images/modules/header/logov7@4x-hover.png?1337118065" />
</a>
<!--
make sure to use fully qualified URLs here since this nav
is used on error pages on other domains
-->
<ul class="top-nav logged_out">
<li class="pricing"><a href="https://github.com/plans">Signup and Pricing</a></li>
<li class="explore"><a href="https://github.com/explore">Explore GitHub</a></li>
<li class="features"><a href="https://github.com/features">Features</a></li>
<li class="blog"><a href="https://github.com/blog">Blog</a></li>
<li class="login"><a href="https://github.com/login?return_to=%2Fadafruit%2FAdafruit-MCP23017-Arduino-Library%2Fblob%2F17ab72f32b9128e00a21bac6c2b95d10681b1b39%2Fexamples%2Ftoggle%2Ftoggle.pde">Login</a></li>
</ul>
</div>
</div>
<div class="site hfeed" itemscope itemtype="http://schema.org/WebPage">
<div class="container hentry">
<div class="pagehead repohead instapaper_ignore readability-menu">
<div class="title-actions-bar">
<ul class="pagehead-actions">
<li>
<span class="watch-button"><a href="/login?return_to=%2Fadafruit%2FAdafruit-MCP23017-Arduino-Library" class="minibutton btn-watch js-toggler-target entice tooltipped leftwards" title="You must be logged in to use this feature" rel="nofollow"><span><span class="icon"></span> Watch</span></a><a class="social-count js-social-count" href="/adafruit/Adafruit-MCP23017-Arduino-Library/watchers">5</a></span>
</li>
<li>
<a href="/login?return_to=%2Fadafruit%2FAdafruit-MCP23017-Arduino-Library" class="minibutton btn-fork js-toggler-target fork-button entice tooltipped leftwards" title="You must be logged in to use this feature" rel="nofollow"><span><span class="icon"></span>Fork</span></a><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/network" class="social-count">2</a>
</li>
</ul>
<h1 itemscope itemtype="http://data-vocabulary.org/Breadcrumb" class="entry-title">
<span class="repo-label"><span class="public">public</span></span>
<span class="mega-icon public-repo"></span>
<span class="author vcard">
<a href="/adafruit" class="url fn" itemprop="url" rel="author"> <span itemprop="title">adafruit</span>
</a></span> /
<strong><a href="/adafruit/Adafruit-MCP23017-Arduino-Library" class="js-current-repository">Adafruit-MCP23017-Arduino-Library</a></strong>
</h1>
</div>
<ul class="tabs">
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/" class="selected" highlight="repo_sourcerepo_downloadsrepo_commitsrepo_tagsrepo_branches">Code</a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/network" highlight="repo_network">Network</a>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/pulls" highlight="repo_pulls">Pull Requests <span class='counter'>0</span></a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/issues" highlight="repo_issues">Issues <span class='counter'>0</span></a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/graphs" highlight="repo_graphsrepo_contributors">Graphs</a></li>
</ul>
<div class="frame frame-center tree-finder" style="display:none"
data-tree-list-url="/adafruit/Adafruit-MCP23017-Arduino-Library/tree-list/17ab72f32b9128e00a21bac6c2b95d10681b1b39"
data-blob-url-prefix="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39"
>
<div class="breadcrumb">
<span class="bold"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library">Adafruit-MCP23017-Arduino-Library</a></span> /
<input class="tree-finder-input js-navigation-enable" type="text" name="query" autocomplete="off" spellcheck="false">
</div>
<div class="octotip">
<p>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/dismiss-tree-finder-help" class="dismiss js-dismiss-tree-list-help" title="Hide this notice forever" rel="nofollow">Dismiss</a>
<span class="bold">Octotip:</span> You've activated the <em>file finder</em>
by pressing <span class="kbd">t</span> Start typing to filter the
file list. Use <span class="kbd badmono">↑</span> and
<span class="kbd badmono">↓</span> to navigate,
<span class="kbd">enter</span> to view files.
</p>
</div>
<table class="tree-browser" cellpadding="0" cellspacing="0">
<tr class="js-header"><th>&nbsp;</th><th>name</th></tr>
<tr class="js-no-results no-results" style="display: none">
<th colspan="2">No matching files</th>
</tr>
<tbody class="js-results-list js-navigation-container">
</tbody>
</table>
</div>
<div id="jump-to-line" style="display:none">
<h2>Jump to Line</h2>
<form accept-charset="UTF-8">
<input class="textfield" type="text">
<div class="full-button">
<button type="submit" class="classy">
<span>Go</span>
</button>
</div>
</form>
</div>
<div class="subnav-bar">
<ul class="actions subnav">
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tags" class="blank" highlight="repo_tags">Tags <span class="counter">0</span></a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/downloads" class="blank downloads-blank" highlight="repo_downloads">Downloads <span class="counter">0</span></a></li>
</ul>
<ul class="scope">
<li class="switcher">
<div class="context-menu-container js-menu-container js-context-menu">
<a href="#"
class="minibutton bigger switcher js-menu-target js-commitish-button btn-tree repo-tree"
data-hotkey="w"
data-master-branch="master"
data-ref="">
<span><span class="icon"></span><i>tree:</i> 17ab72f32b</span>
</a>
<div class="context-pane commitish-context js-menu-content">
<a href="javascript:;" class="close js-menu-close"><span class="mini-icon remove-close"></span></a>
<div class="context-title">Switch Branches/Tags</div>
<div class="context-body pane-selector commitish-selector js-navigation-container">
<div class="filterbar">
<input type="text" id="context-commitish-filter-field" class="js-navigation-enable" placeholder="Filter branches/tags" data-filterable />
<ul class="tabs">
<li><a href="#" data-filter="branches" class="selected">Branches</a></li>
<li><a href="#" data-filter="tags">Tags</a></li>
</ul>
</div>
<div class="js-filter-tab js-filter-branches" data-filterable-for="context-commitish-filter-field">
<div class="no-results js-not-filterable">Nothing to show</div>
<div class="commitish-item branch-commitish selector-item js-navigation-item js-navigation-target">
<h4>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/master/examples/toggle/toggle.pde" class="js-navigation-open" data-name="master" rel="nofollow">master</a>
</h4>
</div>
</div>
<div class="js-filter-tab js-filter-tags" style="display:none" data-filterable-for="context-commitish-filter-field">
<div class="no-results js-not-filterable">Nothing to show</div>
</div>
</div>
</div><!-- /.commitish-context-context -->
</div>
</li>
</ul>
<ul class="subnav with-scope">
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/" class="selected" highlight="repo_source">Files</a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/commits/" highlight="repo_commits">Commits</a></li>
<li><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/branches" class="" highlight="repo_branches" rel="nofollow">Branches <span class="counter">1</span></a></li>
</ul>
</div>
</div><!-- /.repohead -->
<!-- block_view_fragment_key: views8/v8/blob:v21:f3431d409c53f3bfe11a49a2e51233e5 -->
<div id="slider">
<div class="breadcrumb" data-path="examples/toggle/toggle.pde/">
<b itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/17ab72f32b9128e00a21bac6c2b95d10681b1b39" class="js-rewrite-sha" itemprop="url"><span itemprop="title">Adafruit-MCP23017-Arduino-Library</span></a></b> / <span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples" class="js-rewrite-sha" itemscope="url"><span itemprop="title">examples</span></a></span> / <span itemscope="" itemtype="http://data-vocabulary.org/Breadcrumb"><a href="/adafruit/Adafruit-MCP23017-Arduino-Library/tree/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/toggle" class="js-rewrite-sha" itemscope="url"><span itemprop="title">toggle</span></a></span> / <strong class="final-path">toggle.pde</strong> <span class="js-clippy mini-icon clippy " data-clipboard-text="examples/toggle/toggle.pde" data-copied-hint="copied!" data-copy-hint="copy to clipboard"></span>
</div>
<div class="commit file-history-tease" data-path="examples/toggle/toggle.pde/">
<img class="main-avatar" height="24" src="https://secure.gravatar.com/avatar/3f7ca151e1f7f7dead8b2db60aa744c1?s=140&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png" width="24" />
<span class="author"><a href="/ladyada">ladyada</a></span>
<time class="js-relative-date" datetime="2012-02-14T09:15:20-08:00" title="2012-02-14 09:15:20">February 14, 2012</time>
<div class="commit-title">
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/commit/6eb6038bd7eacf825b89383ac3d4cd047851ca2d" class="message">Examples for inputs and outputs</a>
</div>
<div class="participation">
<p class="quickstat"><a href="#blob_contributors_box" rel="facebox"><strong>1</strong> contributor</a></p>
</div>
<div id="blob_contributors_box" style="display:none">
<h2>Users on GitHub who have contributed to this file</h2>
<ul class="facebox-user-list">
<li>
<img height="24" src="https://secure.gravatar.com/avatar/3f7ca151e1f7f7dead8b2db60aa744c1?s=140&amp;d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png" width="24" />
<a href="/ladyada">ladyada</a>
</li>
</ul>
</div>
</div>
<div class="frames">
<div class="frame frame-center" data-path="examples/toggle/toggle.pde/" data-permalink-url="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/toggle/toggle.pde" data-title="Adafruit-MCP23017-Arduino-Library/examples/toggle/toggle.pde at master · adafruit/Adafruit-MCP23017-Arduino-Library · GitHub" data-type="blob">
<div id="files" class="bubble">
<div class="file">
<div class="meta">
<div class="info">
<span class="icon"><b class="mini-icon text-file"></b></span>
<span class="mode" title="File Mode">100644</span>
<span>34 lines (22 sloc)</span>
<span>0.771 kb</span>
</div>
<ul class="button-group actions">
<li>
<a class="grouped-button file-edit-link minibutton bigger lighter js-rewrite-sha" href="/adafruit/Adafruit-MCP23017-Arduino-Library/edit/17ab72f32b9128e00a21bac6c2b95d10681b1b39/examples/toggle/toggle.pde" data-method="post" rel="nofollow" data-hotkey="e"><span>Edit this file</span></a>
</li>
<li>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/raw/master/examples/toggle/toggle.pde" class="minibutton btn-raw grouped-button bigger lighter" id="raw-url"><span><span class="icon"></span>Raw</span></a>
</li>
<li>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/blame/master/examples/toggle/toggle.pde" class="minibutton btn-blame grouped-button bigger lighter"><span><span class="icon"></span>Blame</span></a>
</li>
<li>
<a href="/adafruit/Adafruit-MCP23017-Arduino-Library/commits/master/examples/toggle/toggle.pde" class="minibutton btn-history grouped-button bigger lighter" rel="nofollow"><span><span class="icon"></span>History</span></a>
</li>
</ul>
</div>
<div class="data type-java">
<table cellpadding="0" cellspacing="0" class="lines">
<tr>
<td>
<pre class="line_numbers"><span id="L1" rel="#L1">1</span>
<span id="L2" rel="#L2">2</span>
<span id="L3" rel="#L3">3</span>
<span id="L4" rel="#L4">4</span>
<span id="L5" rel="#L5">5</span>
<span id="L6" rel="#L6">6</span>
<span id="L7" rel="#L7">7</span>
<span id="L8" rel="#L8">8</span>
<span id="L9" rel="#L9">9</span>
<span id="L10" rel="#L10">10</span>
<span id="L11" rel="#L11">11</span>
<span id="L12" rel="#L12">12</span>
<span id="L13" rel="#L13">13</span>
<span id="L14" rel="#L14">14</span>
<span id="L15" rel="#L15">15</span>
<span id="L16" rel="#L16">16</span>
<span id="L17" rel="#L17">17</span>
<span id="L18" rel="#L18">18</span>
<span id="L19" rel="#L19">19</span>
<span id="L20" rel="#L20">20</span>
<span id="L21" rel="#L21">21</span>
<span id="L22" rel="#L22">22</span>
<span id="L23" rel="#L23">23</span>
<span id="L24" rel="#L24">24</span>
<span id="L25" rel="#L25">25</span>
<span id="L26" rel="#L26">26</span>
<span id="L27" rel="#L27">27</span>
<span id="L28" rel="#L28">28</span>
<span id="L29" rel="#L29">29</span>
<span id="L30" rel="#L30">30</span>
<span id="L31" rel="#L31">31</span>
<span id="L32" rel="#L32">32</span>
<span id="L33" rel="#L33">33</span>
<span id="L34" rel="#L34">34</span>
</pre>
</td>
<td width="100%">
<div class="highlight"><pre><div class='line' id='LC1'><span class="err">#</span><span class="n">include</span> <span class="o">&lt;</span><span class="n">Wire</span><span class="o">.</span><span class="na">h</span><span class="o">&gt;</span></div><div class='line' id='LC2'><span class="err">#</span><span class="n">include</span> <span class="s">&quot;Adafruit_MCP23017.h&quot;</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="c1">// Basic pin reading and pullup test for the MCP23017 I/O expander</span></div><div class='line' id='LC5'><span class="c1">// public domain!</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'><span class="c1">// Connect pin #12 of the expander to Analog 5 (i2c clock)</span></div><div class='line' id='LC8'><span class="c1">// Connect pin #13 of the expander to Analog 4 (i2c data)</span></div><div class='line' id='LC9'><span class="c1">// Connect pins #15, 16 and 17 of the expander to ground (address selection)</span></div><div class='line' id='LC10'><span class="c1">// Connect pin #9 of the expander to 5V (power)</span></div><div class='line' id='LC11'><span class="c1">// Connect pin #10 of the expander to ground (common ground)</span></div><div class='line' id='LC12'><br/></div><div class='line' id='LC13'><span class="c1">// Output #0 is on pin 21 so connect an LED or whatever from that to ground</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'><span class="n">Adafruit_MCP23017</span> <span class="n">mcp</span><span class="o">;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;</div><div class='line' id='LC17'><span class="kt">void</span> <span class="nf">setup</span><span class="o">()</span> <span class="o">{</span> </div><div class='line' id='LC18'>&nbsp;&nbsp;<span class="n">mcp</span><span class="o">.</span><span class="na">begin</span><span class="o">();</span> <span class="c1">// use default address 0</span></div><div class='line' id='LC19'><br/></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="n">mcp</span><span class="o">.</span><span class="na">pinMode</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">OUTPUT</span><span class="o">);</span></div><div class='line' id='LC21'><span class="o">}</span></div><div class='line' id='LC22'><br/></div><div class='line' id='LC23'><br/></div><div class='line' id='LC24'><span class="c1">// flip the pin #0 up and down</span></div><div class='line' id='LC25'><br/></div><div class='line' id='LC26'><span class="kt">void</span> <span class="nf">loop</span><span class="o">()</span> <span class="o">{</span></div><div class='line' id='LC27'>&nbsp;&nbsp;<span class="n">delay</span><span class="o">(</span><span class="mi">100</span><span class="o">);</span></div><div class='line' id='LC28'><br/></div><div class='line' id='LC29'>&nbsp;&nbsp;<span class="n">mcp</span><span class="o">.</span><span class="na">digitalWrite</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">HIGH</span><span class="o">);</span></div><div class='line' id='LC30'><br/></div><div class='line' id='LC31'>&nbsp;&nbsp;<span class="n">delay</span><span class="o">(</span><span class="mi">100</span><span class="o">);</span></div><div class='line' id='LC32'><br/></div><div class='line' id='LC33'>&nbsp;&nbsp;<span class="n">mcp</span><span class="o">.</span><span class="na">digitalWrite</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="n">LOW</span><span class="o">);</span></div><div class='line' id='LC34'><span class="o">}</span></div></pre></div>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="frame frame-loading large-loading-area" style="display:none;" data-tree-list-url="/adafruit/Adafruit-MCP23017-Arduino-Library/tree-list/17ab72f32b9128e00a21bac6c2b95d10681b1b39" data-blob-url-prefix="/adafruit/Adafruit-MCP23017-Arduino-Library/blob/17ab72f32b9128e00a21bac6c2b95d10681b1b39">
<img src="https://a248.e.akamai.net/assets.github.com/images/spinners/octocat-spinner-64.gif?1329920549" height="64" width="64">
</div>
</div>
<div class="context-overlay"></div>
</div>
<div id="footer-push"></div><!-- hack for sticky footer -->
</div><!-- end of wrapper - hack for sticky footer -->
<!-- footer -->
<div id="footer" >
<div class="upper_footer">
<div class="container clearfix">
<!--[if IE]><h4 id="blacktocat_ie">GitHub Links</h4><![endif]-->
<![if !IE]><h4 id="blacktocat">GitHub Links</h4><![endif]>
<ul class="footer_nav">
<h4>GitHub</h4>
<li><a href="https://github.com/about">About</a></li>
<li><a href="https://github.com/blog">Blog</a></li>
<li><a href="https://github.com/features">Features</a></li>
<li><a href="https://github.com/contact">Contact &amp; Support</a></li>
<li><a href="https://github.com/training">Training</a></li>
<li><a href="http://enterprise.github.com/">GitHub Enterprise</a></li>
<li><a href="http://status.github.com/">Site Status</a></li>
</ul>
<ul class="footer_nav">
<h4>Tools</h4>
<li><a href="http://get.gaug.es/">Gauges: Analyze web traffic</a></li>
<li><a href="http://speakerdeck.com">Speaker Deck: Presentations</a></li>
<li><a href="https://gist.github.com">Gist: Code snippets</a></li>
<li><a href="http://mac.github.com/">GitHub for Mac</a></li>
<li><a href="http://mobile.github.com/">Issues for iPhone</a></li>
<li><a href="http://jobs.github.com/">Job Board</a></li>
</ul>
<ul class="footer_nav">
<h4>Extras</h4>
<li><a href="http://shop.github.com/">GitHub Shop</a></li>
<li><a href="http://octodex.github.com/">The Octodex</a></li>
</ul>
<ul class="footer_nav">
<h4>Documentation</h4>
<li><a href="http://help.github.com/">GitHub Help</a></li>
<li><a href="http://developer.github.com/">Developer API</a></li>
<li><a href="http://github.github.com/github-flavored-markdown/">GitHub Flavored Markdown</a></li>
<li><a href="http://pages.github.com/">GitHub Pages</a></li>
</ul>
</div><!-- /.site -->
</div><!-- /.upper_footer -->
<div class="lower_footer">
<div class="container clearfix">
<!--[if IE]><div id="legal_ie"><![endif]-->
<![if !IE]><div id="legal"><![endif]>
<ul>
<li><a href="https://github.com/site/terms">Terms of Service</a></li>
<li><a href="https://github.com/site/privacy">Privacy</a></li>
<li><a href="https://github.com/security">Security</a></li>
</ul>
<p>&copy; 2012 <span title="0.05006s from fe15.rs.github.com">GitHub</span> Inc. All rights reserved.</p>
</div><!-- /#legal or /#legal_ie-->
<div class="sponsor">
<a href="http://www.rackspace.com" class="logo">
<img alt="Dedicated Server" height="36" src="https://a248.e.akamai.net/assets.github.com/images/modules/footer/rackspaces_logo.png?1329920549" width="38" />
</a>
Powered by the <a href="http://www.rackspace.com ">Dedicated
Servers</a> and<br/> <a href="http://www.rackspacecloud.com">Cloud
Computing</a> of Rackspace Hosting<span>&reg;</span>
</div>
</div><!-- /.site -->
</div><!-- /.lower_footer -->
</div><!-- /#footer -->
<div id="keyboard_shortcuts_pane" class="instapaper_ignore readability-extra" style="display:none">
<h2>Keyboard Shortcuts <small><a href="#" class="js-see-all-keyboard-shortcuts">(see all)</a></small></h2>
<div class="columns threecols">
<div class="column first">
<h3>Site wide shortcuts</h3>
<dl class="keyboard-mappings">
<dt>s</dt>
<dd>Focus site search</dd>
</dl>
<dl class="keyboard-mappings">
<dt>?</dt>
<dd>Bring up this help dialog</dd>
</dl>
</div><!-- /.column.first -->
<div class="column middle" style='display:none'>
<h3>Commit list</h3>
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>c <em>or</em> o <em>or</em> enter</dt>
<dd>Open commit</dd>
</dl>
<dl class="keyboard-mappings">
<dt>y</dt>
<dd>Expand URL to its canonical form</dd>
</dl>
</div><!-- /.column.first -->
<div class="column last" style='display:none'>
<h3>Pull request list</h3>
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o <em>or</em> enter</dt>
<dd>Open issue</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="platform-mac">⌘</span><span class="platform-other">ctrl</span> <em>+</em> enter</dt>
<dd>Submit comment</dd>
</dl>
</div><!-- /.columns.last -->
</div><!-- /.columns.equacols -->
<div style='display:none'>
<div class="rule"></div>
<h3>Issues</h3>
<div class="columns threecols">
<div class="column first">
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>x</dt>
<dd>Toggle selection</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o <em>or</em> enter</dt>
<dd>Open issue</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="platform-mac">⌘</span><span class="platform-other">ctrl</span> <em>+</em> enter</dt>
<dd>Submit comment</dd>
</dl>
</div><!-- /.column.first -->
<div class="column last">
<dl class="keyboard-mappings">
<dt>c</dt>
<dd>Create issue</dd>
</dl>
<dl class="keyboard-mappings">
<dt>l</dt>
<dd>Create label</dd>
</dl>
<dl class="keyboard-mappings">
<dt>i</dt>
<dd>Back to inbox</dd>
</dl>
<dl class="keyboard-mappings">
<dt>u</dt>
<dd>Back to issues</dd>
</dl>
<dl class="keyboard-mappings">
<dt>/</dt>
<dd>Focus issues search</dd>
</dl>
</div>
</div>
</div>
<div style='display:none'>
<div class="rule"></div>
<h3>Issues Dashboard</h3>
<div class="columns threecols">
<div class="column first">
<dl class="keyboard-mappings">
<dt>j</dt>
<dd>Move selection down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>k</dt>
<dd>Move selection up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o <em>or</em> enter</dt>
<dd>Open issue</dd>
</dl>
</div><!-- /.column.first -->
</div>
</div>
<div style='display:none'>
<div class="rule"></div>
<h3>Network Graph</h3>
<div class="columns equacols">
<div class="column first">
<dl class="keyboard-mappings">
<dt><span class="badmono">←</span> <em>or</em> h</dt>
<dd>Scroll left</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="badmono">→</span> <em>or</em> l</dt>
<dd>Scroll right</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="badmono">↑</span> <em>or</em> k</dt>
<dd>Scroll up</dd>
</dl>
<dl class="keyboard-mappings">
<dt><span class="badmono">↓</span> <em>or</em> j</dt>
<dd>Scroll down</dd>
</dl>
<dl class="keyboard-mappings">
<dt>t</dt>
<dd>Toggle visibility of head labels</dd>
</dl>
</div><!-- /.column.first -->
<div class="column last">
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">←</span> <em>or</em> shift h</dt>
<dd>Scroll all the way left</dd>
</dl>
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">→</span> <em>or</em> shift l</dt>
<dd>Scroll all the way right</dd>
</dl>
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">↑</span> <em>or</em> shift k</dt>
<dd>Scroll all the way up</dd>
</dl>
<dl class="keyboard-mappings">
<dt>shift <span class="badmono">↓</span> <em>or</em> shift j</dt>
<dd>Scroll all the way down</dd>
</dl>
</div><!-- /.column.last -->
</div>
</div>
<div >
<div class="rule"></div>
<div class="columns threecols">
<div class="column first" >
<h3>Source Code Browsing</h3>
<dl class="keyboard-mappings">
<dt>t</dt>
<dd>Activates the file finder</dd>
</dl>
<dl class="keyboard-mappings">
<dt>l</dt>
<dd>Jump to line</dd>
</dl>
<dl class="keyboard-mappings">
<dt>w</dt>
<dd>Switch branch/tag</dd>
</dl>
<dl class="keyboard-mappings">
<dt>y</dt>
<dd>Expand URL to its canonical form</dd>
</dl>
</div>
</div>
</div>
<div style='display:none'>
<div class="rule"></div>
<div class="columns threecols">
<div class="column first">
<h3>Browsing Commits</h3>
<dl class="keyboard-mappings">
<dt><span class="platform-mac">⌘</span><span class="platform-other">ctrl</span> <em>+</em> enter</dt>
<dd>Submit comment</dd>
</dl>
<dl class="keyboard-mappings">
<dt>escape</dt>
<dd>Close form</dd>
</dl>
<dl class="keyboard-mappings">
<dt>p</dt>
<dd>Parent commit</dd>
</dl>
<dl class="keyboard-mappings">
<dt>o</dt>
<dd>Other parent commit</dd>
</dl>
</div>
</div>
</div>
</div>
<div id="markdown-help" class="instapaper_ignore readability-extra">
<h2>Markdown Cheat Sheet</h2>
<div class="cheatsheet-content">
<div class="mod">
<div class="col">
<h3>Format Text</h3>
<p>Headers</p>
<pre>
# This is an &lt;h1&gt; tag
## This is an &lt;h2&gt; tag
###### This is an &lt;h6&gt; tag</pre>
<p>Text styles</p>
<pre>
*This text will be italic*
_This will also be italic_
**This text will be bold**
__This will also be bold__
*You **can** combine them*
</pre>
</div>
<div class="col">
<h3>Lists</h3>
<p>Unordered</p>
<pre>
* Item 1
* Item 2
* Item 2a
* Item 2b</pre>
<p>Ordered</p>
<pre>
1. Item 1
2. Item 2
3. Item 3
* Item 3a
* Item 3b</pre>
</div>
<div class="col">
<h3>Miscellaneous</h3>
<p>Images</p>
<pre>
![GitHub Logo](/images/logo.png)
Format: ![Alt Text](url)
</pre>
<p>Links</p>
<pre>
http://github.com - automatic!
[GitHub](http://github.com)</pre>
<p>Blockquotes</p>
<pre>
As Kanye West said:
> We're living the future so
> the present is our past.
</pre>
</div>
</div>
<div class="rule"></div>
<h3>Code Examples in Markdown</h3>
<div class="col">
<p>Syntax highlighting with <a href="http://github.github.com/github-flavored-markdown/" title="GitHub Flavored Markdown" target="_blank">GFM</a></p>
<pre>
```javascript
function fancyAlert(arg) {
if(arg) {
$.facebox({div:'#foo'})
}
}
```</pre>
</div>
<div class="col">
<p>Or, indent your code 4 spaces</p>
<pre>
Here is a Python code example
without syntax highlighting:
def foo:
if not bar:
return true</pre>
</div>
<div class="col">
<p>Inline code for comments</p>
<pre>
I think you should use an
`&lt;addr&gt;` element here instead.</pre>
</div>
</div>
</div>
</div>
<div class="ajax-error-message">
<p><span class="mini-icon exclamation"></span> Something went wrong with that request. Please try again. <a href="javascript:;" class="ajax-error-dismiss">Dismiss</a></p>
</div>
<div id="logo-popup">
<h2>Looking for the GitHub logo?</h2>
<ul>
<li>
<h4>GitHub Logo</h4>
<a href="http://github-media-downloads.s3.amazonaws.com/GitHub_Logos.zip"><img alt="Github_logo" src="https://a248.e.akamai.net/assets.github.com/images/modules/about_page/github_logo.png?1329920549" /></a>
<a href="http://github-media-downloads.s3.amazonaws.com/GitHub_Logos.zip" class="minibutton btn-download download"><span><span class="icon"></span>Download</span></a>
</li>
<li>
<h4>The Octocat</h4>
<a href="http://github-media-downloads.s3.amazonaws.com/Octocats.zip"><img alt="Octocat" src="https://a248.e.akamai.net/assets.github.com/images/modules/about_page/octocat.png?1329920549" /></a>
<a href="http://github-media-downloads.s3.amazonaws.com/Octocats.zip" class="minibutton btn-download download"><span><span class="icon"></span>Download</span></a>
</li>
</ul>
</div>
<span id='server_response_time' data-time='0.05243' data-host='fe15'></span>
</body>
</html>

View File

@ -0,0 +1,34 @@
#include <Wire.h>
#include "Adafruit_MCP23017.h"
// Basic pin reading and pullup test for the MCP23017 I/O expander
// public domain!
// Connect pin #12 of the expander to Analog 5 (i2c clock)
// Connect pin #13 of the expander to Analog 4 (i2c data)
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Output #0 is on pin 21 so connect an LED or whatever from that to ground
Adafruit_MCP23017 mcp;
void setup() {
mcp.begin(); // use default address 0
mcp.pinMode(0, OUTPUT);
}
// flip the pin #0 up and down
void loop() {
delay(100);
mcp.digitalWrite(0, HIGH);
delay(100);
mcp.digitalWrite(0, LOW);
}

View File

@ -0,0 +1,21 @@
#######################################
# Syntax Coloring Map for MCP23017
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
MCP23017 KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
pullUp KEYWORD2
writeGPIOAB KEYWORD2
readGPIOAB KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

View File

@ -0,0 +1,26 @@
Software License Agreement (BSD License)
Copyright (c) 2012, Adafruit Industries
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

119
libraries/DS1307/DS1307.cpp Normal file
View File

@ -0,0 +1,119 @@
/*
* Maurice Ribble
* 4-17-2008
* http://www.glacialwanderer.com/hobbyrobotics
* This code tests the DS1307 Real Time clock on the Arduino board.
* The ds1307 works in binary coded decimal or BCD. You can look up
* bcd in google if you aren't familior with it. There can output
* a square wave, but I don't expose that in this code. See the
* ds1307 for it's full capabilities.
*
* Add Wire.begin(); to main setup function when ready to use.
*
* Modified 9/12/2009 by Arclight for C library use.
* arclight@gmail.com
*/
#include <DS1307.h>
#include <Wire.h>
DS1307::DS1307(){
}
DS1307::~DS1307(){
}
// Convert normal decimal numbers to binary coded decimal
uint8_t DS1307::decToBcd(uint8_t val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
uint8_t DS1307::bcdToDec(uint8_t val)
{
return ( (val/16*10) + (val%16) );
}
// Stops the DS1307, but it has the side effect of setting seconds to 0
// Probably only want to use this for testing
/*
void DS1307::stopDs1307()
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(0);
Wire.write(0x80);
Wire.endTransmission();
}
*/
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void DS1307::setDateDs1307(uint8_t second, // 0-59
uint8_t minute, // 0-59
uint8_t hour, // 1-23
uint8_t dayOfWeek, // 1-7
uint8_t dayOfMonth, // 1-28/29/30/31
uint8_t month, // 1-12
uint8_t year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(byte(0));
Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour)); // If you want 12 hour am/pm you need to set
// bit 6 (also need to change readDateDs1307)
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
// Gets the date and time from the ds1307
void DS1307::getDateDs1307(uint8_t *second,
uint8_t *minute,
uint8_t *hour,
uint8_t *dayOfWeek,
uint8_t *dayOfMonth,
uint8_t *month,
uint8_t *year)
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
/*
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
uint8_t second = 20;
uint8_t minute = 9;
uint8_t hour = 19;
uint8_t dayOfWeek = 6;
uint8_t dayOfMonth = 12;
uint8_t month = 9;
uint8_t year = 9;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
*/

44
libraries/DS1307/DS1307.h Normal file
View File

@ -0,0 +1,44 @@
/* Adds support for the DS1307 real-time clock chip (RTC)
*/
#ifndef _DS1307_H_
#define _DS1307_H_
#endif
#ifndef _Wire_H_
#define _Wire_H_
#endif
#include <Arduino.h>
#define DS1307_I2C_ADDRESS 0x68
extern byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
class DS1307 {
public:
DS1307();
~DS1307();
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year); // 0-99
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year);
private:
byte decToBcd(byte val);
byte bcdToDec(byte val);
};

View File

@ -0,0 +1,4 @@
decToBcd KEYWORD2
bcdToDec KEYWORD2
setDateDs1307 KEYWORD2
getDateDs1307 KEYWORD2

View File

@ -0,0 +1,76 @@
/*
E24C1024.cpp
AT24C1024 Library for Arduino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US
This library is based on several projects:
The Arduino EEPROM library found here:
http://arduino.cc/en/Reference/EEPROM
The 24C256 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM
The 24C512 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM24LC512
Our project page is here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
From the datasheet:
The AT24C1024B provides 1,048,576 bits of serial electrically
erasable and programmable read only memory (EEPROM) organized
as 131,072 words of 8 bits each. The devices cascadable
feature allows up to four devices to share a common two-wire
bus.
http://www.atmel.com/dyn/resources/prod_documents/doc5194.pdf
*/
#include <Wire.h>
#include <Arduino.h>
#include "E24C1024.h"
E24C1024::E24C1024(void)
{
Wire.begin();
}
void E24C1024::write(unsigned long dataAddress, uint8_t data)
{
Wire.beginTransmission((uint8_t)((0x500000 | dataAddress) >> 16)); // B1010xxx
Wire.write((uint8_t)((dataAddress & WORD_MASK) >> 8)); // MSB
Wire.write((uint8_t)(dataAddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5);
}
uint8_t E24C1024::read(unsigned long dataAddress)
{
uint8_t data = 0x00;
Wire.beginTransmission((uint8_t)((0x500000 | dataAddress) >> 16)); // B1010xxx
Wire.write((uint8_t)((dataAddress & WORD_MASK) >> 8)); // MSB
Wire.write((uint8_t)(dataAddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(0x50,1);
if (Wire.available()) data = Wire.read();
return data;
}
E24C1024 EEPROM1024;

View File

@ -0,0 +1,62 @@
#ifndef E24C1024_h
#define E24C1024_h
/*
E24C1024.h
AT24C1024 Library for Arduino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 US
This library is based on several projects:
The Arduino EEPROM library found here:
http://arduino.cc/en/Reference/EEPROM
The 24C256 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM
The 24C512 library found here:
http://www.arduino.cc/playground/Code/I2CEEPROM24LC512
Our project page is here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
From the datasheet:
The AT24C1024B provides 1,048,576 bits of serial electrically
erasable and programmable read only memory (EEPROM) organized
as 131,072 words of 8 bits each. The devices cascadable
feature allows up to four devices to share a common two-wire
bus.
http://www.atmel.com/dyn/resources/prod_documents/doc5194.pdf
*/
//#include <WConstants.h>
#include <Wire.h>
#define FULL_MASK 0x7FFFF
#define DEVICE_MASK 0x7F0000
#define WORD_MASK 0xFFFF
class E24C1024
{
public:
E24C1024();
static void write(unsigned long, uint8_t);
static uint8_t read(unsigned long);
};
extern E24C1024 EEPROM1024;
#endif

View File

@ -0,0 +1,115 @@
/*
EEPROM1024.pde
AT24C1024 EEPROM Benchmark Sketch
Our project page is here:
http://www.arduino.cc/playground/Code/I2CEEPROM24C1024
From the datasheet:
The AT24C1024B provides 1,048,576 bits of serial electrically
erasable and programmable read only memory (EEPROM) organized
as 131,072 words of 8 bits each. The devices cascadable
feature allows up to four devices to share a common two-wire
bus.
http://www.atmel.com/dyn/resources/prod_documents/doc5194.pdf
*/
#include <WProgram.h>
#include <Wire.h>
#include <E24C1024.h>
unsigned long time;
unsigned long finishTime;
unsigned long errors = 0;
unsigned long address = 0;
byte loop_size;
// Set to a higher number if you want to start at a higher address.
#define MIN_ADDRESS 0
// Upper boundary of the address space. Choose one.
#define MAX_ADDRESS 131072 // 1 device
//#define MAX_ADDRESS 262144 // 2 devices
//#define MAX_ADDRESS 393216 // 3 devices
//#define MAX_ADDRESS 524288 // 4 devices
void setup()
{
// Make sure we aren't reading old data
randomSeed(analogRead(0));
loop_size = random(1, 100);
Serial.begin(9600);
Serial.println();
Serial.println("E24C1024 Library Benchmark Sketch");
Serial.println();
writeByByteTest();
readByByteTest();
}
void loop()
{
}
void writeByByteTest()
{
time = millis();
errors = 0;
Serial.println("--------------------------------");
Serial.println("Write By Byte Test:");
Serial.println();
Serial.print("Writing data:");
for (address = MIN_ADDRESS; address < MAX_ADDRESS; address++)
{
EEPROM1024.write(address, (uint8_t)(address % loop_size));
if (!(address % 5000)) Serial.print(".");
}
finishTime = millis() - time;
Serial.println("DONE");
Serial.print("Total Time (seconds): ");
Serial.println((unsigned long)(finishTime / 1000));
Serial.print("Write operations per second: ");
Serial.println((unsigned long)(MAX_ADDRESS / (finishTime / 1000)));
Serial.println("--------------------------------");
Serial.println();
}
void readByByteTest()
{
time = millis();
errors = 0;
Serial.println("--------------------------------");
Serial.println("Read By Byte Test:");
Serial.println();
Serial.print("Reading data:");
for (address = MIN_ADDRESS; address < MAX_ADDRESS; address++)
{
uint8_t data;
data = EEPROM1024.read(address);
if (data != (uint8_t)(address % loop_size))
{
Serial.println();
Serial.print("Address: ");
Serial.print(address);
Serial.print(" Should be: ");
Serial.print((uint8_t)(address % loop_size), DEC);
Serial.print(" Read val: ");
Serial.println(data, DEC);
errors++;
}
if (!(address % 5000)) Serial.print(".");
}
finishTime = millis() - time;
Serial.println("DONE");
Serial.println();
Serial.print("Total Test Time (secs): ");
Serial.println((unsigned long)(finishTime / 1000));
Serial.print("Read operations per second: ");
Serial.println((unsigned long)(MAX_ADDRESS / (finishTime / 1000)));
Serial.print("Total errors: ");
Serial.println(errors);
Serial.println("--------------------------------");
Serial.println();
}

View File

@ -0,0 +1,25 @@
#include <NewSoftSerial.h>
NewSoftSerial mySerial(2, 3);
void setup()
{
Serial.begin(57600);
Serial.println("Goodnight moon!");
// set the data rate for the NewSoftSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}
void loop() // run over and over again
{
if (mySerial.available()) {
Serial.print((char)mySerial.read());
}
if (Serial.available()) {
mySerial.print((char)Serial.read());
}
}

View File

@ -0,0 +1,33 @@
#include <NewSoftSerial.h>
NewSoftSerial nss(2, 3);
NewSoftSerial nss2(4, 5);
void setup()
{
nss2.begin(4800);
nss.begin(4800);
Serial.begin(115200);
}
void loop()
{
// Every 10 seconds switch from
// one serial GPS device to the other
if ((millis() / 10000) % 2 == 0)
{
if (nss.available())
{
Serial.print(nss.read(), BYTE);
}
}
else
{
if (nss2.available())
{
Serial.print(nss2.read(), BYTE);
}
}
}

View File

@ -0,0 +1,539 @@
/*
NewSoftSerial.cpp - Multi-instance software serial library
Copyright (c) 2006 David A. Mellis. All rights reserved.
-- Interrupt-driven receive and other improvements by ladyada
-- Tuning, circular buffer, derivation from class Print,
multi-instance support, porting to 8MHz processors,
various optimizations, PROGMEM delay tables, inverse logic and
direct port writing by Mikal Hart
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
The latest version of this library can always be found at
http://arduiniana.org.
*/
// When set, _DEBUG co-opts pins 11 and 13 for debugging with an
// oscilloscope or logic analyzer. Beware: it also slightly modifies
// the bit times, so don't rely on it too much at high baud rates
#define _DEBUG 0
#define _DEBUG_PIN1 11
#define _DEBUG_PIN2 13
//
// Includes
//
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "WConstants.h"
#include "pins_arduino.h"
#include "NewSoftSerial.h"
// Abstractions for maximum portability between processors
// These are macros to associate pins to pin change interrupts
#if !defined(digitalPinToPCICR) // Courtesy Paul Stoffregen
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)NULL))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)NULL))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
#else
#define digitalPinToPCICR(p) ((uint8_t *)NULL)
#define digitalPinToPCICRbit(p) 0
#define digitalPinToPCMSK(p) ((uint8_t *)NULL)
#define digitalPinToPCMSKbit(p) 0
#endif
#endif
//
// Lookup table
//
typedef struct _DELAY_TABLE
{
long baud;
unsigned short rx_delay_centering;
unsigned short rx_delay_intrabit;
unsigned short rx_delay_stopbit;
unsigned short tx_delay;
} DELAY_TABLE;
#if F_CPU == 16000000
static const DELAY_TABLE PROGMEM table[] =
{
// baud rxcenter rxintra rxstop tx
{ 115200, 1, 17, 17, 12, },
{ 57600, 10, 37, 37, 33, },
{ 38400, 25, 57, 57, 54, },
{ 31250, 31, 70, 70, 68, },
{ 28800, 34, 77, 77, 74, },
{ 19200, 54, 117, 117, 114, },
{ 14400, 74, 156, 156, 153, },
{ 9600, 114, 236, 236, 233, },
{ 4800, 233, 474, 474, 471, },
{ 2400, 471, 950, 950, 947, },
{ 1200, 947, 1902, 1902, 1899, },
{ 300, 3804, 7617, 7617, 7614, },
};
const int XMIT_START_ADJUSTMENT = 5;
#elif F_CPU == 8000000
static const DELAY_TABLE table[] PROGMEM =
{
// baud rxcenter rxintra rxstop tx
{ 115200, 1, 5, 5, 3, },
{ 57600, 1, 15, 15, 13, },
{ 38400, 2, 25, 26, 23, },
{ 31250, 7, 32, 33, 29, },
{ 28800, 11, 35, 35, 32, },
{ 19200, 20, 55, 55, 52, },
{ 14400, 30, 75, 75, 72, },
{ 9600, 50, 114, 114, 112, },
{ 4800, 110, 233, 233, 230, },
{ 2400, 229, 472, 472, 469, },
{ 1200, 467, 948, 948, 945, },
{ 300, 1895, 3805, 3805, 3802, },
};
const int XMIT_START_ADJUSTMENT = 4;
#elif F_CPU == 20000000
// 20MHz support courtesy of the good people at macegr.com.
// Thanks, Garrett!
static const DELAY_TABLE PROGMEM table[] =
{
// baud rxcenter rxintra rxstop tx
{ 115200, 3, 21, 21, 18, },
{ 57600, 20, 43, 43, 41, },
{ 38400, 37, 73, 73, 70, },
{ 31250, 45, 89, 89, 88, },
{ 28800, 46, 98, 98, 95, },
{ 19200, 71, 148, 148, 145, },
{ 14400, 96, 197, 197, 194, },
{ 9600, 146, 297, 297, 294, },
{ 4800, 296, 595, 595, 592, },
{ 2400, 592, 1189, 1189, 1186, },
{ 1200, 1187, 2379, 2379, 2376, },
{ 300, 4759, 9523, 9523, 9520, },
};
const int XMIT_START_ADJUSTMENT = 6;
#else
#error This version of NewSoftSerial supports only 20, 16 and 8MHz processors
#endif
//
// Statics
//
NewSoftSerial *NewSoftSerial::active_object = 0;
char NewSoftSerial::_receive_buffer[_NewSS_MAX_RX_BUFF];
volatile uint8_t NewSoftSerial::_receive_buffer_tail = 0;
volatile uint8_t NewSoftSerial::_receive_buffer_head = 0;
//
// Debugging
//
// This function generates a brief pulse
// for debugging or measuring on an oscilloscope.
inline void DebugPulse(uint8_t pin, uint8_t count)
{
#if _DEBUG
volatile uint8_t *pport = portOutputRegister(digitalPinToPort(pin));
uint8_t val = *pport;
while (count--)
{
*pport = val | digitalPinToBitMask(pin);
*pport = val;
}
#endif
}
//
// Private methods
//
/* static */
inline void NewSoftSerial::tunedDelay(uint16_t delay) {
uint8_t tmp=0;
asm volatile("sbiw %0, 0x01 \n\t"
"ldi %1, 0xFF \n\t"
"cpi %A0, 0xFF \n\t"
"cpc %B0, %1 \n\t"
"brne .-10 \n\t"
: "+r" (delay), "+a" (tmp)
: "0" (delay)
);
}
// This function sets the current object as the "active"
// one and returns true if it replaces another
bool NewSoftSerial::activate(void)
{
if (active_object != this)
{
_buffer_overflow = false;
uint8_t oldSREG = SREG;
cli();
_receive_buffer_head = _receive_buffer_tail = 0;
active_object = this;
SREG = oldSREG;
return true;
}
return false;
}
//
// The receive routine called by the interrupt handler
//
void NewSoftSerial::recv()
{
#if GCC_VERSION < 40302
// Work-around for avr-gcc 4.3.0 OSX version bug
// Preserve the registers that the compiler misses
// (courtesy of Arduino forum user *etracer*)
asm volatile(
"push r18 \n\t"
"push r19 \n\t"
"push r20 \n\t"
"push r21 \n\t"
"push r22 \n\t"
"push r23 \n\t"
"push r26 \n\t"
"push r27 \n\t"
::);
#endif
uint8_t d = 0;
// If RX line is high, then we don't see any start bit
// so interrupt is probably not for us
if (_inverse_logic ? rx_pin_read() : !rx_pin_read())
{
// Wait approximately 1/2 of a bit width to "center" the sample
tunedDelay(_rx_delay_centering);
DebugPulse(_DEBUG_PIN2, 1);
// Read each of the 8 bits
for (uint8_t i=0x1; i; i <<= 1)
{
tunedDelay(_rx_delay_intrabit);
DebugPulse(_DEBUG_PIN2, 1);
uint8_t noti = ~i;
if (rx_pin_read())
d |= i;
else // else clause added to ensure function timing is ~balanced
d &= noti;
}
// skip the stop bit
tunedDelay(_rx_delay_stopbit);
DebugPulse(_DEBUG_PIN2, 1);
if (_inverse_logic)
d = ~d;
// if buffer full, set the overflow flag and return
if ((_receive_buffer_tail + 1) % _NewSS_MAX_RX_BUFF != _receive_buffer_head)
{
// save new data in buffer: tail points to where byte goes
_receive_buffer[_receive_buffer_tail] = d; // save new byte
_receive_buffer_tail = (_receive_buffer_tail + 1) % _NewSS_MAX_RX_BUFF;
}
else
{
#if _DEBUG // for scope: pulse pin as overflow indictator
DebugPulse(_DEBUG_PIN1, 1);
#endif
_buffer_overflow = true;
}
}
#if GCC_VERSION < 40302
// Work-around for avr-gcc 4.3.0 OSX version bug
// Restore the registers that the compiler misses
asm volatile(
"pop r27 \n\t"
"pop r26 \n\t"
"pop r23 \n\t"
"pop r22 \n\t"
"pop r21 \n\t"
"pop r20 \n\t"
"pop r19 \n\t"
"pop r18 \n\t"
::);
#endif
}
void NewSoftSerial::tx_pin_write(uint8_t pin_state)
{
if (pin_state == LOW)
*_transmitPortRegister &= ~_transmitBitMask;
else
*_transmitPortRegister |= _transmitBitMask;
}
uint8_t NewSoftSerial::rx_pin_read()
{
return *_receivePortRegister & _receiveBitMask;
}
//
// Interrupt handling
//
/* static */
inline void NewSoftSerial::handle_interrupt()
{
if (active_object)
{
active_object->recv();
}
}
#if defined(PCINT0_vect)
ISR(PCINT0_vect)
{
NewSoftSerial::handle_interrupt();
}
#endif
#if defined(PCINT1_vect)
ISR(PCINT1_vect)
{
NewSoftSerial::handle_interrupt();
}
#endif
#if defined(PCINT2_vect)
ISR(PCINT2_vect)
{
NewSoftSerial::handle_interrupt();
}
#endif
#if defined(PCINT3_vect)
ISR(PCINT3_vect)
{
NewSoftSerial::handle_interrupt();
}
#endif
//
// Constructor
//
NewSoftSerial::NewSoftSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) :
_rx_delay_centering(0),
_rx_delay_intrabit(0),
_rx_delay_stopbit(0),
_tx_delay(0),
_buffer_overflow(false),
_inverse_logic(inverse_logic)
{
setTX(transmitPin);
setRX(receivePin);
}
//
// Destructor
//
NewSoftSerial::~NewSoftSerial()
{
end();
}
void NewSoftSerial::setTX(uint8_t tx)
{
pinMode(tx, OUTPUT);
digitalWrite(tx, HIGH);
_transmitBitMask = digitalPinToBitMask(tx);
uint8_t port = digitalPinToPort(tx);
_transmitPortRegister = portOutputRegister(port);
}
void NewSoftSerial::setRX(uint8_t rx)
{
pinMode(rx, INPUT);
if (!_inverse_logic)
digitalWrite(rx, HIGH); // pullup for normal logic!
_receivePin = rx;
_receiveBitMask = digitalPinToBitMask(rx);
uint8_t port = digitalPinToPort(rx);
_receivePortRegister = portInputRegister(port);
}
//
// Public methods
//
void NewSoftSerial::begin(long speed)
{
_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
{
long baud = pgm_read_dword(&table[i].baud);
if (baud == speed)
{
_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
_rx_delay_intrabit = pgm_read_word(&table[i].rx_delay_intrabit);
_rx_delay_stopbit = pgm_read_word(&table[i].rx_delay_stopbit);
_tx_delay = pgm_read_word(&table[i].tx_delay);
break;
}
}
// Set up RX interrupts, but only if we have a valid RX baud rate
if (_rx_delay_stopbit)
{
if (digitalPinToPCICR(_receivePin))
{
*digitalPinToPCICR(_receivePin) |= _BV(digitalPinToPCICRbit(_receivePin));
*digitalPinToPCMSK(_receivePin) |= _BV(digitalPinToPCMSKbit(_receivePin));
}
tunedDelay(_tx_delay); // if we were low this establishes the end
}
#if _DEBUG
pinMode(_DEBUG_PIN1, OUTPUT);
pinMode(_DEBUG_PIN2, OUTPUT);
#endif
activate();
}
void NewSoftSerial::end()
{
if (digitalPinToPCMSK(_receivePin))
*digitalPinToPCMSK(_receivePin) &= ~_BV(digitalPinToPCMSKbit(_receivePin));
}
// Read data from buffer
int NewSoftSerial::read(void)
{
uint8_t d;
// A newly activated object never has any rx data
if (activate())
return -1;
// Empty buffer?
if (_receive_buffer_head == _receive_buffer_tail)
return -1;
// Read from "head"
d = _receive_buffer[_receive_buffer_head]; // grab next byte
_receive_buffer_head = (_receive_buffer_head + 1) % _NewSS_MAX_RX_BUFF;
return d;
}
uint8_t NewSoftSerial::available(void)
{
// A newly activated object never has any rx data
if (activate())
return 0;
return (_receive_buffer_tail + _NewSS_MAX_RX_BUFF - _receive_buffer_head) % _NewSS_MAX_RX_BUFF;
}
void NewSoftSerial::write(uint8_t b)
{
if (_tx_delay == 0)
return;
activate();
uint8_t oldSREG = SREG;
cli(); // turn off interrupts for a clean txmit
// Write the start bit
tx_pin_write(_inverse_logic ? HIGH : LOW);
tunedDelay(_tx_delay + XMIT_START_ADJUSTMENT);
// Write each of the 8 bits
if (_inverse_logic)
{
for (byte mask = 0x01; mask; mask <<= 1)
{
if (b & mask) // choose bit
tx_pin_write(LOW); // send 1
else
tx_pin_write(HIGH); // send 0
tunedDelay(_tx_delay);
}
tx_pin_write(LOW); // restore pin to natural state
}
else
{
for (byte mask = 0x01; mask; mask <<= 1)
{
if (b & mask) // choose bit
tx_pin_write(HIGH); // send 1
else
tx_pin_write(LOW); // send 0
tunedDelay(_tx_delay);
}
tx_pin_write(HIGH); // restore pin to natural state
}
SREG = oldSREG; // turn interrupts back on
tunedDelay(_tx_delay);
}
#if !defined(cbi)
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
void NewSoftSerial::enable_timer0(bool enable)
{
if (enable)
#if defined(__AVR_ATmega8__)
sbi(TIMSK, TOIE0);
#else
sbi(TIMSK0, TOIE0);
#endif
else
#if defined(__AVR_ATmega8__)
cbi(TIMSK, TOIE0);
#else
cbi(TIMSK0, TOIE0);
#endif
}
void NewSoftSerial::flush()
{
if (active_object == this)
{
uint8_t oldSREG = SREG;
cli();
_receive_buffer_head = _receive_buffer_tail = 0;
SREG = oldSREG;
}
}

View File

@ -0,0 +1,107 @@
/*
NewSoftSerial.h - Multi-instance software serial library
Copyright (c) 2006 David A. Mellis. All rights reserved.
-- Interrupt-driven receive and other improvements by ladyada
-- Tuning, circular buffer, derivation from class Print,
multi-instance support, porting to 8MHz processors,
various optimizations, PROGMEM delay tables, inverse logic and
direct port writing by Mikal Hart
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
The latest version of this library can always be found at
http://arduiniana.org.
*/
#ifndef NewSoftSerial_h
#define NewSoftSerial_h
#include <inttypes.h>
#include "Print.h"
/******************************************************************************
* Definitions
******************************************************************************/
#define _NewSS_MAX_RX_BUFF 64 // RX buffer size
#define _NewSS_VERSION 10 // software version of this library
#ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif
class NewSoftSerial : public Print
{
private:
// per object data
uint8_t _receivePin;
uint8_t _receiveBitMask;
volatile uint8_t *_receivePortRegister;
uint8_t _transmitBitMask;
volatile uint8_t *_transmitPortRegister;
uint16_t _rx_delay_centering;
uint16_t _rx_delay_intrabit;
uint16_t _rx_delay_stopbit;
uint16_t _tx_delay;
uint16_t _buffer_overflow:1;
uint16_t _inverse_logic:1;
// static data
static char _receive_buffer[_NewSS_MAX_RX_BUFF];
static volatile uint8_t _receive_buffer_tail;
static volatile uint8_t _receive_buffer_head;
static NewSoftSerial *active_object;
// private methods
void recv();
bool activate();
virtual void write(uint8_t byte);
uint8_t rx_pin_read();
void tx_pin_write(uint8_t pin_state);
void setTX(uint8_t transmitPin);
void setRX(uint8_t receivePin);
// private static method for timing
static inline void tunedDelay(uint16_t delay);
public:
// public methods
NewSoftSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);
~NewSoftSerial();
void begin(long speed);
void end();
int read();
uint8_t available(void);
bool active() { return this == active_object; }
bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
static int library_version() { return _NewSS_VERSION; }
static void enable_timer0(bool enable);
void flush();
// public only for easy access by interrupt handlers
static inline void handle_interrupt();
};
// Arduino 0012 workaround
#undef int
#undef char
#undef long
#undef byte
#undef float
#undef abs
#undef round
#endif

Binary file not shown.

View File

@ -0,0 +1,30 @@
#######################################
# Syntax Coloring Map for NewSoftSerial
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
NewSoftSerial KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
setTX KEYWORD2
setRX KEYWORD2
begin KEYWORD2
end KEYWORD2
read KEYWORD2
available KEYWORD2
active KEYWORD2
overflow KEYWORD2
library_version KEYWORD2
enable_timer0 KEYWORD2
flush KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

View File

@ -0,0 +1,138 @@
#include "pins_arduino.h"
#include "PCATTACH.h"
/*
* an extension to the interrupt support for arduino.
* add pin change interrupts to the external interrupts, giving a way
* for users to have interrupts drive off of any pin.
* Refer to avr-gcc header files, arduino source and atmega datasheet.
*/
/*
* Theory: all IO pins on Atmega168 are covered by Pin Change Interrupts.
* The PCINT corresponding to the pin must be enabled and masked, and
* an ISR routine provided. Since PCINTs are per port, not per pin, the ISR
* must use some logic to actually implement a per-pin interrupt service.
*/
PCATTACH::PCATTACH(){
}
PCATTACH::~PCATTACH(){
}
PCATTACH pc1;
/* Pin to interrupt map:
* D0-D7 = PCINT 16-23 = PCIR2 = PD = PCIE2 = pcmsk2
* D8-D13 = PCINT 0-5 = PCIR0 = PB = PCIE0 = pcmsk0
* A0-A5 (D14-D19) = PCINT 8-13 = PCIR1 = PC = PCIE1 = pcmsk1
*/
volatile uint8_t *port_to_pcmask[] = {
&PCMSK0,
&PCMSK1,
&PCMSK2
};
typedef void (*voidFuncPtr)(void);
volatile static voidFuncPtr PCintFunc[24] = {
NULL };
volatile static uint8_t PCintLast[3];
/*
* attach an interrupt to a specific pin using pin change interrupts.
* First version only supports CHANGE mode.
*/
void PCATTACH::PCattachInterrupt(uint8_t pin, void (*userFunc)(void), int mode) {
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
uint8_t slot;
volatile uint8_t *pcmask;
if (mode != CHANGE) {
return;
}
// map pin to PCIR register
if (port == NOT_A_PORT) {
return;
}
else {
port -= 2;
pcmask = port_to_pcmask[port];
}
slot = port * 8 + (pin % 8);
PCintFunc[slot] = userFunc;
// set the mask
*pcmask |= bit;
// enable the interrupt
PCICR |= 0x01 << port;
}
void PCATTACH::PCdetachInterrupt(uint8_t pin) {
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *pcmask;
// map pin to PCIR register
if (port == NOT_A_PORT) {
return;
}
else {
port -= 2;
pcmask = port_to_pcmask[port];
}
// disable the mask.
*pcmask &= ~bit;
// if that's the last one, disable the interrupt.
if (*pcmask == 0) {
PCICR &= ~(0x01 << port);
}
}
// common code for isr handler. "port" is the PCINT number.
// there isn't really a good way to back-map ports and masks to pins.
void PCATTACH::PCint(uint8_t port) {
uint8_t bit;
uint8_t curr;
uint8_t mask;
uint8_t pin;
// get the pin states for the indicated port.
curr = *portInputRegister(port+2);
mask = curr ^ PCintLast[port];
PCintLast[port] = curr;
// mask is pins that have changed. screen out non pcint pins.
if ((mask &= *port_to_pcmask[port]) == 0) {
return;
}
// mask is pcint pins that have changed.
for (uint8_t i=0; i < 8; i++) {
bit = 0x01 << i;
if (bit & mask) {
pin = port * 8 + i;
if (PCintFunc[pin] != NULL) {
PCintFunc[pin]();
}
}
}
}
SIGNAL (PCINT0_vect) {
pc1.PCint(0);
}
SIGNAL (PCINT1_vect) {
pc1.PCint(1);
}
SIGNAL (PCINT2_vect) {
pc1.PCint(2);
}

View File

@ -0,0 +1,30 @@
#ifndef _PCATTACH_H_
#define _PCATTACH_H_
#endif
#include <Arduino.h>
class PCATTACH {
public:
PCATTACH();
~PCATTACH();
void PCattachInterrupt(uint8_t pin, void (*userFunc)(void), int mode);
void PCdetachInterrupt(uint8_t pin);
static void PCint(uint8_t);
/*
volatile uint8_t *port_to_pcmask[];
typedef void (*voidFuncPtr)(void);
volatile static voidFuncPtr PCintFunc[];
volatile static uint8_t PCintLast[];
*/
};

View File

@ -0,0 +1,2 @@
PCattachInterrupt KEYWORD2
PCdetachInterrupt KEYWORD2

View File

@ -0,0 +1,118 @@
#include <WIEGAND26.h>
extern byte reader1Pins[]; // Reader 1 connected to pins 4,5
extern byte reader2Pins[]; // Reader2 connected to pins 6,7
extern byte reader3Pins[]; // Reader3 connected to pins X,Y
extern long reader1;
extern int reader1Count;
extern long reader2;
extern int reader2Count;
extern long reader3;
extern int reader3Count;
WIEGAND26::WIEGAND26(){
}
WIEGAND26::~WIEGAND26(){
}
/* Wiegand Reader code. Modify as needed or comment out unused readers.
* system supports up to 3 independent readers.
*/
void WIEGAND26::initReaderOne(void) {
for(byte i=0; i<2; i++){
pinMode(reader1Pins[i], OUTPUT);
digitalWrite(reader1Pins[i], HIGH); // enable internal pull up causing a one
digitalWrite(reader1Pins[i], LOW); // disable internal pull up causing zero and thus an interrupt
pinMode(reader1Pins[i], INPUT);
digitalWrite(reader1Pins[i], HIGH); // enable internal pull up
}
delay(10);
reader1Count=0;
reader1=0;
}
void WIEGAND26::initReaderTwo(void) {
for(byte i=0; i<2; i++){
pinMode(reader2Pins[i], OUTPUT);
digitalWrite(reader2Pins[i], HIGH); // enable internal pull up causing a one
digitalWrite(reader2Pins[i], LOW); // disable internal pull up causing zero and thus an interrupt
pinMode(reader2Pins[i], INPUT);
digitalWrite(reader2Pins[i], HIGH); // enable internal pull up
}
delay(10);
reader2Count=0;
reader2=0;
}
void WIEGAND26::reader1One() {
if(digitalRead(reader1Pins[1]) == LOW){
reader1Count++;
reader1 = reader1 << 1;
reader1 |= 1;
}
}
void WIEGAND26::reader1Zero() {
if(digitalRead(reader1Pins[0]) == LOW){
reader1Count++;
reader1 = reader1 << 1;
}
}
void WIEGAND26::reader2One() {
if(digitalRead(reader2Pins[1]) == LOW){
reader2Count++;
reader2 = reader2 << 1;
reader2 |= 1;
}
}
void WIEGAND26::reader2Zero(void) {
if(digitalRead(reader2Pins[0]) == LOW){
reader2Count++;
reader2 = reader2 << 1;
}
}
void WIEGAND26::initReaderThree(void) {
for(byte i=0; i<2; i++){
pinMode(reader3Pins[i], OUTPUT);
digitalWrite(reader3Pins[i], HIGH); // enable internal pull up causing a one
digitalWrite(reader3Pins[i], LOW); // disable internal pull up causing zero and thus an interrupt
pinMode(reader3Pins[i], INPUT);
digitalWrite(reader3Pins[i], HIGH); // enable internal pull up
}
delay(10);
reader3Count=0;
reader3=0;
}
void WIEGAND26::reader3One(void) {
if(digitalRead(reader3Pins[1]) == LOW){
reader3Count++;
reader3 = reader3 << 1;
reader3 |= 1;
}
}
void WIEGAND26::reader3Zero(void) {
if(digitalRead(reader3Pins[0]) == LOW){
reader3Count++;
reader3 = reader3 << 1;
}
}

View File

@ -0,0 +1,36 @@
#ifndef _WIEGAND26_H_
#define _WIEGAND26_H_
#endif
#include <Arduino.h>
class WIEGAND26 {
public:
WIEGAND26();
~WIEGAND26();
//const byte reader1Pins[]; // Reader 1 connected to pins 4,5
//const byte reader2Pins[]; // Reader2 connected to pins 6,7
//const byte reader3Pins[]; // Reader3 connected to pins X,Y
//volatile long reader1;
//volatile int reader1Count;
//volatile long reader2;
//volatile int reader2Count;
//volatile long reader3;
//volatile int reader3Count;
void initReaderOne(void);
void initReaderTwo(void);
void reader1One(void);
void reader1Zero(void);
void reader2One(void);
void reader2Zero(void);
void initReaderThree(void);
void reader3One(void);
void reader3Zero(void);
private:
};

View File

@ -0,0 +1,9 @@
initReaderOne KEYWORD2
initReaderTwo KEYWORD2
reader1One KEYWORD2
reader1Zero KEYWORD2
reader2One KEYWORD2
reader2Zero KEYWORD2
initReaderThree KEYWORD2
reader3One KEYWORD2
reader3Zero KEYWORD2

41
user.h Normal file
View File

@ -0,0 +1,41 @@
/* User preferences file - Modify this header to use the correct options for your
* installation.
* Be sure to set the passwords/etc, as the defaul is "1234"
*/
/* Hardware options
*
*/
#define MCU328 // Set this if using any boards other than the "Mega"
#define HWV4STD // Use this option if using Open access v3 Standard board
#define MCPIOXP // Set this if using the v4 hardware with the MCP23017 i2c IO chip
//#define AT24EEPROM // Set this if you have the At24C i2c EEPROM chip installed
#define READER2KEYPAD 0 // Set this if your second reader has a keypad
/* Static user List - Implemented as an array for testing and access override
*/
//#define LCDBOARD // Uncomment to use LCD board
// Uses the "cLCD" library that extends arduino LCD class
// Has issues - must use a non-standard pinout, disables other MCP IO pins
// Library is from the TC4 Coffee Roaster project
// Download here: http://code.google.com/p/tc4-shield/
#define DEBUG 2 // Set to 4 for display of raw tag numbers in BIN, 3 for decimal, 2 for HEX, 1 for only denied, 0 for never.
#define VERSION 1.40
#define UBAUDRATE 9600 // Set the baud rate for the USB serial port
#define PRIVPASSWORD 0x1234 // Console "priveleged mode" password
#define DOORDELAY 5000 // How long to open door lock once access is granted. (2500 = 2.5s)
#define SENSORTHRESHOLD 100 // Analog sensor change that will trigger an alarm (0..255)
#define KEYPADTIMEOUT 5000 // Timeout for pin pad entry. Users on keypads can enter commands after reader swipe.
#define CARDFORMAT 1 // Card format
// 0=first 25 raw bytes from card
// 1=First and second parity bits stripped (default for most systems)
#define BEDTIME 23 // Set the time to automatically relock front door.
#define BEDTIME_ENABLED 0 // Determine whether or not to relock front door nightly