<p dir="ltr">I should have refreshed my inbox prior to writing my note. Sooner or later I will learn this lesson. </p>
<p dir="ltr">Truth be told, for this application debouncing the switch is probably not necessary, UNLESS you plan on eventually limiting the number of shots a player gets in a game or before reloading. Which would prevent somebody from holding the trigger & simply panning around during the play area. </p>

<div class="gmail_quote">On Jul 15, 2014 10:32 AM, "Adam Haile" <<a href="mailto:email@adamhaile.net">email@adamhaile.net</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Joe,<div><br></div><div>Easiest way to do the mentioned bias resistors is to use the one's built into the AT chip :)</div><div>Every IO pin on the AT series chips have an internal pull-up resistor ranging from 10k-50k ohm (depending on the chip model).</div>


<div><br></div><div>To enable it, you set the pin mode to input and then write a high bit to it. Sounds weird, but that's just the way the resisters work:</div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px">pinMode(buttonPin, INPUT);  </span><br>


</div><div><span style="font-family:arial,sans-serif;font-size:13px">digitalWrite(buttonPin, HIGH); //sets internal pull-up </span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div>


<font face="arial, sans-serif">Then, simply wire your button to "pull" that pin to ground. i.e. hook one side of the button to buttonPin and the other to ground. When the button closes the bias is now ground because it has the least resistance and your micro will see LOW. See the following for more: <a href="http://arduino.cc/en/Tutorial/DigitalPins" target="_blank">http://arduino.cc/en/Tutorial/DigitalPins</a></font></div>


<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">For debouncing, if you aren't too worried about not doing it the most efficient way try this: <a href="http://playground.arduino.cc/code/bounce" target="_blank">http://playground.arduino.cc/code/bounce</a></font></div>


<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">At its simplest, you can do something like this:</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"><div>


uint8_t _oldState = HIGH;</div><div>uint8_t _curState = _oldState;</div><div>long bounceThreshold = 100;//wait 100ms, increase or decrease depending on how sesitive you want the debouncing</div><div><br></div><div>_curState = digitalRead(buttonPin);</div>


<div>if(_curState != _oldState)</div><div>{</div><div><span style="white-space:pre-wrap"> </span>delay(bounceThreshold);</div><div><span style="white-space:pre-wrap">  </span>if(_curState == digitalRead(buttonPin))</div>

<div><span style="white-space:pre-wrap">  </span>{</div><div><span style="white-space:pre-wrap">                </span>if(_curState)</div><div><span style="white-space:pre-wrap">            </span>{</div><div><span style="white-space:pre-wrap">                        </span>// turn LED on: </div>


<div><span style="white-space:pre-wrap">          </span>}</div><div><span style="white-space:pre-wrap">                </span>else</div><div><span style="white-space:pre-wrap">             </span>{</div><div><span style="white-space:pre-wrap">                        </span>// turn LED off: </div>


<div><span style="white-space:pre-wrap">          </span>}</div><div><span style="white-space:pre-wrap">                </span>_oldState = _curState;</div><div><span style="white-space:pre-wrap">   </span>}</div><div>}</div><div><br>

</div><div>It's pretty basic, but it gets the job done in most cases. Note, this should make it so the LED is on only while the button is actually down. It's not a toggle (press on/press off). To to that, in the if(_curSate) section just flip a boolean (ledState != ledState) and then at the end of that whole if statement do digitalWrite(ledPin, ledState);</div>


<div><br></div><div>There's many ways to skin this one... personally I use external interrupts with buttons... but that's a whole other lesson. Though, side note. The reason the internal bias resistors are pull-up is that the chips are set to only be able to be woken from sleep when the external interrupt goes LOW. You can configure the interrupts to react to LOW or HIGH, but being woken from sleep is a special case and it looks like they simplified the chip circuit by requiring that a wake be a LOW pulse.</div>


</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"><br></font></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 15, 2014 at 10:15 AM, Glen Smith <span dir="ltr"><<a href="mailto:mrglenasmith@gmail.com" target="_blank">mrglenasmith@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">I'm guessing that you have 2 problems. One is due to your input switch bouncing. When a mechanical switch closes it does not simply change from false to true. For a few milliseconds (immediately for us slow humans but forever for a u-processor running this little bit of code) it bounces back & forth between the two states. Regardless of how fast or hard you push that switch, the Tiny85 will see many of these changes. </p>




