Skip to content

Instantly share code, notes, and snippets.

@eschen42
Last active October 13, 2018 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eschen42/28c1f77eb6aefbe0c10a609004b04313 to your computer and use it in GitHub Desktop.
Save eschen42/28c1f77eb6aefbe0c10a609004b04313 to your computer and use it in GitHub Desktop.
Icon code for positive-edge triggered bistable multivibrator
procedure co_bistable(off_state, on_state)
local button, bistable_button, bistable_state
/off_state := "off"
/on_state := "on"
bistable_button := bistable_state := button := off_state
return create while button := (
if button ~== bistable_button
then if (bistable_button := button) == on_state
then bistable_state := if bistable_state == off_state
then on_state
else off_state
else &null
else &null
, bistable_state
) @ &source
end
procedure main()
local bistable, i
bistable := co_bistable("no","yes")
every i := 1 to 30 do {
if 1 = ?2
then write(" button -> off yields state ", "no" @ bistable)
else write("button -> ON yields state ", "yes" @ bistable)
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment