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

<br>
</div></div>

<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>
</blockquote></div>