URGENT HELP

Hi!
I have a project, in which I use the bluetooth module HC-05, with that I have to make a traffic light simulation turn on the yellow leds immediately by pressing the "on" button and immediately return to the succession of the traffic light when I press the button " off "
I thought it could be done with "attachInterrupt" but it does not work : smiley-confundir:
What I can do?

You need to do two things for a start.

One is to go back and edit your title to a meaningful topic without the stuck Caps Lock.

The second is to comprehend what "interrupts" are. As a complete beginner, it is incredibly unlikely that interrupts will be useful to you.

A common "newbie" misunderstanding is that an interrupt is a mechanism for altering the flow of a program - to execute an alternate function. Nothing could be further from the truth.

An interrupt is a mechanism for performing an action which can be executed in "no time at all" with an urgency that it must be performed immediately or else data - information - will be lost or some harm will occur.

Now these criteria are in a microprocessor time scale - microseconds. This must not be confused with a human time scale of tens or hundreds of milliseconds or indeed, a couple of seconds. A switch operation is in this latter category and a mechanical operation perhaps several milliseconds; the period of a 6000 RPM shaft rotation is ten milliseconds.

Unless it is a very complex procedure, you would expect the loop() to cycle many times per millisecond. If it does not, there is most likely an error in code planning; while the delay() function is provided for testing purposes, its action goes strictly against effective programming methods. The loop() will be successively testing a number of contingencies as to whether each requires action, only one of which may be whether a particular timing criteria has expired. Unless an action must be executed in the order of microseconds, it will be handled in the loop().

So what sort of actions do require such immediate attention? Well, generally those which result from the computer hardware itself, such as high speed transfer of data in UARTs(, USARTs) or disk controllers.

An alternate use of interrupts, for context switching in RTOSs, is rarely relevant to this category of microprocessors as it is more efficient to write cooperative code as described above.

Mazapancito:
with that I have to make a traffic light simulation turn on the yellow leds immediately by pressing the "on" button and immediately return to the succession of the traffic light when I press the button " off "

There is no need for an interrupt to do things in human timescales. Humans are verrryyy sssllllooooooowww.

What you need to do is ensure that you write a responsive program that can detect the button press within a timescale that the human perceives as immediate.

Have a look at the demo Several Things at a Time

Also the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

  • What Arduino controller are you using?
  • What does the Bluetooth communicate with?
  • Can you tell us your electronics, programming, arduino, hardware experience?
  • Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
  • Can you post a copy of the code you have already written?

Thanks.. Tom.. :slight_smile:

Paul__B:
Now these criteria are in a microprocessor time scale - microseconds. This must not be confused with a human time scale of tens or hundreds of milliseconds or indeed, a couple of seconds.

Johnny Carson defined microsecond as the time between the traffic light going green and the first car horn to honk.

WELCOME !
since two people already told you to read How To Use This Forum, I will just say +1
when you read How to use this forum, #7 will show you how to post code using 'code tags'
since we can only guess what you are doing, it would help to know what you are doing.
read about how to use 'code tags' and post your code.
I think the answer for your question might be rather simple. but without seeing your code, we can only guess.

Mazapancito:
I have a project, in which I use the bluetooth module HC-05, with that I have to make a traffic light simulation turn on the yellow leds immediately by pressing the "on" button and immediately return to the succession of the traffic light when I press the button " off "

Get the basic traffic light working first, without using delay() for the timing, that will be important when you need to quickly respond to the button. From that point, it should be fairly easy to immediately advance to the yellow light when the "ON" button is pressed, and stay there until the "OFF" button is pressed.