Welcome Guest! To enable all features please Login or Register.
Go to last post Go to first unread
#1 Posted : Saturday, February 17, 2018 12:46:00 PM(UTC)

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 572

Thanks: 1 times
Was thanked: 34 time(s) in 31 post(s)
This question was asked on the Reddit/r/Arduino forum.

The user is making a project with 2 LEDs and one button. When you click the button a first time, one LED turns on. When you click the button a second time, the second LED starts blinking. Finally pressing the button a third time turns off both LEDs.

This post contains a project for doing this in Embrio.

The project is fairly simple.

The LED 1 and LED 2 agents simply have a digital output node for writing to the LEDs.
Update the input pins on these agents to match your hardware

The Button agent takes a digital input, passes it through an Above or Below node to get a trigger to fire when the button is pressed, and runs that through a quick timer to limit how often the button can press. This solves the debouncing issue the user was having in their code.

LED 2 Blink is the only behavior agent in this project. It exposes one input activation on the Above Or Below node which is used to turn this agent on or off. When turned on, the timer starts. When the timer finishes, it toggles the switch, and fires the times again if the input activation is still activated. When the input activation goes low, it turns off the timer and switch.

Finally the top level Control agent does state control with a Multi Step node which is incremented by the button agent. The first step has no connections, on this step both LEDs are off. The second step turns on the LED 1 activation, turning on that LED. The third step activates both the LED 1 agent and the LED 2 Blink agent so both LEDs are on. When clicked again the Multi Step agent resets back to step 1 where both LEDs are off.

Edited by user Saturday, February 17, 2018 12:50:26 PM(UTC)  | Reason: Not specified

File Attachment(s):
TwoLEDsOneButton.zip (18kb) downloaded 1 time(s).

You cannot view/download attachments. Try to login or register.
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.