Click here to Skip to main content
15,886,799 members
Articles / Internet of Things / Arduino

Arduino Unleashed

Rate me:
Please Sign up or sign in to vote.
4.90/5 (19 votes)
18 Sep 2010CPOL8 min read 171.2K   678   40  
This article is all about empowering you with more powerful tools that let you unleash your creativity without being limited by the default IDE.
  • arduino.zip
    • Arduino
      • .metadata
        • .lock
        • .log
        • .mylyn
          • contexts
          • repositories.xml.zip
        • .plugins
          • de.innot.avreclipse.core
          • org.eclipse.cdt.core
          • org.eclipse.cdt.make.core
          • org.eclipse.cdt.managedbuilder.core
          • org.eclipse.cdt.ui
          • org.eclipse.core.resources
            • .history
              • 0
                • 90178f64a8c1001f13c7f5de4bcffe65
              • 11
                • 90c8cb7aaec1001f1a968c8925716fac
              • 15
                • e003e79caec1001f1a968c8925716fac
              • 16
                • 309eaa2aaac1001f1a968c8925716fac
                • b00fc1e8a7c1001f13c7f5de4bcffe65
              • 17
                • 303f0b1aaac1001f1a968c8925716fac
              • 19
                • 50db879ba9c1001f13c7f5de4bcffe65
                • b0822d6baac1001f1a968c8925716fac
              • 1a
                • a0d01b72aec1001f1a968c8925716fac
              • 1d
                • 9006869ba9c1001f13c7f5de4bcffe65
              • 2
                • 40805c37b3c1001f1a968c8925716fac
              • 24
                • 908eddbfafc1001f1a968c8925716fac
              • 25
                • 60a2bb77aec1001f1a968c8925716fac
              • 26
                • 709c0a3eadc1001f1a968c8925716fac
              • 29
                • b0563bbbafc1001f1a968c8925716fac
              • 2a
                • 50b68fbfa7c1001f13c7f5de4bcffe65
              • 2f
                • 609fb36eaec1001f1a968c8925716fac
              • 3
                • 00b2433ea6c1001f13c7f5de4bcffe65
              • 30
                • e0862b6baac1001f1a968c8925716fac
              • 31
                • e0f5edd5a9c1001f13c7f5de4bcffe65
              • 32
                • 40a6c07eaac1001f1a968c8925716fac
              • 33
                • 7066e74ab3c1001f1a968c8925716fac
                • 80265848a7c1001f13c7f5de4bcffe65
              • 34
                • 00eb51d6adc1001f1a968c8925716fac
              • 35
                • d05a5b48a7c1001f13c7f5de4bcffe65
                • e046fe19aac1001f1a968c8925716fac
              • 36
                • 20ed7c6ba8c1001f13c7f5de4bcffe65
              • 37
                • f03b866ba8c1001f13c7f5de4bcffe65
              • 39
                • 507dde20a9c1001f13c7f5de4bcffe65
              • 3b
                • a0b1ce97aec1001f1a968c8925716fac
              • 3d
                • 0063ef74aec1001f1a968c8925716fac
              • 3e
                • e0191572aec1001f1a968c8925716fac
              • 42
                • 80903869aac1001f1a968c8925716fac
              • 45
                • 10c140a1aec1001f1a968c8925716fac
              • 47
                • 3073473caec1001f1a968c8925716fac
              • 48
                • c0b85d37b3c1001f1a968c8925716fac
              • 4f
                • 70572f6baac1001f1a968c8925716fac
              • 50
                • 30083988b3c1001f1a968c8925716fac
              • 51
                • d0723269a6c1001f13c7f5de4bcffe65
              • 52
                • 902b1441b0c1001f1a968c8925716fac
              • 54
                • d06a4b3caec1001f1a968c8925716fac
              • 56
                • 002c6d00aac1001f13c7f5de4bcffe65
                • b00a8fbdafc1001f1a968c8925716fac
                • b09bbdc9a7c1001f13c7f5de4bcffe65
              • 57
                • b0f54422aac1001f1a968c8925716fac
              • 58
                • d077b7b2afc1001f1a968c8925716fac
              • 5a
                • d05d819faec1001f1a968c8925716fac
              • 5b
                • b0f4b977aec1001f1a968c8925716fac
              • 5c
                • 007bc27eaac1001f1a968c8925716fac
              • 5d
                • 40e5c897aec1001f1a968c8925716fac
                • 608adfbfafc1001f1a968c8925716fac
                • d013899ba9c1001f13c7f5de4bcffe65
              • 5e
                • c0b1af2db3c1001f1a968c8925716fac
              • 5f
                • 3048ecd5a9c1001f13c7f5de4bcffe65
              • 61
                • 404b5cd6adc1001f1a968c8925716fac
              • 67
                • 20740441b0c1001f1a968c8925716fac
              • 68
                • 20aee081aec1001f1a968c8925716fac
              • 6a
                • f0ee1a37a9c1001f13c7f5de4bcffe65
              • 6b
                • d06be49caec1001f1a968c8925716fac
              • 6c
                • 10595034b0c1001f1a968c8925716fac
              • 7
                • d076c47eaac1001f1a968c8925716fac
              • 70
                • 10503ea1aec1001f1a968c8925716fac
                • 30b3ee79a7c1001f13c7f5de4bcffe65
                • e06d6369a6c1001f13c7f5de4bcffe65
              • 71
                • f06556d4a9c1001f13c7f5de4bcffe65
              • 72
                • 40a2011aaac1001f1a968c8925716fac
              • 74
                • 00145534b0c1001f1a968c8925716fac
                • 70add097aec1001f1a968c8925716fac
              • 77
                • 50a0ae2db3c1001f1a968c8925716fac
                • 70271c37a9c1001f13c7f5de4bcffe65
              • 79
                • 20b07f9faec1001f1a968c8925716fac
              • 7a
                • 400092bfa7c1001f13c7f5de4bcffe65
                • 8051a52db3c1001f1a968c8925716fac
              • 7b
                • 703298bdafc1001f1a968c8925716fac
              • 7d
                • 006f493caec1001f1a968c8925716fac
                • 0087c57aaec1001f1a968c8925716fac
                • f063093eadc1001f1a968c8925716fac
              • 7f
                • d033043eadc1001f1a968c8925716fac
              • 80
                • a038c7c9a7c1001f13c7f5de4bcffe65
                • f03e3e22aac1001f1a968c8925716fac
              • 81
                • 402ade9caec1001f1a968c8925716fac
                • 809b876ba8c1001f13c7f5de4bcffe65
              • 84
                • 30698b4ea8c1001f13c7f5de4bcffe65
              • 85
                • 90b7c839aec1001f1a968c8925716fac
              • 87
                • 2040ed74aec1001f1a968c8925716fac
              • 8a
                • 004b6169a6c1001f13c7f5de4bcffe65
                • 60a34622aac1001f1a968c8925716fac
              • 8c
                • 70f2e59caec1001f1a968c8925716fac
              • 8d
                • c02f1241b0c1001f1a968c8925716fac
              • 8f
                • a05b95bfa7c1001f13c7f5de4bcffe65
                • e082e281aec1001f1a968c8925716fac
              • 93
                • 602ce681aec1001f1a968c8925716fac
              • 98
                • 5096829faec1001f1a968c8925716fac
              • 99
                • 309f4822aac1001f1a968c8925716fac
                • b0b13c88b3c1001f1a968c8925716fac
              • a
                • 50b47d9faec1001f1a968c8925716fac
              • a4
                • f04b5937b3c1001f1a968c8925716fac
              • a7
                • b077a4e3a7c1001f13c7f5de4bcffe65
                • c015c5c9a7c1001f13c7f5de4bcffe65
              • aa
                • 70c9a82aaac1001f1a968c8925716fac
              • ab
                • 40411937a9c1001f13c7f5de4bcffe65
                • 60a56b00aac1001f13c7f5de4bcffe65
              • ad
                • 30ea3d88b3c1001f1a968c8925716fac
                • c0125bd6adc1001f1a968c8925716fac
              • ae
                • 9088be77aec1001f1a968c8925716fac
                • b0205b37b3c1001f1a968c8925716fac
              • af
                • d02d5234b0c1001f1a968c8925716fac
              • b
                • 007b4155aac1001f1a968c8925716fac
              • b0
                • 10ec9ae1a7c1001f13c7f5de4bcffe65
              • b2
                • 00a8ed4ab3c1001f1a968c8925716fac
              • b4
                • 6066b6b2afc1001f1a968c8925716fac
              • b5
                • 00caa2e3a7c1001f13c7f5de4bcffe65
              • b9
                • 70880d57aac1001f1a968c8925716fac
              • bb
                • 00e5fa3dadc1001f1a968c8925716fac
                • 10ec7f9ba9c1001f13c7f5de4bcffe65
              • bc
                • 0062bfe8a7c1001f13c7f5de4bcffe65
                • 2077bd77aec1001f1a968c8925716fac
              • c1
                • b04742a1aec1001f1a968c8925716fac
                • e0480641b0c1001f1a968c8925716fac
              • c2
                • 1052e020a9c1001f13c7f5de4bcffe65
                • d008d497aec1001f1a968c8925716fac
              • c5
                • 10fc93bfa7c1001f13c7f5de4bcffe65
              • c6
                • 207294e3a7c1001f13c7f5de4bcffe65
              • c7
                • 40840f57aac1001f1a968c8925716fac
              • c8
                • 900a53d4a9c1001f13c7f5de4bcffe65
                • c0bc1057aac1001f1a968c8925716fac
              • c9
                • 40a743a1aec1001f1a968c8925716fac
                • d0cce481aec1001f1a968c8925716fac
              • ca
                • 3066bde8a7c1001f13c7f5de4bcffe65
              • cb
                • 908ae120a9c1001f13c7f5de4bcffe65
              • cc
                • c02d0a1aaac1001f1a968c8925716fac
                • f08df0d5a9c1001f13c7f5de4bcffe65
              • d0
                • 2085eb4ab3c1001f1a968c8925716fac
              • d3
                • 000c5248a7c1001f13c7f5de4bcffe65
              • d5
                • a08c0b57aac1001f1a968c8925716fac
              • d6
                • 80e0ee4ab3c1001f1a968c8925716fac
              • d8
                • 20d0e3bfafc1001f1a968c8925716fac
              • d9
                • b0f4a62aaac1001f1a968c8925716fac
                • f06d2b69a6c1001f13c7f5de4bcffe65
              • dc
                • c0aece7aaec1001f1a968c8925716fac
              • e0
                • 80db5334b0c1001f1a968c8925716fac
              • e1
                • 00c31337a9c1001f13c7f5de4bcffe65
              • e3
                • 8081dc20a9c1001f13c7f5de4bcffe65
              • e5
                • 507e1d72aec1001f1a968c8925716fac
              • e6
                • 704b50d4a9c1001f13c7f5de4bcffe65
              • e7
                • 106559d6adc1001f1a968c8925716fac
              • e8
                • c0006f00aac1001f13c7f5de4bcffe65
                • c037f174aec1001f1a968c8925716fac
              • e9
                • a091b4b2afc1001f1a968c8925716fac
              • ea
                • 408e846ba8c1001f13c7f5de4bcffe65
              • eb
                • c08496bdafc1001f1a968c8925716fac
              • ec
                • 702d55d4a9c1001f13c7f5de4bcffe65
              • f1
                • b019ad2db3c1001f1a968c8925716fac
                • f0dc3a88b3c1001f1a968c8925716fac
              • f4
                • 50225a48a7c1001f13c7f5de4bcffe65
              • f7
                • 4076cd7aaec1001f1a968c8925716fac
              • f8
                • b0d6ab2aaac1001f1a968c8925716fac
              • fb
                • 10fda6b2afc1001f1a968c8925716fac
            • .projects
              • Arduino
                • .indexes
                  • 19
                    • history.index
                  • 33
                    • history.index
                  • af
                    • history.index
                  • history.index
                  • properties.index
                • .markers
              • BlinkenLights
                • .indexes
                  • 19
                    • history.index
                  • 33
                    • history.index
                  • af
                    • history.index
                  • history.index
                  • properties.index
            • .root
              • .indexes
                • history.version
                • properties.index
                • properties.version
              • 3.tree
            • .safetable
              • org.eclipse.core.resources
          • org.eclipse.core.runtime
          • org.eclipse.debug.core
          • org.eclipse.debug.ui
          • org.eclipse.epp.usagedata.recording
          • org.eclipse.equinox.p2.ui
          • org.eclipse.ltk.core.refactoring
          • org.eclipse.mylyn.bugzilla.core
          • org.eclipse.mylyn.tasks.ui
          • org.eclipse.team.cvs.core
          • org.eclipse.ui.intro
          • org.eclipse.ui.workbench
        • version.ini
      • Arduino
      • BlinkenLights
