Login
gpcr/examples/blink.cr
Login

[edit]

examples/blink.cr @ trunk

../src/gpcr/main

require '../src/gpcr/main'
scale = 0.75
fontscale = 1.500
box wid 2.215 ht 0.340 with .nw at (0.035, -0.035) fill 0xCBD5E1 color 0xCBD5E1
box wid 2.215 ht 0.340 with .nw at (0.000, 0.000) fill 0x7C83E6 color 0x7C83E6
box wid 0.300 ht 0.065 rad 0.018 at (0.370, -0.022) fill 0xffffff color 0xffffff
line from (0.140, 0.000) to (0.140, -0.340) color white
line from (2.075, 0.000) to (2.075, -0.340) color white
text "require '../src/gpcr/main'" color white at (1.108, -0.170)

crystal source

require "../src/gpcr/main"

json block

{
  "kind": "require",
  "name": "../src/gpcr/main",
  "doc": null,
  "children": []
}

blink

blink: LED on/off loop after start

on start 2 forever 3 set user LED  true 4 wait  0.5  seconds 5 set user LED  false 6 wait  0.5  seconds 7
scale = 0.75
fontscale = 1.500
box wid 0.870 ht 0.340 with .nw at (0.035, -0.455) fill 0xCBD5E1 color 0xCBD5E1
box wid 0.870 ht 0.340 with .nw at (0.000, -0.420) fill 0xFFAB19 color 0xFFAB19
ellipse wid 1.600 ht 0.340 at (0.800, -0.420) fill 0xFFAB19 color 0xFFAB19
box wid 0.300 ht 0.065 rad 0.018 at (0.370, -0.792) fill 0xFFAB19 color 0xFFAB19
text "on start" color white at (0.435, -0.590)
box wid 0.240 ht 0.220 rad 0.110 at (0.720, -0.560) fill 0x334155 color 0x334155
text "2" at (0.720, -0.560) color 0xf8fafc
box wid 2.720 ht 2.470 rad 0.035 with .nw at (0.035, -0.875) fill 0xCBD5E1 color 0xCBD5E1
box wid 2.720 ht 2.470 rad 0.035 with .nw at (0.000, -0.840) fill 0xFFAB19 color 0xFFAB19
box wid 2.340 ht 1.800 rad 0.035 with .nw at (0.320, -1.300) fill 0xFFFDE7 color 0xFFFDE7
box wid 0.300 ht 0.065 rad 0.018 at (0.370, -0.863) fill 0xffffff color 0xffffff
box wid 0.300 ht 0.065 rad 0.018 at (0.370, -3.343) fill 0xFFAB19 color 0xFFAB19
text "forever" color white at (1.360, -1.070)
box wid 0.240 ht 0.220 rad 0.110 at (2.570, -0.980) fill 0x334155 color 0x334155
text "3" at (2.570, -0.980) color 0xf8fafc
box wid 2.027 ht 0.340 rad 0.035 with .nw at (0.455, -1.395) fill 0xCBD5E1 color 0xCBD5E1
box wid 2.027 ht 0.340 rad 0.035 with .nw at (0.420, -1.360) fill 0x4C97FF color 0x4C97FF
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -1.383) fill 0xFFFDE7 color 0xFFFDE7
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -1.733) fill 0x4C97FF color 0x4C97FF
text "set user LED " color white at (1.096, -1.530)
box wid 0.555 ht 0.205 rad 0.102 with .nw at (1.692, -1.427) fill 0xFFFFFF color 0xFFFFFF
text "true" color 0x263238 at (1.970, -1.530)
box wid 0.240 ht 0.220 rad 0.110 at (2.297, -1.500) fill 0x334155 color 0x334155
text "4" at (2.297, -1.500) color 0xf8fafc
box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.455, -1.815) fill 0xCBD5E1 color 0xCBD5E1
box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.420, -1.780) fill 0xFFAB19 color 0xFFAB19
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -1.803) fill 0xFFFDE7 color 0xFFFDE7
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.152) fill 0xFFAB19 color 0xFFAB19
text "wait " color white at (0.742, -1.950)
box wid 0.496 ht 0.205 rad 0.102 with .nw at (1.029, -1.848) fill 0xFFFFFF color 0xFFFFFF
text "0.5" color 0x263238 at (1.277, -1.950)
text " seconds" color white at (1.939, -1.950)
box wid 0.240 ht 0.220 rad 0.110 at (2.283, -1.920) fill 0x334155 color 0x334155
text "5" at (2.283, -1.920) color 0xf8fafc
box wid 2.096 ht 0.340 rad 0.035 with .nw at (0.455, -2.235) fill 0xCBD5E1 color 0xCBD5E1
box wid 2.096 ht 0.340 rad 0.035 with .nw at (0.420, -2.200) fill 0x4C97FF color 0x4C97FF
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.223) fill 0xFFFDE7 color 0xFFFDE7
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.572) fill 0x4C97FF color 0x4C97FF
text "set user LED " color white at (1.096, -2.370)
box wid 0.624 ht 0.205 rad 0.102 with .nw at (1.692, -2.268) fill 0xFFFFFF color 0xFFFFFF
text "false" color 0x263238 at (2.004, -2.370)
box wid 0.240 ht 0.220 rad 0.110 at (2.366, -2.340) fill 0x334155 color 0x334155
text "6" at (2.366, -2.340) color 0xf8fafc
box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.455, -2.655) fill 0xCBD5E1 color 0xCBD5E1
box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.420, -2.620) fill 0xFFAB19 color 0xFFAB19
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.643) fill 0xFFFDE7 color 0xFFFDE7
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.992) fill 0xFFAB19 color 0xFFAB19
text "wait " color white at (0.742, -2.790)
box wid 0.496 ht 0.205 rad 0.102 with .nw at (1.029, -2.688) fill 0xFFFFFF color 0xFFFFFF
text "0.5" color 0x263238 at (1.277, -2.790)
text " seconds" color white at (1.939, -2.790)
box wid 0.240 ht 0.220 rad 0.110 at (2.283, -2.760) fill 0x334155 color 0x334155
text "7" at (2.283, -2.760) color 0xf8fafc
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -1.733) fill 0x4C97FF color 0x4C97FF
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.152) fill 0xFFAB19 color 0xFFAB19
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.572) fill 0x4C97FF color 0x4C97FF
box wid 0.300 ht 0.065 rad 0.018 at (0.790, -2.992) fill 0xFFAB19 color 0xFFAB19

