{
  "format": "evn-blocks",
  "version": 3,
  "title": "Gesture sensor: every block",
  "needs": "the gesture sensor on I2C port 1 (nothing over it at the start), a hand or a black card, a white sheet, and something coloured",
  "description": "Every gesture sensor block once: how close your hand is, the colour the sensor sees, waiting for a swipe, and checking for one without waiting. The directions are the way the hand moved with the module's label upright, after a black / white colour calibration the board keeps for the port.",
  "workspace": {
    "blocks": {
      "languageVersion": 0,
      "blocks": [
        {
          "type": "evn_setup_start",
          "x": 30,
          "y": 30,
          "next": {
            "block": {
              "type": "evn_gesture_setup",
              "fields": {
                "PORT": "1"
              }
            }
          }
        },
        {
          "type": "evn_program_start",
          "x": 30,
          "y": 115,
          "next": {
            "block": {
              "type": "evn_comment",
              "fields": {
                "TEXT": "calibrate the colour once (the board keeps it for this port). The LED is infrared, so the colour sees the room light: black = the sensor covered completely, white = a white sheet in the room light. Swipes off first: gesture mode freezes the colour and the calibration refuses it"
              },
              "next": {
                "block": {
                  "type": "evn_python",
                  "fields": {
                    "CODE": "gesture_sensor_1.engines(gesture=False)"
                  },
                  "next": {
                    "block": {
                      "type": "text_print",
                      "inputs": {
                        "TEXT": {
                          "shadow": {
                            "type": "text",
                            "fields": {
                              "TEXT": "cover the sensor completely (a hand or a black card on it)"
                            }
                          }
                        }
                      },
                      "next": {
                        "block": {
                          "type": "evn_wait",
                          "inputs": {
                            "TIME": {
                              "shadow": {
                                "type": "math_number",
                                "fields": {
                                  "NUM": 3000
                                }
                              }
                            }
                          },
                          "next": {
                            "block": {
                              "type": "evn_gesture_calibrate",
                              "fields": {
                                "PORT": "1",
                                "WHAT": "black"
                              },
                              "next": {
                                "block": {
                                  "type": "text_print",
                                  "inputs": {
                                    "TEXT": {
                                      "shadow": {
                                        "type": "text",
                                        "fields": {
                                          "TEXT": "hold a white sheet a few cm above the sensor, in the room light"
                                        }
                                      }
                                    }
                                  },
                                  "next": {
                                    "block": {
                                      "type": "evn_wait",
                                      "inputs": {
                                        "TIME": {
                                          "shadow": {
                                            "type": "math_number",
                                            "fields": {
                                              "NUM": 3000
                                            }
                                          }
                                        }
                                      },
                                      "next": {
                                        "block": {
                                          "type": "evn_gesture_calibrate",
                                          "fields": {
                                            "PORT": "1",
                                            "WHAT": "white"
                                          },
                                          "next": {
                                            "block": {
                                              "type": "evn_python",
                                              "fields": {
                                                "CODE": "gesture_sensor_1.engines(gesture=True)"
                                              },
                                              "next": {
                                                "block": {
                                                  "type": "evn_comment",
                                                  "fields": {
                                                    "TEXT": "how close: 0 (nothing there) to 255 (very close). A hand held still close by freezes the number until it moves away (the sensor is then watching for a swipe)"
                                                  },
                                                  "next": {
                                                    "block": {
                                                      "type": "controls_repeat_ext",
                                                      "inputs": {
                                                        "TIMES": {
                                                          "shadow": {
                                                            "type": "math_number",
                                                            "fields": {
                                                              "NUM": 30
                                                            }
                                                          }
                                                        },
                                                        "DO": {
                                                          "block": {
                                                            "type": "text_print",
                                                            "inputs": {
                                                              "TEXT": {
                                                                "block": {
                                                                  "type": "text_join",
                                                                  "inputs": {
                                                                    "ADD0": {
                                                                      "shadow": {
                                                                        "type": "text",
                                                                        "fields": {
                                                                          "TEXT": "proximity "
                                                                        }
                                                                      }
                                                                    },
                                                                    "ADD1": {
                                                                      "block": {
                                                                        "type": "evn_gesture_proximity",
                                                                        "fields": {
                                                                          "PORT": "1"
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              }
                                                            },
                                                            "next": {
                                                              "block": {
                                                                "type": "evn_wait",
                                                                "inputs": {
                                                                  "TIME": {
                                                                    "shadow": {
                                                                      "type": "math_number",
                                                                      "fields": {
                                                                        "NUM": 100
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          }
                                                        }
                                                      },
                                                      "next": {
                                                        "block": {
                                                          "type": "evn_comment",
                                                          "fields": {
                                                            "TEXT": "the colour it sees: hold something coloured close above it. Swipes off meanwhile: with them on, something held close freezes the colour and can stop the program with an error"
                                                          },
                                                          "next": {
                                                            "block": {
                                                              "type": "evn_python",
                                                              "fields": {
                                                                "CODE": "gesture_sensor_1.engines(gesture=False)"
                                                              },
                                                              "next": {
                                                                "block": {
                                                                  "type": "controls_repeat_ext",
                                                                  "inputs": {
                                                                    "TIMES": {
                                                                      "shadow": {
                                                                        "type": "math_number",
                                                                        "fields": {
                                                                          "NUM": 10
                                                                        }
                                                                      }
                                                                    },
                                                                    "DO": {
                                                                      "block": {
                                                                        "type": "text_print",
                                                                        "inputs": {
                                                                          "TEXT": {
                                                                            "block": {
                                                                              "type": "evn_gesture_color",
                                                                              "fields": {
                                                                                "PORT": "1"
                                                                              }
                                                                            }
                                                                          }
                                                                        },
                                                                        "next": {
                                                                          "block": {
                                                                            "type": "evn_wait",
                                                                            "inputs": {
                                                                              "TIME": {
                                                                                "shadow": {
                                                                                  "type": "math_number",
                                                                                  "fields": {
                                                                                    "NUM": 300
                                                                                  }
                                                                                }
                                                                              }
                                                                            }
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  },
                                                                  "next": {
                                                                    "block": {
                                                                      "type": "text_print",
                                                                      "inputs": {
                                                                        "TEXT": {
                                                                          "shadow": {
                                                                            "type": "text",
                                                                            "fields": {
                                                                              "TEXT": "take it away"
                                                                            }
                                                                          }
                                                                        }
                                                                      },
                                                                      "next": {
                                                                        "block": {
                                                                          "type": "evn_wait",
                                                                          "inputs": {
                                                                            "TIME": {
                                                                              "shadow": {
                                                                                "type": "math_number",
                                                                                "fields": {
                                                                                  "NUM": 2000
                                                                                }
                                                                              }
                                                                            }
                                                                          },
                                                                          "next": {
                                                                            "block": {
                                                                              "type": "evn_comment",
                                                                              "fields": {
                                                                                "TEXT": "swipes back on, with nothing over the sensor"
                                                                              },
                                                                              "next": {
                                                                                "block": {
                                                                                  "type": "evn_python",
                                                                                  "fields": {
                                                                                    "CODE": "gesture_sensor_1.engines(gesture=True)"
                                                                                  },
                                                                                  "next": {
                                                                                    "block": {
                                                                                      "type": "evn_comment",
                                                                                      "fields": {
                                                                                        "TEXT": "wait for three swipes (None when none comes within 5 s)"
                                                                                      },
                                                                                      "next": {
                                                                                        "block": {
                                                                                          "type": "controls_repeat_ext",
                                                                                          "inputs": {
                                                                                            "TIMES": {
                                                                                              "shadow": {
                                                                                                "type": "math_number",
                                                                                                "fields": {
                                                                                                  "NUM": 3
                                                                                                }
                                                                                              }
                                                                                            },
                                                                                            "DO": {
                                                                                              "block": {
                                                                                                "type": "text_print",
                                                                                                "inputs": {
                                                                                                  "TEXT": {
                                                                                                    "block": {
                                                                                                      "type": "evn_gesture_wait",
                                                                                                      "fields": {
                                                                                                        "PORT": "1"
                                                                                                      },
                                                                                                      "inputs": {
                                                                                                        "TIMEOUT": {
                                                                                                          "shadow": {
                                                                                                            "type": "math_number",
                                                                                                            "fields": {
                                                                                                              "NUM": 5000
                                                                                                            }
                                                                                                          }
                                                                                                        }
                                                                                                      }
                                                                                                    }
                                                                                                  }
                                                                                                }
                                                                                              }
                                                                                            }
                                                                                          },
                                                                                          "next": {
                                                                                            "block": {
                                                                                              "type": "evn_comment",
                                                                                              "fields": {
                                                                                                "TEXT": "check for a swipe without waiting, for 10 s: each swipe is reported once, None in between"
                                                                                              },
                                                                                              "next": {
                                                                                                "block": {
                                                                                                  "type": "controls_repeat_ext",
                                                                                                  "inputs": {
                                                                                                    "TIMES": {
                                                                                                      "shadow": {
                                                                                                        "type": "math_number",
                                                                                                        "fields": {
                                                                                                          "NUM": 200
                                                                                                        }
                                                                                                      }
                                                                                                    },
                                                                                                    "DO": {
                                                                                                      "block": {
                                                                                                        "type": "variables_set",
                                                                                                        "fields": {
                                                                                                          "VAR": {
                                                                                                            "id": "v_swipe"
                                                                                                          }
                                                                                                        },
                                                                                                        "inputs": {
                                                                                                          "VALUE": {
                                                                                                            "block": {
                                                                                                              "type": "evn_gesture_gesture",
                                                                                                              "fields": {
                                                                                                                "PORT": "1"
                                                                                                              }
                                                                                                            }
                                                                                                          }
                                                                                                        },
                                                                                                        "next": {
                                                                                                          "block": {
                                                                                                            "type": "controls_if",
                                                                                                            "inputs": {
                                                                                                              "IF0": {
                                                                                                                "block": {
                                                                                                                  "type": "logic_compare",
                                                                                                                  "fields": {
                                                                                                                    "OP": "NEQ"
                                                                                                                  },
                                                                                                                  "inputs": {
                                                                                                                    "A": {
                                                                                                                      "block": {
                                                                                                                        "type": "variables_get",
                                                                                                                        "fields": {
                                                                                                                          "VAR": {
                                                                                                                            "id": "v_swipe"
                                                                                                                          }
                                                                                                                        }
                                                                                                                      }
                                                                                                                    },
                                                                                                                    "B": {
                                                                                                                      "block": {
                                                                                                                        "type": "logic_null"
                                                                                                                      }
                                                                                                                    }
                                                                                                                  }
                                                                                                                }
                                                                                                              },
                                                                                                              "DO0": {
                                                                                                                "block": {
                                                                                                                  "type": "text_print",
                                                                                                                  "inputs": {
                                                                                                                    "TEXT": {
                                                                                                                      "block": {
                                                                                                                        "type": "variables_get",
                                                                                                                        "fields": {
                                                                                                                          "VAR": {
                                                                                                                            "id": "v_swipe"
                                                                                                                          }
                                                                                                                        }
                                                                                                                      }
                                                                                                                    }
                                                                                                                  }
                                                                                                                }
                                                                                                              }
                                                                                                            },
                                                                                                            "next": {
                                                                                                              "block": {
                                                                                                                "type": "evn_wait",
                                                                                                                "inputs": {
                                                                                                                  "TIME": {
                                                                                                                    "shadow": {
                                                                                                                      "type": "math_number",
                                                                                                                      "fields": {
                                                                                                                        "NUM": 50
                                                                                                                      }
                                                                                                                    }
                                                                                                                  }
                                                                                                                }
                                                                                                              }
                                                                                                            }
                                                                                                          }
                                                                                                        }
                                                                                                      }
                                                                                                    }
                                                                                                  }
                                                                                                }
                                                                                              }
                                                                                            }
                                                                                          }
                                                                                        }
                                                                                      }
                                                                                    }
                                                                                  }
                                                                                }
                                                                              }
                                                                            }
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          }
                                                        }
                                                      }
                                                    }
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      ]
    },
    "variables": [
      {
        "name": "swipe",
        "id": "v_swipe"
      }
    ]
  }
}