/*
  wiring_pulse.c - pulseIn() function
  Part of Arduino - http://www.arduino.cc/

  Copyright (c) 2005-2006 David A. Mellis

  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., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/

#include "wiring_private.h"
#include "pins_arduino.h"

/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
 * or LOW, the type of pulse to measure.  Works on pulses from 2-3 microseconds
 * to 3 minutes in length, but must be called at least a few dozen microseconds
 * before the start of the pulse. */
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
{
	// cache the port and bit of the pin in order to speed up the
	// pulse width measuring loop and achieve finer resolution.  calling
	// digitalRead() instead yields much coarser resolution.
	uint8_t bit = digitalPinToBitMask(pin);
	uint8_t port = digitalPinToPort(pin);
	uint8_t stateMask = (state ? bit : 0);
	unsigned long width = 0; // keep initialization out of time critical area
	
	// convert the timeout from microseconds to a number of times through
	// the initial loop; it takes 16 clock cycles per iteration.
	unsigned long numloops = 0;
	unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
	
	// wait for any previous pulse to end
	while ((*portInputRegister(port) & bit) == stateMask)
		if (numloops++ == maxloops)
			return 0;
	
	// wait for the pulse to start
	while ((*portInputRegister(port) & bit) != stateMask)
		if (numloops++ == maxloops)
			return 0;
	
	// wait for the pulse to stop
	while ((*portInputRegister(port) & bit) == stateMask)
		width++;

	// convert the reading to microseconds. The loop has been determined
	// to be 10 clock cycles long and have about 16 clocks between the edge
	// and the start of the loop. There will be some error introduced by
	// the interrupt handlers.
	return clockCyclesToMicroseconds(width * 10 + 16); 
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NVIDIA India
India India
I am a software engineer by profession and an electronics engineer by education. Used to be (and still am) a hobby programmer, an electronics enthusiast/DIYer etc.

Some areas which interest me are...compiler construction, operating systems, robotics, science in general etc

Comments and Discussions