<p dir="ltr">The other thing you are running into is called a floating input. When you set the button as an input, you need to use a resistor to bias the input to return to a known level. Think of it like a lever, unless a spring pushes or pulls the lever to a known state, when you let go of it, the lever will simply stay where you left it. In the case of your input, you left it high, so the charge on the input slowly dissipates, and a second or so later the Tiny85 sees it as a low. These biasing resistors are called pull-up & pull-down resistors. </p>




<div class="gmail_quote">On Jul 15, 2014 6:58 AM, "Bothari" <<a href="mailto:bothari@gmail.com" target="_blank">bothari@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div dir="ltr">Group,<div><br></div><div>I've been learning about hardware for the last couple of months, but I've come up against a problem with inputs.  I put together a little IR gun with the AtTiny85, but I can't get the trigger to fire the gun.  I've reduced the problem to one AtTiny85 with a resistor and LED, but I still don't understand what's going on.</div>




<div><br></div><div>With the below code (Blink from the examples) I can touch the #2 pin high and the light on pin 3 comes on, but it stays on for like a second or so before going off.  I think it should go off immediately.<br>




</div><div><div><br></div><div>I added 3 blinks on the LED on startup to make sure I know when it resets, and the fuse bits for the oscillator are set to 8mHz.  That works as expected.</div><div><br></div><div>Any ideas?</div>




<div>Joe</div><div><br></div><div><div>const int buttonPin = 2;     // the number of the pushbutton pin</div><div>const int ledPin =  3;      // the number of the LED pin</div><div><br></div><div>// variables will change:</div>




<div>int buttonState = 0;         // variable for reading the pushbutton status</div><div><br></div><div>void setup() {</div><div>  // initialize the LED pin as an output:</div><div>  pinMode(ledPin, OUTPUT);      </div>



<div>
  digitalWrite(ledPin, LOW); </div><div>  // initialize the pushbutton pin as an input:</div><div>  pinMode(buttonPin, INPUT);     </div><div><br></div><div>  //Show that we rebooted</div><div>  digitalWrite(ledPin, HIGH);</div>




<div>  delay(300); </div><div>  digitalWrite(ledPin, LOW);  </div><div>  delay(300); </div><div><br></div><div>  digitalWrite(ledPin, HIGH);</div><div>  delay(300); </div><div>  digitalWrite(ledPin, LOW);  </div><div>  delay(300); </div>




<div><br></div><div>  digitalWrite(ledPin, HIGH);</div><div>  delay(300); </div><div>  digitalWrite(ledPin, LOW);  </div><div>  delay(300); </div><div>}</div><div><br></div><div>void loop(){</div><div>  // read the state of the pushbutton value:</div>




<div>  buttonState = digitalRead(buttonPin);</div><div><br></div><div>  // check if the pushbutton is pressed.</div><div>  // if it is, the buttonState is HIGH:</div><div>  if (buttonState == HIGH) {     </div><div>    // turn LED on:    </div>




<div>    digitalWrite(ledPin, HIGH);  </div><div>  } </div><div>  else {</div><div>    // turn LED off:</div><div>    digitalWrite(ledPin, LOW); </div><div>  }</div><div>}</div></div><span><font color="#888888"><div>

<br></div>-- <br>"There are only two industries that refer to their customers as ‘users’." - Edward Tufte<br>

<br>
</font></span></div></div><span><font color="#888888">

<p></p>

-- <br>
NOTICE: This list is OBSOLETE. For details about the replacement TriEmbed list go here:<br>
<a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
--- <br>
You received this message because you are subscribed to the Google Groups "trianglearduino" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:trianglearduino+unsubscribe@googlegroups.com" target="_blank">trianglearduino+unsubscribe@googlegroups.com</a>.<br>
Visit this group at <a href="http://groups.google.com/group/trianglearduino" target="_blank">http://groups.google.com/group/trianglearduino</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank">https://groups.google.com/d/optout</a>.<br>
</font></span></blockquote></div>
<br>_______________________________________________<br>
Triangle, NC Embedded Computing mailing list<br>
<a href="mailto:TriEmbed@triembed.org" target="_blank">TriEmbed@triembed.org</a><br>
<a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>
TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><br>
<br></blockquote></div><br></div>
</blockquote></div>