<div dir="ltr">You're absolutely right.   It depends on the application.  Talking about taking "about a second" to turn off led me to presume it was still at the human perception level.<div><div><br></div><div>
Rob.</div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 15, 2014 at 3:29 PM, R Craig <span dir="ltr"><<a href="mailto:roncraig007@yahoo.com" target="_blank">roncraig007@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Doesn't it sort of depend, Rob, on who or what is at the other end?<br>
<br>
Without debouncing the button, the IR LED will flash on-off-on-off some number of times before settling down to on.  If the other end were just a human looking at the light, then sure, it wouldn't matter because the human would never detect or be confused by the very brief flashes.  This being an IR, though, I imagine there is another piece of electronics at the other end, and it might or might not be confused by the IR going on and off a bunch of times with each single button press.   <br>

<br>
If it is a sensor in a target, it might well register 6 or 8 hits (racking up some serious points in the process) with just a single press of the button.  The point of debouncing the button is to ensure your output switches state just *once* with each press.  For an IR LED, it might make quite a difference, depending on the circumstances.<br>

<br>
Best,<br>
Ron<br>
--------------------------------------------<br>
On Tue, 7/15/14, Robert Mackie <<a href="mailto:rob@mackies.org">rob@mackies.org</a>> wrote:<br>
<br>
 Subject: Re: [TriEmbed] [OBSOLETE trianglearduino:1095] Problem with AtTiny85 and buttons<br>
 To: "Adam Haile" <<a href="mailto:email@adamhaile.net">email@adamhaile.net</a>><br>
 Cc: "TriEmbed Discussion" <<a href="mailto:triembed@triembed.org">triembed@triembed.org</a>><br>
 Date: Tuesday, July 15, 2014, 2:15 PM<br>
<div class=""><br>
 Just to<br>
 emphasize, since you weren't doing a toggled state but<br>
 were having the light simply show the current pressed state<br>
 of the button (bright when switch closed, no light when<br>
 switch open) you don't need to worry about<br>
 de-bouncing.<br>
<br>
 However, you do need to take<br>
 care of biasing the input as described in Adam's email<br>
 or with an external resistor.<br>
 Rob.<br>
<br>
<br>
 On Tue, Jul 15, 2014 at 10:32 AM, Adam Haile <<a href="mailto:email@adamhaile.net">email@adamhaile.net</a>><br>
 wrote:<br>
<br>
 Joe,<br>
 Easiest<br>
 way to do the mentioned bias resistors is to use the<br>
</div> one's built into the AT chip :)Every IO pin<br>
<div><div class="h5"> on the AT series chips have an internal pull-up resistor<br>
 ranging from 10k-50k ohm (depending on the chip<br>
 model).<br>
<br>
<br>
<br>
 To enable it, you set the<br>
 pin mode to input and then write a high bit to it. Sounds<br>
 weird, but that's just the way the resisters<br>
 work:<br>
 pinMode(buttonPin, INPUT);<br>
  <br>
<br>
<br>
<br>
 digitalWrite(buttonPin, HIGH);<br>
 //sets internal pull-up <br>
<br>
<br>
<br>
 Then, simply wire your button<br>
 to "pull" that pin to ground. i.e. hook one side<br>
 of the button to buttonPin and the other to ground. When the<br>
 button closes the bias is now ground because it has the<br>
 least resistance and your micro will see LOW. See the<br>
 following for more: <a href="http://arduino.cc/en/Tutorial/DigitalPins" target="_blank">http://arduino.cc/en/Tutorial/DigitalPins</a><br>
<br>
<br>
<br>
 For debouncing, if you aren't too worried<br>
 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><br>
<br>
<br>
<br>
 At its simplest, you can do something like<br>
 this:<br>
<br>
<br>
<br>
 uint8_t _oldState = HIGH;uint8_t _curState =<br>
 _oldState;long bounceThreshold = 100;//wait<br>
 100ms, increase or decrease depending on how sesitive you<br>
 want the debouncing<br>
 _curState =<br>
 digitalRead(buttonPin);<br>
<br>
<br>
 if(_curState != _oldState){    delay(bounceThreshold);    if(_curState ==<br>
 digitalRead(buttonPin))<br>
<br>
     {        if(_curState)        {            // turn LED<br>
 on: <br>
<br>
<br>
         }        else        {            // turn LED<br>
 off: <br>
<br>
<br>
         }        _oldState =<br>
 _curState;    }}<br>
<br>
<br>
 It's pretty basic, but it gets the job done<br>
 in most cases. Note, this should make it so the LED is on<br>
 only while the button is actually down. It's not a<br>
 toggle (press on/press off). To to that, in the if(_curSate)<br>
 section just flip a boolean (ledState != ledState) and then<br>
 at the end of that whole if statement do<br>
 digitalWrite(ledPin, ledState);<br>
<br>
<br>
<br>
 There's many ways to<br>
 skin this one... personally I use external interrupts with<br>
 buttons... but that's a whole other lesson. Though, side<br>
 note. The reason the internal bias resistors are pull-up is<br>
 that the chips are set to only be able to be woken from<br>
 sleep when the external interrupt goes LOW. You can<br>
 configure the interrupts to react to LOW or HIGH, but being<br>
 woken from sleep is a special case and it looks like they<br>
 simplified the chip circuit by requiring that a wake be a<br>
 LOW pulse.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
 On Tue, Jul 15, 2014 at 10:15 AM,<br>
 Glen Smith <<a href="mailto:mrglenasmith@gmail.com">mrglenasmith@gmail.com</a>><br>
 wrote:<br>
