{
  "format": "evn-blocks",
  "version": 3,
  "title": "VL53L1X distance sensor: every block",
  "needs": "an ST VL53L1X distance sensor on I2C port 1",
  "description": "Every block of the VL53L1X: ten seconds of distances in short range (up to about 1.3 m, better in daylight) at its fastest timing budget, 15 ms, then a 50 ms budget and ten seconds in long range (up to about 4 m in the dark); -1 when a reading is not valid; then 10 readings a second on an 8 x 8 field of view, the sensor itself detecting things closer than 200 mm (the 'detects' answer printed for five seconds) and between 100 and 300 mm (the distance printed, -1 when not detected), and every reading again.",
  "workspace": {
    "blocks": {
      "languageVersion": 0,
      "blocks": [
        {
          "type": "evn_setup_start",
          "x": 30,
          "y": 30,
          "next": {
            "block": {
              "type": "evn_vl53l1x_setup",
              "fields": {
                "PORT": "1"
              }
            }
          }
        },
        {
          "type": "evn_program_start",
          "x": 30,
          "y": 160,
          "next": {
            "block": {
              "type": "evn_vl53l1x_mode",
              "fields": {
                "PORT": "1",
                "MODE": "short"
              },
              "next": {
                "block": {
                  "type": "evn_vl53l1x_budget",
                  "fields": {
                    "PORT": "1",
                    "MS": "15"
                  },
                  "next": {
                    "block": {
                      "type": "controls_repeat_ext",
                      "inputs": {
                        "TIMES": {
                          "shadow": {
                            "type": "math_number",
                            "fields": {
                              "NUM": 20
                            }
                          }
                        },
                        "DO": {
                          "block": {
                            "type": "text_print",
                            "inputs": {
                              "TEXT": {
                                "block": {
                                  "type": "evn_vl53l1x_distance",
                                  "fields": {
                                    "PORT": "1"
                                  }
                                }
                              }
                            },
                            "next": {
                              "block": {
                                "type": "evn_wait",
                                "inputs": {
                                  "TIME": {
                                    "shadow": {
                                      "type": "math_number",
                                      "fields": {
                                        "NUM": 500
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      },
                      "next": {
                        "block": {
                          "type": "evn_vl53l1x_budget",
                          "fields": {
                            "PORT": "1",
                            "MS": "50"
                          },
                          "next": {
                            "block": {
                              "type": "evn_vl53l1x_mode",
                              "fields": {
                                "PORT": "1",
                                "MODE": "long"
                              },
                              "next": {
                                "block": {
                                  "type": "controls_repeat_ext",
                                  "inputs": {
                                    "TIMES": {
                                      "shadow": {
                                        "type": "math_number",
                                        "fields": {
                                          "NUM": 20
                                        }
                                      }
                                    },
                                    "DO": {
                                      "block": {
                                        "type": "text_print",
                                        "inputs": {
                                          "TEXT": {
                                            "block": {
                                              "type": "evn_vl53l1x_distance",
                                              "fields": {
                                                "PORT": "1"
                                              }
                                            }
                                          }
                                        },
                                        "next": {
                                          "block": {
                                            "type": "evn_wait",
                                            "inputs": {
                                              "TIME": {
                                                "shadow": {
                                                  "type": "math_number",
                                                  "fields": {
                                                    "NUM": 500
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  },
                                  "next": {
                                    "block": {
                                      "type": "evn_vl53l1x_inter",
                                      "fields": {
                                        "PORT": "1"
                                      },
                                      "inputs": {
                                        "MS": {
                                          "shadow": {
                                            "type": "math_number",
                                            "fields": {
                                              "NUM": 100
                                            }
                                          }
                                        }
                                      },
                                      "next": {
                                        "block": {
                                          "type": "evn_vl53l1x_roi",
                                          "fields": {
                                            "PORT": "1",
                                            "W": "8",
                                            "H": "8"
                                          },
                                          "next": {
                                            "block": {
                                              "type": "evn_vl53l1x_threshold",
                                              "fields": {
                                                "PORT": "1",
                                                "WHAT": "signal_threshold"
                                              },
                                              "inputs": {
                                                "VALUE": {
                                                  "shadow": {
                                                    "type": "math_number",
                                                    "fields": {
                                                      "NUM": 1024
                                                    }
                                                  }
                                                }
                                              },
                                              "next": {
                                                "block": {
                                                  "type": "evn_vl53l1x_detect",
                                                  "fields": {
                                                    "PORT": "1",
                                                    "WINDOW": "below"
                                                  },
                                                  "inputs": {
                                                    "MM": {
                                                      "shadow": {
                                                        "type": "math_number",
                                                        "fields": {
                                                          "NUM": 200
                                                        }
                                                      }
                                                    }
                                                  },
                                                  "next": {
                                                    "block": {
                                                      "type": "controls_repeat_ext",
                                                      "inputs": {
                                                        "TIMES": {
                                                          "shadow": {
                                                            "type": "math_number",
                                                            "fields": {
                                                              "NUM": 20
                                                            }
                                                          }
                                                        },
                                                        "DO": {
                                                          "block": {
                                                            "type": "text_print",
                                                            "inputs": {
                                                              "TEXT": {
                                                                "block": {
                                                                  "type": "evn_vl53l1x_detected",
                                                                  "fields": {
                                                                    "PORT": "1"
                                                                  }
                                                                }
                                                              }
                                                            },
                                                            "next": {
                                                              "block": {
                                                                "type": "evn_wait",
                                                                "inputs": {
                                                                  "TIME": {
                                                                    "shadow": {
                                                                      "type": "math_number",
                                                                      "fields": {
                                                                        "NUM": 250
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          }
                                                        }
                                                      },
                                                      "next": {
                                                        "block": {
                                                          "type": "evn_vl53l1x_detect_window",
                                                          "fields": {
                                                            "PORT": "1",
                                                            "WINDOW": "inside"
                                                          },
                                                          "inputs": {
                                                            "LOW": {
                                                              "shadow": {
                                                                "type": "math_number",
                                                                "fields": {
                                                                  "NUM": 100
                                                                }
                                                              }
                                                            },
                                                            "HIGH": {
                                                              "shadow": {
                                                                "type": "math_number",
                                                                "fields": {
                                                                  "NUM": 300
                                                                }
                                                              }
                                                            }
                                                          },
                                                          "next": {
                                                            "block": {
                                                              "type": "controls_repeat_ext",
                                                              "inputs": {
                                                                "TIMES": {
                                                                  "shadow": {
                                                                    "type": "math_number",
                                                                    "fields": {
                                                                      "NUM": 20
                                                                    }
                                                                  }
                                                                },
                                                                "DO": {
                                                                  "block": {
                                                                    "type": "text_print",
                                                                    "inputs": {
                                                                      "TEXT": {
                                                                        "block": {
                                                                          "type": "evn_vl53l1x_distance",
                                                                          "fields": {
                                                                            "PORT": "1"
                                                                          }
                                                                        }
                                                                      }
                                                                    },
                                                                    "next": {
                                                                      "block": {
                                                                        "type": "evn_wait",
                                                                        "inputs": {
                                                                          "TIME": {
                                                                            "shadow": {
                                                                              "type": "math_number",
                                                                              "fields": {
                                                                                "NUM": 250
                                                                              }
                                                                            }
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              },
                                                              "next": {
                                                                "block": {
                                                                  "type": "evn_vl53l1x_detect_off",
                                                                  "fields": {
                                                                    "PORT": "1"
                                                                  },
                                                                  "next": {
                                                                    "block": {
                                                                      "type": "evn_vl53l1x_roi",
                                                                      "fields": {
                                                                        "PORT": "1",
                                                                        "W": "16",
                                                                        "H": "16"
                                                                      },
                                                                      "next": {
                                                                        "block": {
                                                                          "type": "evn_vl53l1x_inter",
                                                                          "fields": {
                                                                            "PORT": "1"
                                                                          },
                                                                          "inputs": {
                                                                            "MS": {
                                                                              "shadow": {
                                                                                "type": "math_number",
                                                                                "fields": {
                                                                                  "NUM": 0
                                                                                }
                                                                              }
                                                                            }
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          }
                                                        }
                                                      }
                                                    }
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}