crystal source

@[GPCR::Graph(x: 10, y: 30)]
def blink
  on_start
  forever do
    set_user_led true
    wait 0.5
    set_user_led false
    wait 0.5
  end
end

json block

{
  "kind": "graph",
  "name": "blink",
  "doc": "blink: LED on/off loop after start",
  "children": [
    {
      "kind": "call",
      "name": "on_start",
      "receiver": null,
      "op_index": 2,
      "args": [],
      "label": "on start",
      "shape": "hat",
      "category": "Events",
      "children": []
    },
    {
      "kind": "c_call",
      "name": "forever",
      "op_index": 3,
      "args": [],
      "body": [
        {
          "kind": "call",
          "name": "set_user_led",
          "receiver": null,
          "op_index": 4,
          "args": [
            "true"
          ],
          "label": "set user LED [true]",
          "shape": "command",
          "category": null,
          "children": []
        },
        {
          "kind": "call",
          "name": "wait",
          "receiver": null,
          "op_index": 5,
          "args": [
            "0.5"
          ],
          "label": "wait [0.5] seconds",
          "shape": "command",
          "category": "Control",
          "children": []
        },
        {
          "kind": "call",
          "name": "set_user_led",
          "receiver": null,
          "op_index": 6,
          "args": [
            "false"
          ],
          "label": "set user LED [false]",
          "shape": "command",
          "category": null,
          "children": []
        },
        {
          "kind": "call",
          "name": "wait",
          "receiver": null,
          "op_index": 7,
          "args": [
            "0.5"
          ],
          "label": "wait [0.5] seconds",
          "shape": "command",
          "category": "Control",
          "children": []
        }
      ]
    }
  ]
}