tag:blogger.com,1999:blog-49016168065454340042024-03-06T01:04:59.142-08:00arduinoPedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.comBlogger24125tag:blogger.com,1999:blog-4901616806545434004.post-8188262439062236402013-12-23T02:42:00.002-08:002013-12-23T02:42:38.976-08:00Logo email<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8TfFXUcA9JQsyC5StqLn86fQldjSsZVczqH3jI4yG8OhliTsXcxrfHlsxM8jCZrc7Y02sVDSIC5skeP51gNobsIE5-oKeDdxLI4_f5YfalVbJkR6N3UbdOhKw29FGuRRmmzLyNJJibkL4/s1600/logo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="69" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8TfFXUcA9JQsyC5StqLn86fQldjSsZVczqH3jI4yG8OhliTsXcxrfHlsxM8jCZrc7Y02sVDSIC5skeP51gNobsIE5-oKeDdxLI4_f5YfalVbJkR6N3UbdOhKw29FGuRRmmzLyNJJibkL4/s320/logo.png" width="320" /></a></div>
<br />Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-5040299991022707862012-02-07T19:19:00.001-08:002012-02-07T19:19:44.315-08:00Control Structures goto<h2>goto</h2>Transfers program flow to a labeled point in the program <br />
<h4>Syntax</h4>label: <br />
goto label; // sends program flow to the label <br />
<h4>Tip</h4>The use of <em>goto</em> is discouraged in C programming, and some authors of C programming books claim that the <em>goto</em> statement is never necessary, but used judiciously, it can simplify certain programs. The reason that many programmers frown upon the use of <em>goto</em> is that with the unrestrained use of <em>goto</em> statements, it is easy to create a program with undefined program flow, which can never be debugged. <br />
With that said, there are instances where a goto statement can come in handy, and simplify coding. One of these situations is to break out of deeply nested <em>for</em> loops, or <em>if</em> logic blocks, on a certain condition. <br />
<h4>Example</h4><pre>for(byte r = 0; r < 255; r++){
for(byte g = 255; g > -1; g--){
for(byte b = 0; b < 255; b++){
if (analogRead(0) > 250){ goto bailout;}
// more statements ...
}
}
}
bailout:
<a href="http://arduino.cc/en/Reference/Goto">References</a></pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-86054853742266137162012-02-07T19:17:00.000-08:002012-02-07T19:17:57.765-08:00Control Structures return<h2>return</h2>Terminate a function and return a value from a function to the calling function, if desired. <br />
<h4>Syntax:</h4>return; <br />
return value; // both forms are valid <br />
<h4>Parameters</h4>value: any variable or constant type <br />
<h4>Examples:</h4>A function to compare a sensor input to a threshold <br />
<pre>int checkSensor(){
if (analogRead(0) > 400) {
return 1;
else{
return 0;
}
}
</pre>The return keyword is handy to test a section of code without having to "comment out" large sections of possibly buggy code. <br />
<pre>void loop(){
// brilliant code idea to test here
return;
// the rest of a dysfunctional sketch here
// this code will never be executed
}
</pre><h4>See also</h4><a class="wikilink" href="http://arduino.cc/en/Reference/Comments">comments</a><br />
<br />
<a href="http://arduino.cc/en/Reference/Return">References </a>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-11622018194308714772012-02-07T19:15:00.000-08:002012-02-07T19:15:58.657-08:00Control Structures continue<h2>continue</h2>The continue statement skips the rest of the current iteration of a loop (<strong>do</strong>, <strong>for</strong>, or <strong>while</strong>). It continues by checking the conditional expression of the loop, and proceeding with any subsequent iterations. <br />
<h4>Example</h4><pre>for (x = 0; x < 255; x ++)
{
if (x > 40 && x < 120){ // create jump in values
continue;
}
digitalWrite(PWMpin, x);
delay(50);
}
<a href="http://arduino.cc/en/Reference/Continue">References</a></pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-34069490279920498272012-02-07T19:13:00.000-08:002012-02-07T19:13:04.525-08:00Control Structures break<h2>break</h2><strong>break</strong> is used to exit from a <strong>do</strong>, <strong>for</strong>, or <strong>while</strong> loop, bypassing the normal loop condition. It is also used to exit from a <strong>switch</strong> statement. <br />
<h4>Example</h4><pre>for (x = 0; x < 255; x ++)
{
digitalWrite(PWMpin, x);
sens = analogRead(sensorPin);
if (sens > threshold){ // bail out on sensor detect
x = 0;
break;
}
delay(50);
}
<a href="http://arduino.cc/en/Reference/Break">References</a></pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-4607124806027610192012-02-07T19:11:00.000-08:002012-02-07T19:11:14.218-08:00Control Structures do... while<h2>do - while</h2>The <strong>do</strong> loop works in the same manner as the <strong>while</strong> loop, with the exception that the condition is tested at the end of the loop, so the <strong>do</strong> loop will <em>always</em> run at least once. <br />
<pre>do
{
// statement block
} while (test condition);
</pre><h4>Example</h4><pre>do
{
delay(50); // wait for sensors to stabilize
x = readSensors(); // check the sensors
} while (x < 100);
<a href="http://arduino.cc/en/Reference/DoWhile">References</a></pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-74765194775431472482012-02-07T19:03:00.000-08:002012-02-07T19:04:12.417-08:00Control Structures while<h2>while loops</h2><h4>Description</h4><b>while</b> loops will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. Something must change the tested variable, or the <b>while</b> loop will never exit. This could be in your code, such as an incremented variable, or an external condition, such as testing a sensor. <br />
<h4>Syntax</h4><pre>while(expression){
// statement(s)
}
</pre><h4>Parameters</h4>expression - a (boolean) C statement that evaluates to true or false <br />
<h4>Example</h4><pre>var = 0;
while(var < 200){
// do something repetitive 200 times
var++;
}
<a href="http://arduino.cc/en/Reference/While">References</a></pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-56921873023733537732012-02-07T19:01:00.000-08:002012-02-07T19:01:23.834-08:00Control Structures switch case<h2>switch / case statements</h2>Like <strong>if</strong> statements, <strong>switch...case</strong> controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. <br />
The <strong>break</strong> keyword exits the switch statement, and is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break, or the end of the switch statement is reached. <br />
<h3>Example</h3><pre>switch (var) {
case 1:
//do something when var equals 1
break;
case 2:
//do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
}
</pre><h3>Syntax</h3><pre>switch (var) {
case label:
// statements
break;
case label:
// statements
break;
default:
// statements
}
</pre><h3>Parameters</h3>var: the variable whose value to compare to the various cases <br />
label: a value to compare the variable to <br />
<h4>See also:</h4><a class="wikilink" href="http://arduino.cc/en/Reference/Else">if...else</a> <a class="wikilink" href="http://arduino.cc/en/Reference/HomePage">Reference Home</a><br />
<br />
<a href="http://arduino.cc/en/Reference/SwitchCase">References </a>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-28329326255181909172012-02-07T18:58:00.000-08:002012-02-07T18:58:34.031-08:00Control Structures for<h2>for statements</h2><h4>Desciption</h4>The <strong>for</strong> statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The <strong>for</strong> statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins. <br />
There are three parts to the <strong>for</strong> loop header: <br />
<code><strong>for</strong> (<strong>initialization</strong>;<strong> condition</strong>;<strong> increment</strong>) {</code> <br />
<code> //statement(s);</code> <br />
<code>}</code> <br />
<div><img alt="" height="220px" src="http://arduino.cc/en/uploads/Reference/ForLoopIllustrated.png" title="" /></div>The <strong>initialization</strong> happens first and exactly once. Each time through the loop, the <strong>condition</strong> is tested; if it's true, the statement block, and the <strong>increment</strong> is executed, then the <strong>condition</strong> is tested again. When the <strong>condition</strong> becomes false, the loop ends. <br />
<h4>Example</h4><pre>// Dim an LED using a PWM pin
int PWMpin = 10; // LED in series with 470 ohm resistor on pin 10
void setup()
{
// no setup needed
}
void loop()
{
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}
}
</pre><h4>Coding Tips</h4>The C <strong>for</strong> loop is much more flexible than <strong>for</strong> loops found in some other computer languages, including BASIC. Any or all of the three header elements may be omitted, although the semicolons are required. Also the statements for initialization, condition, and increment can be any valid C statements with unrelated variables, and use any C datatypes including floats. These types of unusual <strong>for</strong> statements may provide solutions to some rare programming problems. <br />
For example, using a multiplication in the increment line will generate a logarithmic progression:<br />
<br />
<pre>for(int x = 2; x < 100; x = x * 1.5){
println(x);
}
</pre>Generates: 2,3,4,6,9,13,19,28,42,63,94 <br />
Another example, fade an LED up and down with one <strong>for</strong> loop: <br />
<pre>void loop()
{
int x = 1;
for (int i = 0; i > -1; i = i + x){
analogWrite(PWMpin, i);
if (i == 255) x = -1; // switch direction at peak
delay(10);
}
}
</pre><h4>See also</h4><ul><li><a class="wikilink" href="http://arduino.cc/en/Reference/While">while</a><br />
<br />
<a href="http://arduino.cc/en/Reference/For">References </a> </li>
</ul>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-65504818324154013642012-02-07T18:49:00.000-08:002012-02-07T18:49:02.882-08:00Control Structures if... else<h2>if / else</h2><strong>if/else</strong> allows greater control over the flow of code than the basic <strong>if</strong> statement, by allowing multiple tests to be grouped together. For example, an analog input could be tested and one action taken if the input was less than 500, and another action taken if the input was 500 or greater. The code would look like this: <br />
<pre>if (pinFiveInput < 500)
{
// action A
}
else
{
// action B
}
</pre><strong>else</strong> can proceed another <strong>if</strong> test, so that multiple, mutually exclusive tests can be run at the same time. <br />
Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction. If no test proves to be true, the default <strong>else</strong> block is executed, if one is present, and sets the default behavior. <br />
Note that an <strong>else if</strong> block may be used with or without a terminating <strong>else</strong> block and vice versa. An unlimited number of such <strong>else if</strong> branches is allowed. <br />
<pre>if (pinFiveInput < 500)
{
// do Thing A
}
else if (pinFiveInput >= 1000)
{
// do Thing B
}
else
{
// do Thing C
}
</pre>Another way to express branching, mutually exclusive tests, is with the <a class="wikilink" href="http://arduino.cc/en/Reference/SwitchCase">switch case</a> statement. <br />
<h4>See also:</h4><a class="wikilink" href="http://arduino.cc/en/Reference/SwitchCase">switch case</a> <a class="wikilink" href="http://arduino.cc/en/Reference/HomePage">Reference Home</a><br />
<br />
<a href="http://arduino.cc/en/Reference/Else">References</a> Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-40544981978673662692012-02-07T18:45:00.000-08:002012-02-07T18:45:42.640-08:00Control Structures if<h2>if (conditional) and ==, !=, <, > (comparison operators)</h2><strong><code>if</code></strong>, which is used in conjunction with a comparison operator, tests whether a certain condition has been reached, such as an input being above a certain number. The format for an if test is: <br />
<pre>if (someVariable > 50)
{
// do something here
}
</pre>The program tests to see if someVariable is greater than 50. If it is, the program takes a particular action. Put another way, if the statement in parentheses is true, the statements inside the brackets are run. If not, the program skips over the code. <br />
The brackets may be omitted after an <em>if</em> statement. If this is done, the next line (defined by the semicolon) becomes the only conditional statement. <br />
<pre>if (x > 120) digitalWrite(LEDpin, HIGH);
if (x > 120)
digitalWrite(LEDpin, HIGH);
if (x > 120){ digitalWrite(LEDpin, HIGH); }
if (x > 120){
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, HIGH);
} // all are correct
</pre>The statements being evaluated inside the parentheses require the use of one or more operators: <br />
<h3>Comparison Operators:</h3><pre><strong>x == y</strong> (x is equal to y)
<strong>x != y</strong> (x is not equal to y)
<strong>x < y</strong> (x is less than y)
<strong>x > y</strong> (x is greater than y)
<strong>x <= y</strong> (x is less than or equal to y)
<strong>x >= y</strong> (x is greater than or equal to y)
</pre><h4>Warning: </h4>Beware of accidentally using the single equal sign (e.g.<code> if (x = 10)</code> ). The single equal sign is the assignment operator, and sets x to 10 (puts the value 10 into the variable x). Instead use the double equal sign (e.g.<code> if (x == 10) </code>), which is the comparison operator, and tests <em>whether</em> x is equal to 10 or not. The latter statement is only true if x equals 10, but the former statement will always be true. <br />
This is because C evaluates the statement <code> if (x=10) </code> as follows: 10 is assigned to x (remember that the single equal sign is the <a class="wikilink" href="http://arduino.cc/en/Reference/Assignment">assignment operator</a>), so x now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to TRUE, since any non-zero number evaluates to TRUE. Consequently, <code>if (x = 10)</code> will always evaluate to TRUE, which is not the desired result when using an 'if' statement. Additionally, the variable x will be set to 10, which is also not a desired action. <br />
<strong>if</strong> can also be part of a branching control structure using the <a class="wikilink" href="http://arduino.cc/en/Reference/Else">if...else</a>] construction.<br />
<a href="http://arduino.cc/en/Reference/If">References</a>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-25856583878591835182012-02-07T18:42:00.000-08:002012-02-07T18:42:31.940-08:00Language Reference : Structure loop ()<h1>loop()</h1>After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board. <br />
<h3>Example</h3><pre>int buttonPin = 3;
// setup initializes serial and the button pin
void setup()
{
beginSerial(9600);
pinMode(buttonPin, INPUT);
}
// loop checks the button pin each time,
// and will send serial if it is pressed
void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite('H');
else
serialWrite('L');
delay(1000);
}
<a href="http://arduino.cc/en/Reference/Loop">Reference</a>
</pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-84457570397987675452012-02-07T18:39:00.000-08:002012-02-07T18:39:31.583-08:00Language Reference : Structure setup ()<h2>setup()</h2>The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board. <br />
<h3>Example</h3><pre>int buttonPin = 3;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop()
{
// ...
}
<a href="http://arduino.cc/en/Reference/HomePage">References</a>
</pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-37981173052084557002011-08-12T09:42:00.000-07:002011-08-12T09:42:19.713-07:00Arduino Interrupts<div id="wikitext"> <span class="wikiword"></span><br />
<span class="wikiword">MsTimer2</span> is a small and very easy to use library to interface Timer2 with humans. It's called <span class="wikiword">MsTimer2</span> because it "hardcodes" a resolution of 1 millisecond on timer2. <br />
UPDATED: <br />
<ul><li>works on <span class="wikiword">ATmega1280</span> (thanks to Manuel Negri). </li>
<li>works on <span class="wikiword">ATmega328</span> (thanks Jerome Despatis). </li>
<li>works on <span class="wikiword">ATmega48</span>/88/168 and <span class="wikiword">ATmega128</span>/8. </li>
</ul><h3>Methods</h3><dl><dt><span class="wikiword">MsTimer2</span>::set(unsigned long ms, void (*f)()) </dt>
<dd>this function sets a time on ms for the overflow. Each overflow, "f" will be called. "f" has to be declared void with no parameters. </dd>
<dt><span class="wikiword">MsTimer2</span>::start() </dt>
<dd>enables the interrupt. </dd>
<dt><span class="wikiword">MsTimer2</span>::stop() </dt>
<dd>disables the interrupt. </dd></dl><h3>Source code</h3>License: LGPL <br />
<a class="urllink" href="http://www.arduino.cc/playground/uploads/Main/MsTimer2.zip" rel="nofollow">MsTimer2.zip</a> <br />
Install it on {arduino-path}/hardware/libraries/ <br />
<h3>Compile Ubuntu 11.04</h3><h3> <span style="font-size: small; font-weight: normal;"><span style="font-family: inherit;">First , root mode</span></span><i><span style="font-family: inherit; font-weight: normal;"><br />
<span style="font-family: Arial,Helvetica,sans-serif;"></span></span></i><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"><span style="font-size: small;"><span style="font-weight: normal;">sudo su</span></span></span></span></h3><h3><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"><span style="font-size: small;"><span style="font-weight: normal;"><br />
</span></span></span></span><span style="font-family: inherit; font-weight: normal;">Unzip MsTimer2.zip</span></h3><h3><i><span style="font-family: inherit; font-weight: normal;"><span style="font-family: Arial,Helvetica,sans-serif;"></span></span></i><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"><span style="font-size: small;"><span style="font-weight: normal;"> unzip MsTimer2.zip</span></span></span></span><i><span style="font-family: inherit; font-weight: normal;"><br />
</span></i><span style="font-family: inherit; font-weight: normal;">Copy MsTimer2 from /usr/share/arduino/libraries<br />
<span style="font-family: Arial,Helvetica,sans-serif;"></span></span><span style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"><span style="font-size: small;"><span style="font-weight: normal;">cp -r MsTimer2.zip /usr/share/arduino/libraries</span></span></span></span><i style="font-family: Arial,Helvetica,sans-serif;"><span style="color: black;"><span style="font-size: small;"><span style="font-weight: normal;"><br />
</span></span></span></i><span class="short_text" id="result_box" lang="en" style="font-family: Arial,Helvetica,sans-serif;"><span class="hps"> </span></span></h3><h3><u><i><span class="short_text" id="result_box" lang="en"><span class="hps">Ready</span><span class="">,</span> <span class="hps">examples</span> <span class="hps">are already in</span> <span class="hps">default,in</span> <span class="hps">the</span> <span class="hps">ide</span></span></i></u></h3><h3><span style="color: black;"><span style="font-size: small;"><span style="font-family: inherit; font-weight: normal;"> </span><i><span style="font-family: inherit; font-weight: normal;"> </span></i><span style="font-family: inherit;"> </span></span></span></h3><h3>Example</h3><pre>// Toggle LED on pin 13 each second
#include <mstimer2.h>
void flash() {
static boolean output = HIGH;
digitalWrite(13, output);
output = !output;
}
void setup() {
pinMode(13, OUTPUT);
MsTimer2::set(500, flash); // 500ms period
MsTimer2::start();
}
void loop() {
}
</mstimer2.h></pre><h3>Bugs</h3>send any bug to javiervalencia80 [at] gmail.com<br />
<br />
<a href="http://www.arduino.cc/playground/Main/MsTimer2">References </a><br />
<br />
</div>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-27326110280684513962010-04-01T19:21:00.000-07:002010-04-01T19:21:25.153-07:00PAPERduino’s design<div class="entry-date"><span class="meta-sep">{</span> <abbr class="published" title="2009-05-06T17:08:19+0000">2009 05 06</abbr> <span class="meta-sep">}</span></div><h2 class="entry-title">PAPERduino’s design</h2><div class="entry-content"> This is a fully functional version of the Arduino. We eliminated the PCB and use paper and cardboard as support and the result is.. the PAPERduino :D<br />
This is the the first version of the layout design, next we will try more designs, and another materials. You just need to print the top and the bottom layout, and glue them to any kind of support you want. We hope that you start making your own boards. If you do, please share your photos with us, we would love to see them ;)<br />
There is no USB direct connection, so to program the paperduino you will need some kind of FTDI cable or adapter. One of this products will be fine:<br />
<a href="http://www.adafruit.com/index.php?main_page=product_info&cPath=18&products_id=70">FTDI cable</a> from Adafruit Industries<br />
<a href="http://www.sparkfun.com/commerce/product_info.php?products_id=9115">FTDI adapter</a> from Sparkfun<br />
<img alt="" src="http://farm4.static.flickr.com/3653/3507622765_a18cac9288.jpg?v=0" /><br />
<strong><a href="http://guilhermemartins.net/lab_files/paperduino.pdf">Download PDF</a></strong><br />
Components list:<br />
1 x 7805 Voltage regulator<br />
2 x LEDs (different colors)<br />
2 x 560 Ohm resistors (between 220oHm and 1K)<br />
1 x 10k Ohm resistor<br />
2 x 100 uF capacitors<br />
1x 16 MHz clock crystal<br />
2 x 22 pF capacitors<br />
1 x 0.01 uF capacitor<br />
1 x button<br />
1 x Atmel ATMega168<br />
1 x socket 28 pin<br />
Female and Male headers<br />
<a href="http://www.flickr.com/photos/guibot/3507287339/sizes/o/in/set-72157617758151682/"><img alt="" class="alignnone" height="375" src="http://farm4.static.flickr.com/3405/3507287339_ae34d2aff1.jpg?v=0" width="500" /></a><br />
<a href="http://www.flickr.com/photos/guibot/3507321983/sizes/o/"><img alt="" class="alignnone" height="264" src="http://farm4.static.flickr.com/3554/3507321983_2858584052.jpg?v=0" width="500" /></a><br />
<strong>Instructions:</strong><br />
Use a needle to puncture the holes for your components.<br />
<img alt="" class="alignnone" height="375" src="http://farm4.static.flickr.com/3551/3508361680_d5acc17b97.jpg?v=0" width="500" /><br />
Don’t rush, place one component after another and do all the solder work carefully.<br />
<img alt="" class="alignnone" height="375" src="http://farm4.static.flickr.com/3394/3508371334_7e6e222596.jpg?v=0" width="500" /><br />
Follow the connection lines.<br />
<img alt="" class="alignnone" height="375" src="http://farm4.static.flickr.com/3388/3507563103_9848e7456f.jpg?v=0" width="500" /><br />
And this should be the final look of your paperduino connections.<img alt="" class="alignnone" height="375" src="http://farm4.static.flickr.com/3390/3508341324_dd69c50be5.jpg?v=0" width="500" /><br />
<strong>PAPERduino for ALL</strong><br />
<a href="http://www.google.com/search?q=paperduino&hl=en&client=opera&rls=en&start=0&sa=N">http://www.google.com/search?client=opera&rls=en&q=paperduino&sourceid=opera&ie=utf-8&oe=utf-8</a><br />
<a href="http://blog.makezine.com/archive/2009/05/paperduino.html?CMP=OTC-0D6B489...">http://blog.makezine.com/archive/2009/05/paperduino.html?CMP=OTC-0D6B489…</a><br />
<a href="http://gizmodo.com/5248824/paperduino-combines-circuit-boards-with-paint...">http://gizmodo.com/5248824/paperduino-combines-circuit-boards-with-paint…</a><br />
<a href="http://dailydiy.com/2009/05/11/paperduino/">http://dailydiy.com/2009/05/11/paperduino/</a><br />
<a href="http://www.freeduino.org/index.html">http://www.freeduino.org/index.html</a> (with 2 stars)<br />
<a href="http://search.twitter.com/search?q=paperduino">http://search.twitter.com/search?q=paperduino</a><br />
<a href="http://www.engadget.com/2009/05/11/paperduino-is-like-the-cardboard-fort-version-of-every-hackers/">http://www.engadget.com/2009/05/11/paperduino-is-like-the-cardboard-fort-version-of-every-hackers/ </a><br />
and more..<br />
<a href="http://theawesomer.com/paperduino/13281/">http://theawesomer.com/paperduino/13281/</a><br />
<a href="http://es.makezine.com/archive/2009/05/paperduino_el_arduino_de_papel.html">http://es.makezine.com/archive/2009/05/paperduino_el_arduino_de_papel.html</a><br />
<a href="http://jmsarduino.blogspot.com/2009/05/paperduino-hifiduino.html">http://jmsarduino.blogspot.com/2009/05/paperduino-hifiduino.html</a><br />
fonte :<a href="http://lab.guilhermemartins.net/paperduino-prints/" target="_blank">http://lab.guilhermemartins.net/paperduino-prints/ </a><br />
<br />
tags : Arduino, PaperDuino, Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino <br />
<br />
</div><span class="entry-published"></span>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-36325987816094797712010-03-24T18:58:00.000-07:002010-03-24T18:58:32.826-07:00SPlaying tones on Multiple outputs using the tone() function<em>Examples > Digital I/O</em> <br />
<h2><span class="wikiword">SPlaying</span> tones on Multiple outputs using the tone() function</h2>This example shows how to use the tone() command to play different notes on multiple outputs. <br />
The tone() command works by taking over one of the Atmega's internal timers, setting it to the frequency you want, and using the timer to pulse an output pin. Since it's only using one timer, you can only play one note at a time. You can, however, play notes on multiple pins sequentially. To do this, you need to turn the timer off for one pin before moving on to the next. <br />
Thanks to Greg Borenstein for clarifying this. <br />
<h3>Circuit</h3><div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/arduino_3_speakers_bb.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/arduino_3_speakers_bb.png" title="" /></a></div><span style="font-size: 83%;">image developed using <a class="urllink" href="http://www.fritzing.org/" rel="nofollow">Fritzing</a>. For more circuit examples, see the <a class="urllink" href="http://fritzing.org/projects/" rel="nofollow">Fritzing project page</a> </span> <br />
<strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/arduino_3_speakers_schem.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/arduino_3_speakers_schem.png" title="" /></a></div><h3>Code</h3>The sketch below plays a tone on each of the speakers in sequence, turning off the previous speaker first. Note that the duration of each tone is the same as the delay that follows it. <br />
Here's the main sketch:<br />
<pre id="line1">/*
Multiple tone player
Plays multiple tones on multiple pins in sequence
circuit:
* 3 8-ohm speaker on digital pins 6, 7, and 11
created 8 March 2010
by Tom Igoe
based on a snippet from Greg Borenstein
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone4
*/
void setup() {
}
void loop() {
// turn off tone function for pin 11:
noTone(11);
// play a note on pin 6 for 200 ms:
tone(6, 440, 200);
delay(200);
// turn off tone function for pin 6:
noTone(6);
// play a note on pin 7 for 500 ms:
tone(7, 494, 500);
delay(500);
// turn off tone function for pin 7:
noTone(7);
// play a note on pin 11 for 500 ms:
tone(11, 523, 300);
delay(300);</pre><pre id="line1">}</pre><pre id="line1"></pre><pre id="line1">fonte : <a href="http://arduino.cc/en/Tutorial/Tone4">http://arduino.cc/en/Tutorial/Tone4</a></pre><pre id="line1">tags : Arduino,SPlaying tones on Multiple outputs using the tone() function , Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino </pre><!--[if !IE]> Firefox and others will use outer object -->Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-56316154803542188482010-03-24T18:47:00.000-07:002010-03-24T18:47:57.224-07:00Simple keyboard using the tone() function<em>Examples > Digital I/O</em> <br />
<h2>Simple keyboard using the tone() function</h2>This example shows how to use the tone() command to generate different pitches depending on which sensor is pressed. <br />
<h3>Circuit</h3><div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/arduino_fsrs_speaker_bb.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/arduino_fsrs_speaker_bb.png" title="" /></a></div><span style="font-size: 83%;">image developed using <a class="urllink" href="http://www.fritzing.org/" rel="nofollow">Fritzing</a>. For more circuit examples, see the <a class="urllink" href="http://fritzing.org/projects/" rel="nofollow">Fritzing project page</a> </span> <br />
<strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/arduino_fsrs_speaker_schem.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/arduino_fsrs_speaker_schem.png" title="" /></a></div><h3>Code</h3>The sketch below reads three analog sensors. Each corresponds to a note value in an array of notes. IF any of the sensors is above a given threshold, the corresponding note is played. <br />
The sketch uses an extra file, pitches.h. This file contains all the pitch values for typical notes. For example, NOTE_C4 is middle C. NOTE_FS4 is F sharp, and so forth. This note table was originally written by Brett Hagman, on whose work the tone() command was based. You may find it useful for whenever you want to make musical notes. <br />
To make this file, click on the "new Tab" button in the upper right hand corner of the window. It looks like this: <br />
<div><img alt="" src="http://arduino.cc/en/uploads/Tutorial/newTab.png" title="" /></div>The paste in the following code:<br />
<br />
<a name='more'></a><br />
<pre id="line1">/*************************************************
* Public Constants
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978</pre><pre id="line1"> </pre><pre id="line1"></pre><pre id="line1">Here's the main sketch : </pre><pre id="line1">/*
keyboard
Plays a pitch that changes based on a changing analog input
circuit:
* 3 force-sensing resistors from +5V to analog in 0 through 5
* 3 10K resistors from analog in 0 through 5 to ground
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone3
*/
#include "pitches.h"
const int threshold = 10; // minimum reading of the sensors that generates a note
// notes to play, corresponding to the 3 sensors:
int notes[] = {
NOTE_A4, NOTE_B4,NOTE_C3 };
void setup() {
}
void loop() {
for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
// get a sensor reading:
int sensorReading = analogRead(thisSensor);
// if the sensor is pressed hard enough:
if (sensorReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[thisSensor], 20);
}
}
Serial.println();
}</pre><pre id="line1">fonte : <a href="http://arduino.cc/en/Tutorial/Tone3">http://arduino.cc/en/Tutorial/Tone3</a></pre><pre id="line1">tags : Arduino,Simple keyboard using the tone() function, Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino </pre><pre id="line1"></pre><pre id="line1"></pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-84170374277161558172010-03-24T18:43:00.000-07:002010-03-24T18:43:04.532-07:00Pitch follower using the tone() function<em>Examples > Digital I/O</em> <br />
<h2>Pitch follower using the tone() function</h2>This example shows how to use the tone() command to generate a pitch that follows the values of an analog input <br />
<h3>Circuit</h3><div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/arduino_speaker_photocell_bb.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/arduino_speaker_photocell_bb.png" title="" /></a></div><span style="font-size: 83%;">image developed using <a class="urllink" href="http://www.fritzing.org/" rel="nofollow">Fritzing</a>. For more circuit examples, see the <a class="urllink" href="http://fritzing.org/projects/" rel="nofollow">Fritzing project page</a> </span> <br />
<strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/arduino_speaker_photocell_schem.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/arduino_speaker_photocell_schem.png" title="" /></a></div><h3>Code</h3>The code for this example is very simple. Just take an analog input and map its values to a range of audible pitches. Humans can hear from 20 - 20,000Hz, but 100 - 1000 usually works pretty well for this sketch. <br />
You'll need to get the actual range of your analog input for the mapping. In the circuit shown, the analog input value ranged from about 400 to about 1000. Change the values in the map() comand to match the range for your sensor. <br />
The sketch is as follows:<br />
<pre id="line1">/*
Pitch follower
Plays a pitch that changes based on a changing analog input
circuit:
* 8-ohm speaker on digital pin 8
* photoresistor on analog 0 to 5V
* 4.7K resistor on analog 0 to ground
created 21 Jan 2010
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone2
*/
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the pitch to the range of the analog input.
// change the minimum and maximum input numbers below
// depending on the range your sensor's giving:
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
// play the pitch:
tone(8, thisPitch, 10);
}</pre><pre id="line1"><a name='more'></a>fonte : <a href="http://arduino.cc/en/Tutorial/Tone2">http://arduino.cc/en/Tutorial/Tone2</a>
tags : Arduino, Pedro Ernesto Scotton, Pedro Scotton, Pitch follower using the tone() function, Starter Arduino
</pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-38082921730033147662010-03-24T18:38:00.000-07:002010-03-24T18:38:08.306-07:00Play Melody using the tone() function<em>Examples > Digital I/O</em> <br />
<h2>Play Melody using the tone() function</h2>This example shows how to use the tone() command to generate notes. It plays a little melody you may have heard before. <br />
<h3>Circuit</h3><div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/speaker_bb.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/speaker_bb.png" title="" /></a></div><span style="font-size: 83%;">image developed using <a class="urllink" href="http://www.fritzing.org/" rel="nofollow">Fritzing</a>. For more circuit examples, see the <a class="urllink" href="http://fritzing.org/projects/" rel="nofollow">Fritzing project page</a> </span> <br />
<strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/speaker_bb.png" rel="nofollow"><img alt="" height="300px" src="http://arduino.cc/en/uploads/Tutorial/speaker_schem.png" title="" /></a></div><h3>Code</h3>The code below uses an extra file, pitches.h. This file contains all the pitch values for typical notes. For example, NOTE_C4 is middle C. NOTE_FS4 is F sharp, and so forth. This note table was originally written by Brett Hagman, on whose work the tone() command was based. You may find it useful for whenever you want to make musical notes. <br />
To make this file, click on the "new Tab" button in the upper right hand corner of the window. It looks like this: <br />
<div><img alt="" src="http://arduino.cc/en/uploads/Tutorial/newTab.png" title="" /></div>The paste in the following code:<br />
<pre id="line1">/*************************************************
* Public Constants
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978</pre><pre id="line1"> </pre>The main sketch is as follows:<br />
<br />
<pre id="line1">/*
Melody
Plays a melody
circuit:
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
}
}
void loop() {
// no need to repeat the melody.
}</pre><pre id="line1"><a name='more'></a>fonte: <a href="http://arduino.cc/en/Tutorial/Tone">http://arduino.cc/en/Tutorial/Tone</a></pre><pre id="line1">tags: Arduino, Play Melody using the tone() function, Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino </pre><!--[if !IE]> Firefox and others will use outer object -->Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-64865090646862011702010-03-24T18:33:00.000-07:002010-03-24T18:33:37.885-07:00Debounce<em>Examples > Digital I/O</em> <br />
<h2>Debounce</h2>This example demonstrates the use of a pushbutton as a switch: each time you press the button, the LED (or whatever) is turned on (if it's off) or off (if on). It also debounces the input, without which pressing the button once would appear to the code as multiple presses. Makes use of the millis() function to keep track of the time when the button is pressed. <br />
<h3>Circuit</h3><div><img alt="" src="http://arduino.cc/en/uploads/Tutorial/button.png" title="" /></div><span style="font-size: 83%;">image developed using <a class="urllink" href="http://www.fritzing.org/" rel="nofollow">Fritzing</a>. For more circuit examples, see the <a class="urllink" href="http://fritzing.org/projects/" rel="nofollow">Fritzing project page</a> </span> <br />
<strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/button_schem.png" rel="nofollow"><img alt="" src="http://arduino.cc/en/uploads/Tutorial/button_schem.png" title="" width="400px" /></a></div><h3>Code</h3>The code below is based on <a class="urllink" href="http://www.ladyada.net/learn/sensors/tilt.html" rel="nofollow">Limor Fried's version of debounce</a>, but the logic is inverted from her example. In her example, the switch returns LOW when closed, and HIGH when open. Here, the switch returns HIGH when pressed and LOW when not pressed. <br />
<pre id="line1">/*
Debounce
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached from pin 2 to +5V
* 10K resistor attached from pin 2 to ground
* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
created 21 November 2006
by David A. Mellis
modified 3 Jul 2009
by Limor Fried
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Debounce
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
buttonState = reading;
}
// set the LED using the state of the button:
digitalWrite(ledPin, buttonState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}</pre><pre id="line1"><a name='more'></a>fonte ; <a href="http://arduino.cc/en/Tutorial/Debounce">http://arduino.cc/en/Tutorial/Debounce</a></pre><pre id="line1">tags : Arduino, Debounce, Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino
</pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-90974044924263729082010-03-24T18:30:00.000-07:002010-03-24T18:30:49.062-07:00Button State Change Detection (Edge Detection)<em>Examples > Digital I/O</em> <br />
<h2>Button State Change Detection (Edge Detection)</h2>Once you've got a <a class="wikilink" href="http://arduino.cc/en/Tutorial/Button">pushbutton</a> working, you often want to do some action based on how many times the button is pushed. To do this, you need to know when the button changes state from off to on, and count how many times this change of state happens. This is called <strong>state change detection</strong> or <strong>edge detection.</strong> <br />
Connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-down resistor (here 10 <span class="wikiword">KOhms</span>) to ground. The second goes from the corresponding leg of the pushbutton to the 5 volt supply. The third connects to a digital i/o pin (here pin 2) which reads the button's state. <br />
When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to voltage, so that we read a HIGH. (The pin is still connected to ground, but the resistor resists the flow of current, so the path of least resistance is to +5V.) <br />
If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, not connected to either voltage or ground. It will more or less randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit. <br />
<h3>Circuit</h3><div><img alt="" src="http://arduino.cc/en/uploads/Tutorial/button.png" title="" /></div><span style="font-size: 83%;">image developed using <a class="urllink" href="http://www.fritzing.org/" rel="nofollow">Fritzing</a>. For more circuit examples, see the <a class="urllink" href="http://fritzing.org/projects/" rel="nofollow">Fritzing project page</a> </span> <br />
<strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/button_schem.png" rel="nofollow"><img alt="" src="http://arduino.cc/en/uploads/Tutorial/button_schem.png" title="" width="400px" /></a></div>The sketch below continually reads the button's state. It then compares the button's state to its state the last time through the main loop. If the current button state is different from the last button state and the current button state is high, then the button changed from off to on. The sketch then increments a button push counter. <br />
The sketch also checks the button push counter's value, and if it's an even multiple of four, it turns the LED on pin 13 ON. Otherwise, it turns it off. <br />
<h3>Code</h3>((:div class=code :)<br />
<pre id="line1">/*
State change detection (edge detection)
Often, you don't need to know the state of a digital input all the time,
but you just need to know when the input changes from one state to another.
For example, you want to know when a button goes from OFF to ON. This is called
state change detection, or edge detection.
This example shows how to detect when a button or button changes from off to on
and on to off.
The circuit:
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* LED attached from pin 13 to ground (or use the built-in LED on
most Arduino boards)
created 27 Sep 2005
modified 30 Dec 2009
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/ButtonStateChange
*/
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter, DEC);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}</pre><pre id="line1"><a name='more'></a>fonte : <a href="http://arduino.cc/en/Tutorial/ButtonStateChange">http://arduino.cc/en/Tutorial/ButtonStateChange</a>
tags : Arduino, Button State Change Detection (Edge Detection), Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino
</pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-55178147518767288682010-03-24T18:27:00.000-07:002010-03-24T18:27:11.608-07:00Button<em>Examples > Digital I/O</em> <br />
<h2>Button</h2>Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button. <br />
Connect three wires to the Arduino board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 <span class="wikiword">KOhms</span>) to ground. The other leg of the button connects to the 5 volt supply. <br />
When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that we read a HIGH. <br />
You can also wire this circuit the opposite way, with a pullup resistor keeping the input HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button. <br />
If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it will randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resistor in the circuit. <br />
<h3>Circuit</h3><div><img alt="" src="http://arduino.cc/en/uploads/Tutorial/button.png" title="" /></div><span style="font-size: 83%;">image developed using <a class="urllink" href="http://www.fritzing.org/" rel="nofollow">Fritzing</a>. For more circuit examples, see the <a class="urllink" href="http://fritzing.org/projects/" rel="nofollow">Fritzing project page</a> </span> <br />
<strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/button_schem.png" rel="nofollow"><img alt="" src="http://arduino.cc/en/uploads/Tutorial/button_schem.png" title="" width="400px" /></a></div><h3>Code</h3><pre id="line1">/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 7.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http: www.0j0.org="">
modified 17 Jun 2009
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}</http:></pre><pre id="line1"><a name='more'></a> tags: Arduino, Button, Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino </pre><pre id="line1">fonte : <a href="http://arduino.cc/en/Tutorial/Button%20">http://arduino.cc/en/Tutorial/Button </a></pre>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-43414689499615397012010-03-24T18:20:00.000-07:002010-03-24T18:20:24.687-07:00BlinkIn most programming languages, the first program you write prints "hello world" to the screen. Since an Arduino board doesn't have a screen, we blink an LED instead. <br />
The boards are designed to make it easy to blink an LED using digital pin 13. Some (like the Diecimila and <span class="wikiword">LilyPad</span>) have the LED built-in to the board. On most others (like the Mini and BT), there is a 1 KB resistor on the pin, allowing you to connect an LED directly. (To connect an LED to another digital pin, you should use an external resistor.) <br />
<span class="wikiword">LEDs</span> have polarity, which means they will only light up if you orient the legs properly. The long leg is typically positive, and should connect to pin 13. The short leg connects to GND; the bulb of the LED will also typically have a flat edge on this side. If the LED doesn't light up, trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of time). <br />
<h3>Circuit</h3><div><img alt="" src="http://arduino.cc/en/uploads/Tutorial/LedOnPin13.jpg" title="" /> </div><strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/Blink_schem2.png" rel="nofollow"><img alt="" src="http://arduino.cc/en/uploads/Tutorial/Blink_schem2.png" title="" width="400px" /></a></div><h3>Code</h3>The example code is very simple, credits are to be found in the comments. <br />
<pre id="line1">/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
The circuit:
* LED connected from digital pin 13 to ground.
* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
Created 1 June 2005
By David Cuartielles
http://arduino.cc/en/Tutorial/Blink
based on an orginal by H. Barragan for the Wiring i/o board
This example code is in the public domain.
*/
int ledPin = 13; // LED connected to digital pin 13
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}</pre><span class="post-labels"><a name='more'></a>tags : Arduino, Blink, Pedro Ernesto Scotton, Pedro Scotton, Starter Arduino<br />
<a href="http://arduinostart.blogspot.com/search/label/Starter%20Arduino" rel="tag"></a></span>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0tag:blogger.com,1999:blog-4901616806545434004.post-61318617532171337342010-03-24T18:08:00.000-07:002010-03-24T18:14:33.411-07:00Blink Without Delay<h2>Blink Without Delay</h2>Sometimes you need to blink an LED (or some other time sensitive function) at the same time as something else (like watching for a button press). That means you can't use delay(), or you'd stop everything else the program while the LED blinked. Here's some code that demonstrates how to blink the LED without using delay(). It keeps track of the last time it turned the LED on or off. Then, each time through loop() it checks if a sufficient interval has passed - if it has, it turns the LED off if it was on and vice-versa. <br />
<h3>Circuit</h3><div><img alt="" src="http://arduino.cc/en/uploads/Tutorial/LedOnPin13.jpg" title="" /> </div><strong>Schematic:</strong> <br />
click the image to enlarge <br />
<div><a class="urllink" href="http://arduino.cc/en/uploads/Tutorial/Blink_schem2.png" rel="nofollow"><img alt="" src="http://arduino.cc/en/uploads/Tutorial/Blink_schem2.png" title="" width="400px" /></a></div><h3>Code</h3><dl><dt>div class=code </dt>
<dd>) <a name='more'></a><pre id="line1">/* Blink without Delay
Turns on and off a light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to
// set pin numbers:
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}</pre><pre id="line1"><a href="http://arduino.cc/en/Tutorial/BlinkWithoutDelay">fonte : http://arduino.cc/en/Tutorial/BlinkWithoutDelay</a></pre><pre id="line1">tags : Blink Without Delay,Arduino,Starter Arduino , Pedro Scotton ,Pedro Ernesto Scotton</pre><pre id="line1"></pre></dd></dl>Pedro Scottonhttp://www.blogger.com/profile/14271695610397932946noreply@blogger.com0