Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7193355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:09:12+00:00 2026-05-28T20:09:12+00:00

I am new to AVR, but i have programmed PICs before, only this time

  • 0

I am new to AVR, but i have programmed PICs before, only this time i am doing everything in linux too so you’ll guess that i am using avrdude…

My goal for this project is to change a bicolor LED’s color depending on a certain state.

By default, the led is RED (if you make the connections right of course), then i want it to go to yellow (which is a quick change between green and red) while the user is holding the button down then on release, it will go to green, then the next time it will turn off.

So, to recap,

LED is red

While i hold the button down its gonna be yellow

When i release it will be green

While i hold the button down again its gonna be yellow

When i release it will be off

While i hold the button down again its gonna be yellow

When i release it will be red (and so on…)

In my actual code, everything works really well sometimes, but sometimes the led gets stuck at yellow and i have no clue why

Any ideas?

Code is on ideone : http://ideone.com/LI9gH

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:09:13+00:00Added an answer on May 28, 2026 at 8:09 pm

    I’m guessing you’re simply seeing the random generator missing the button changes about 1/3rd of the time, because the debouncing is slightly off. Consider the time spent in different states:

    check button
    wait 10ms
    check button again
    if button values differ, update state
    if yellow
      shine red for 1ms
      shine green for 4ms then leave green on
    otherwise
      set current color
    

    That’s your main loop. As you can see, it checks the button in two instants during about 15ms time; and it doesn’t compare to the last value for which it updated state, only with the value 10ms prior. Release the button during the 5ms period of “yellow”, and allumerAmbre will not reset until the next release that happens to fall in the 10ms period. Also, the yellow wound up 1/15 red, possibly not the mix you intended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to javascript/jquery and having a hard time with using this or $(this) to
NEW EDIT: I have narrowed my problem to this - i have a view
I'm new to C++ programming, but have been working in C and Java for
new to python. This is probably simple but I haven't found an answer. rndStr
New to mvc, I have a controller like this public ActionResult Index(DateTime Date, DateTime
New versions of gson have a lot of changes regarding deserialization of Collections. Before
New to both Ruby and Rails but I'm book educated by now (which apparently
New to WCF, but familiar with COM+ - can I wrap a WCF service
New to Linux programming in general. I am trying to communicate with a kernel
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.