[TriEmbed] [OBSOLETE trianglearduino:1095] Problem with AtTiny85 and buttons

Glen Smith mrglenasmith at gmail.com
Tue Jul 15 09:15:34 CDT 2014


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.

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.
On Jul 15, 2014 6:58 AM, "Bothari" <bothari at gmail.com> wrote:

> Group,
>
> 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.
>
> 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.
>
> 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.
>
> Any ideas?
> Joe
>
> const int buttonPin = 2;     // the number of the pushbutton pin
> const int ledPin =  3;      // 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);
>   digitalWrite(ledPin, LOW);
>   // initialize the pushbutton pin as an input:
>   pinMode(buttonPin, INPUT);
>
>   //Show that we rebooted
>   digitalWrite(ledPin, HIGH);
>   delay(300);
>   digitalWrite(ledPin, LOW);
>   delay(300);
>
>   digitalWrite(ledPin, HIGH);
>   delay(300);
>   digitalWrite(ledPin, LOW);
>   delay(300);
>
>   digitalWrite(ledPin, HIGH);
>   delay(300);
>   digitalWrite(ledPin, LOW);
>   delay(300);
> }
>
> 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);
>   }
> }
>
> --
> "There are only two industries that refer to their customers as ‘users’."
> - Edward Tufte
>
>  --
> NOTICE: This list is OBSOLETE. For details about the replacement TriEmbed
> list go here:
> http://mail.triembed.org/mailman/listinfo/triembed_triembed.org
> ---
> You received this message because you are subscribed to the Google Groups
> "trianglearduino" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to trianglearduino+unsubscribe at googlegroups.com.
> Visit this group at http://groups.google.com/group/trianglearduino.
> For more options, visit https://groups.google.com/d/optout.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.triembed.org/pipermail/triembed_triembed.org/attachments/20140715/465c1424/attachment.htm>


More information about the TriEmbed mailing list