Go Down

Topic: Rising and falling edge (Read 11934 times) previous topic - next topic

ElectricalStorm

Hi,
i tough i read somewhere on the internet that a digitalRead instruction could detect a rising and falling edge. For some reason I can't find it anymore. Maybe it was another instruction…
Anyway I need to detect the rising and falling edge of a pushbutton on a digital input, any help would be appreciated.

Thanks,
Chris

PaulS

The digitalRead() function determines whether the current state of the pin is HIGH or LOW. An interrupt can be captured, using an external interrupt, on the change from LOW to HIGH, from LOW to HIGH, or either change.

The pulseIn() function can tell you how long a pin is HIGH or LOW, when the change is caused by something other than a push-button switch.
The art of getting good answers lies in asking good questions.

Onions

http://arduino.cc/en/Reference/DigitalRead digitalRead
http://arduino.cc/en/Reference/AttachInterrupt external interrupts
http://arduino.cc/en/Reference/PulseIn pulseIn

http://arduino.cc/en/Tutorial/Button Using digitalRead
http://arduino.cc/en/Tutorial/ButtonStateChange edge detection

They should explain interrupts, digitalRead, pulseIn, and reading pins with digitalRead. After you've mastered that, you can try learning port manipulation for faster digitalReads.

Onions.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

ElectricalStorm

Thanks for pointing me in the right direction guys . I can probably work something out with the ButtonStateChange code.

Cheers,
Chris

anton1o

#4
Apr 04, 2017, 11:19 am Last Edit: Apr 04, 2017, 11:24 am by anton1o
http://arduino.cc/en/Reference/DigitalRead digitalRead
http://arduino.cc/en/Reference/AttachInterrupt external interrupts
http://arduino.cc/en/Reference/PulseIn pulseIn

http://arduino.cc/en/Tutorial/Button Using digitalRead
http://arduino.cc/en/Tutorial/ButtonStateChange edge detection

They should explain interrupts, digitalRead, pulseIn, and reading pins with digitalRead. After you've mastered that, you can try learning port manipulation for faster digitalReads.

Onions.
The page "Reference/DigitalReadDigitalRead" doesn't exist.
The page "Reference/AttachInterruptExternalInterrupts" doesn't exist.

Reference Home

Whandall

The page "Reference/DigitalReadDigitalRead" doesn't exist.
The page "Reference/AttachInterruptExternalInterrupts" doesn't exist.
But the given links do.

http://arduino.cc/en/Reference/DigitalRead digitalRead
http://arduino.cc/en/Reference/AttachInterrupt external interrupts
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

sterretje

Did you really have to kick a nearly 6 year old thread?
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

sterretje

Have you worked through the most basic programming examples, included in the Arduino IDE?

The flank detection example is the "StateChangeDetection" example. Simply open it under menu option "File-Examples"
Did you read reply #4 and reply #6? :D
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

anton1o

But the given links do.
I just make message to fix the link on that post #2

Whandall

Don't fix something that is not broken.
After six years it would be rather pointless, even it it were broken.

BTW nobody can fix the way you copy links.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

GolamMostafa

Quote
rising and falling edge of a push button
1. A push button has no edge; it has pins.

2. An  electrical full pulse (__|----|__ ; AL, RE, AH, FE) signal has edges in addition to active levels.

3.  What do you want now?
    (a) Sensing the RE (Rising Edge = Leading Edge) of an incoming pulse and then trigger an event.
    (b) Sensing the FE (Falling Edge = Training Edge) of an incoming pulse and then trigger an event.

4. Is it possible to create a full electrical pulse using a push button?
    yes.
    Let us trigger a 74LS123 type one-shot by a push button.

5. The RE of the resultant pulse can be detected by the MCU being interrpted over INT0-pin.

6. The RE of the resultant pulse can also be detected by counting the RE of the incoming pulse
    using T0-pin.


Go Up