<br>
<br>
<br>
 I'm guessing that<br>
 you have 2 problems. One is due to your input switch<br>
 bouncing. When a mechanical switch closes it does not simply<br>
 change from false to true. For a few milliseconds<br>
 (immediately for us slow humans but forever for a<br>
 u-processor running this little bit of code) it bounces back<br>
 & forth between the two states. Regardless of how fast<br>
 or hard you push that switch, the Tiny85 will see many of<br>
 these changes.<br>
<br>
<br>
<br>
<br>
 The other thing you are running into is called<br>
 a floating input. When you set the button as an input, you<br>
 need to use a resistor to bias the input to return to a<br>
 known level. Think of it like a lever, unless a spring<br>
 pushes or pulls the lever to a known state, when you let go<br>
 of it, the lever will simply stay where you left it. In the<br>
 case of your input, you left it high, so the charge on the<br>
 input slowly dissipates, and a second or so later the Tiny85<br>
 sees it as a low. These biasing resistors are called pull-up<br>
 & pull-down resistors.<br>
<br>
<br>
<br>
<br>
 On Jul 15, 2014 6:58<br>
 AM, "Bothari" <<a href="mailto:bothari@gmail.com">bothari@gmail.com</a>><br>
 wrote:<br>
<br>
<br>
<br>
<br>
 Group,<br>
 I've been learning about<br>
 hardware for the last couple of months, but I've come up<br>
 against a problem with inputs.  I put together a little IR<br>
 gun with the AtTiny85, but I can't get the trigger to<br>
 fire the gun.  I've reduced the problem to one AtTiny85<br>
 with a resistor and LED, but I still don't understand<br>
 what's going on.<br>
<br>
<br>
<br>
<br>
<br>
 With the below code (Blink<br>
 from the examples) I can touch the #2 pin high and the light<br>
 on pin 3 comes on, but it stays on for like a second or so<br>
 before going off.  I think it should go off immediately.<br>
<br>
<br>
<br>
<br>
<br>
<br>
 I added 3 blinks<br>
 on the LED on startup to make sure I know when it resets,<br>
 and the fuse bits for the oscillator are set to 8mHz.  That<br>
 works as expected.<br>
 Any<br>
 ideas?<br>
<br>
<br>
<br>
<br>
 Joe<br>
 const<br>
 int buttonPin = 2;     // the number of the pushbutton<br>
</div></div> pinconst int ledPin =  3;      // the number<br>
<div><div class="h5"> of the LED pin<br>
 //<br>
 variables will change:<br>
<br>
<br>
<br>
<br>
 int buttonState = 0;         // variable for<br>
 reading the pushbutton status<br>
 void setup() {  //<br>
 initialize the LED pin as an output: <br>
 pinMode(ledPin, OUTPUT);      <br>
<br>
<br>
<br>
<br>
   digitalWrite(ledPin, LOW);   // initialize<br>
 the pushbutton pin as an input: <br>
 pinMode(buttonPin, INPUT);     <br>
   //Show that we<br>
 rebooted  digitalWrite(ledPin, HIGH);<br>
<br>
<br>
<br>
<br>
   delay(300);   digitalWrite(ledPin,<br>
 LOW);    delay(300); <br>
   digitalWrite(ledPin,<br>
 HIGH);  delay(300);  <br>
 digitalWrite(ledPin, LOW);   <br>
 delay(300); <br>
<br>
<br>
<br>
<br>
<br>
   digitalWrite(ledPin,<br>
 HIGH);  delay(300);  <br>
 digitalWrite(ledPin, LOW);   <br>
 delay(300); }<br>
 void loop(){  // read<br>
 the state of the pushbutton value:<br>
<br>
<br>
<br>
<br>
   buttonState = digitalRead(buttonPin);<br>
   // check if the pushbutton is<br>
 pressed.  // if it is, the buttonState is<br>
 HIGH:  if (buttonState == HIGH) {  <br>
       // turn LED on:    <br>
<br>
<br>
<br>
<br>
     digitalWrite(ledPin, HIGH);   <br>
 }   else {    // turn LED<br>
 off:    digitalWrite(ledPin,<br>
 LOW);   }}<br>
<br>
<br>
 --<br>
 "There are<br>
 only two industries that refer to their customers as<br>
 ‘users’." - Edward Tufte<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
 --<br>
<br>
 NOTICE: This list is OBSOLETE. For details about the<br>
 replacement TriEmbed list go here:<br>
<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>
 ---<br>
<br>
 You received this message because you are subscribed to the<br>
 Google Groups "trianglearduino" group.<br>
<br>
 To unsubscribe from this group and stop receiving emails<br>
 from it, send an email to <a href="mailto:trianglearduino%2Bunsubscribe@googlegroups.com">trianglearduino+unsubscribe@googlegroups.com</a>.<br>
<br>
 Visit this group at <a href="http://groups.google.com/group/trianglearduino" target="_blank">http://groups.google.com/group/trianglearduino</a>.<br>
<br>
 For more options, visit <a href="https://groups.google.com/d/optout" target="_blank">https://groups.google.com/d/optout</a>.<br>
<br>
<br>
<br>
 _______________________________________________<br>
<br>
 Triangle, NC Embedded Computing mailing list<br>
<br>
 <a href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a><br>
<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>
 TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><br>
<br>
<br>
<br>
<br>
<br>
 _______________________________________________<br>
<br>
 Triangle, NC Embedded Computing mailing list<br>
<br>
 <a href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a><br>
<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>
 TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><br>
<br>
<br>
<br>
<br>
</div></div> -----Inline Attachment Follows-----<br>
<div class="HOEnZb"><div class="h5"><br>
 _______________________________________________<br>
 Triangle, NC Embedded Computing mailing list<br>
 <a href="mailto:TriEmbed@triembed.org">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>
</div></div></blockquote></div><br></div>