{
  "format": "evn-blocks",
  "version": 3,
  "title": "Colour sensor: every block",
  "needs": "the colour sensor on I2C port 1, a white sheet, and something blue to hold under it",
  "description": "Every colour sensor block once: the colour it sees, its light level, the numbers behind the colour (hue, saturation, brightness, red, green, blue), and a shorter list of colours to choose from, after a black / white calibration the board keeps for the port.",
  "workspace": {
    "blocks": {
      "languageVersion": 0,
      "blocks": [
        {
          "type": "evn_setup_start",
          "x": 30,
          "y": 30,
          "next": {
            "block": {
              "type": "evn_colorsensor_setup",
              "fields": {
                "PORT": "1"
              }
            }
          }
        },
        {
          "type": "evn_program_start",
          "x": 30,
          "y": 115,
          "next": {
            "block": {
              "type": "evn_comment",
              "fields": {
                "TEXT": "calibrate once (the board keeps it for this port): black with nothing in front, then white"
              },
              "next": {
                "block": {
                  "type": "text_print",
                  "inputs": {
                    "TEXT": {
                      "shadow": {
                        "type": "text",
                        "fields": {
                          "TEXT": "nothing in front of the sensor"
                        }
                      }
                    }
                  },
                  "next": {
                    "block": {
                      "type": "evn_wait",
                      "inputs": {
                        "TIME": {
                          "shadow": {
                            "type": "math_number",
                            "fields": {
                              "NUM": 3000
                            }
                          }
                        }
                      },
                      "next": {
                        "block": {
                          "type": "evn_colorsensor_calibrate",
                          "fields": {
                            "PORT": "1",
                            "WHAT": "black"
                          },
                          "next": {
                            "block": {
                              "type": "text_print",
                              "inputs": {
                                "TEXT": {
                                  "shadow": {
                                    "type": "text",
                                    "fields": {
                                      "TEXT": "hold a white sheet in front of the sensor"
                                    }
                                  }
                                }
                              },
                              "next": {
                                "block": {
                                  "type": "evn_wait",
                                  "inputs": {
                                    "TIME": {
                                      "shadow": {
                                        "type": "math_number",
                                        "fields": {
                                          "NUM": 3000
                                        }
                                      }
                                    }
                                  },
                                  "next": {
                                    "block": {
                                      "type": "evn_colorsensor_calibrate",
                                      "fields": {
                                        "PORT": "1",
                                        "WHAT": "white"
                                      },
                                      "next": {
                                        "block": {
                                          "type": "evn_comment",
                                          "fields": {
                                            "TEXT": "the colour it sees, ten times: move coloured things under the sensor"
                                          },
                                          "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_colorsensor_color",
                                                          "fields": {
                                                            "PORT": "1"
                                                          }
                                                        }
                                                      }
                                                    },
                                                    "next": {
                                                      "block": {
                                                        "type": "evn_wait",
                                                        "inputs": {
                                                          "TIME": {
                                                            "shadow": {
                                                              "type": "math_number",
                                                              "fields": {
                                                                "NUM": 300
                                                              }
                                                            }
                                                          }
                                                        }
                                                      }
                                                    }
                                                  }
                                                }
                                              },
                                              "next": {
                                                "block": {
                                                  "type": "evn_comment",
                                                  "fields": {
                                                    "TEXT": "how bright it is (% of full scale), and the numbers behind the colour"
                                                  },
                                                  "next": {
                                                    "block": {
                                                      "type": "text_print",
                                                      "inputs": {
                                                        "TEXT": {
                                                          "block": {
                                                            "type": "text_join",
                                                            "inputs": {
                                                              "ADD0": {
                                                                "shadow": {
                                                                  "type": "text",
                                                                  "fields": {
                                                                    "TEXT": "light level % "
                                                                  }
                                                                }
                                                              },
                                                              "ADD1": {
                                                                "block": {
                                                                  "type": "evn_colorsensor_ambient",
                                                                  "fields": {
                                                                    "PORT": "1"
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          }
                                                        }
                                                      },
                                                      "next": {
                                                        "block": {
                                                          "type": "text_print",
                                                          "inputs": {
                                                            "TEXT": {
                                                              "block": {
                                                                "type": "text_join",
                                                                "inputs": {
                                                                  "ADD0": {
                                                                    "shadow": {
                                                                      "type": "text",
                                                                      "fields": {
                                                                        "TEXT": "hue "
                                                                      }
                                                                    }
                                                                  },
                                                                  "ADD1": {
                                                                    "block": {
                                                                      "type": "evn_colorsensor_channel",
                                                                      "fields": {
                                                                        "PORT": "1",
                                                                        "WHAT": "hsv().h"
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          },
                                                          "next": {
                                                            "block": {
                                                              "type": "text_print",
                                                              "inputs": {
                                                                "TEXT": {
                                                                  "block": {
                                                                    "type": "text_join",
                                                                    "inputs": {
                                                                      "ADD0": {
                                                                        "shadow": {
                                                                          "type": "text",
                                                                          "fields": {
                                                                            "TEXT": "saturation "
                                                                          }
                                                                        }
                                                                      },
                                                                      "ADD1": {
                                                                        "block": {
                                                                          "type": "evn_colorsensor_channel",
                                                                          "fields": {
                                                                            "PORT": "1",
                                                                            "WHAT": "hsv().s"
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              },
                                                              "next": {
                                                                "block": {
                                                                  "type": "text_print",
                                                                  "inputs": {
                                                                    "TEXT": {
                                                                      "block": {
                                                                        "type": "text_join",
                                                                        "inputs": {
                                                                          "ADD0": {
                                                                            "shadow": {
                                                                              "type": "text",
                                                                              "fields": {
                                                                                "TEXT": "brightness "
                                                                              }
                                                                            }
                                                                          },
                                                                          "ADD1": {
                                                                            "block": {
                                                                              "type": "evn_colorsensor_channel",
                                                                              "fields": {
                                                                                "PORT": "1",
                                                                                "WHAT": "hsv().v"
                                                                              }
                                                                            }
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  },
                                                                  "next": {
                                                                    "block": {
                                                                      "type": "text_print",
                                                                      "inputs": {
                                                                        "TEXT": {
                                                                          "block": {
                                                                            "type": "text_join",
                                                                            "inputs": {
                                                                              "ADD0": {
                                                                                "shadow": {
                                                                                  "type": "text",
                                                                                  "fields": {
                                                                                    "TEXT": "red "
                                                                                  }
                                                                                }
                                                                              },
                                                                              "ADD1": {
                                                                                "block": {
                                                                                  "type": "evn_colorsensor_channel",
                                                                                  "fields": {
                                                                                    "PORT": "1",
                                                                                    "WHAT": "rgb()[0]"
                                                                                  }
                                                                                }
                                                                              }
                                                                            }
                                                                          }
                                                                        }
                                                                      },
                                                                      "next": {
                                                                        "block": {
                                                                          "type": "text_print",
                                                                          "inputs": {
                                                                            "TEXT": {
                                                                              "block": {
                                                                                "type": "text_join",
                                                                                "inputs": {
                                                                                  "ADD0": {
                                                                                    "shadow": {
                                                                                      "type": "text",
                                                                                      "fields": {
                                                                                        "TEXT": "green "
                                                                                      }
                                                                                    }
                                                                                  },
                                                                                  "ADD1": {
                                                                                    "block": {
                                                                                      "type": "evn_colorsensor_channel",
                                                                                      "fields": {
                                                                                        "PORT": "1",
                                                                                        "WHAT": "rgb()[1]"
                                                                                      }
                                                                                    }
                                                                                  }
                                                                                }
                                                                              }
                                                                            }
                                                                          },
                                                                          "next": {
                                                                            "block": {
                                                                              "type": "text_print",
                                                                              "inputs": {
                                                                                "TEXT": {
                                                                                  "block": {
                                                                                    "type": "text_join",
                                                                                    "inputs": {
                                                                                      "ADD0": {
                                                                                        "shadow": {
                                                                                          "type": "text",
                                                                                          "fields": {
                                                                                            "TEXT": "blue "
                                                                                          }
                                                                                        }
                                                                                      },
                                                                                      "ADD1": {
                                                                                        "block": {
                                                                                          "type": "evn_colorsensor_channel",
                                                                                          "fields": {
                                                                                            "PORT": "1",
                                                                                            "WHAT": "rgb()[2]"
                                                                                          }
                                                                                        }
                                                                                      }
                                                                                    }
                                                                                  }
                                                                                }
                                                                              },
                                                                              "next": {
                                                                                "block": {
                                                                                  "type": "evn_comment",
                                                                                  "fields": {
                                                                                    "TEXT": "choose only from blue, white and nothing: then look for blue for 5 s"
                                                                                  },
                                                                                  "next": {
                                                                                    "block": {
                                                                                      "type": "evn_colorsensor_detect",
                                                                                      "fields": {
                                                                                        "PORT": "1",
                                                                                        "RED": "FALSE",
                                                                                        "YELLOW": "FALSE",
                                                                                        "GREEN": "FALSE",
                                                                                        "BLUE": "TRUE",
                                                                                        "WHITE": "TRUE",
                                                                                        "NONE": "TRUE"
                                                                                      },
                                                                                      "next": {
                                                                                        "block": {
                                                                                          "type": "controls_repeat_ext",
                                                                                          "inputs": {
                                                                                            "TIMES": {
                                                                                              "shadow": {
                                                                                                "type": "math_number",
                                                                                                "fields": {
                                                                                                  "NUM": 25
                                                                                                }
                                                                                              }
                                                                                            },
                                                                                            "DO": {
                                                                                              "block": {
                                                                                                "type": "controls_if",
                                                                                                "inputs": {
                                                                                                  "IF0": {
                                                                                                    "block": {
                                                                                                      "type": "evn_colorsensor_sees",
                                                                                                      "fields": {
                                                                                                        "PORT": "1",
                                                                                                        "COLOR": "BLUE"
                                                                                                      }
                                                                                                    }
                                                                                                  },
                                                                                                  "DO0": {
                                                                                                    "block": {
                                                                                                      "type": "text_print",
                                                                                                      "inputs": {
                                                                                                        "TEXT": {
                                                                                                          "shadow": {
                                                                                                            "type": "text",
                                                                                                            "fields": {
                                                                                                              "TEXT": "blue!"
                                                                                                            }
                                                                                                          }
                                                                                                        }
                                                                                                      }
                                                                                                    }
                                                                                                  }
                                                                                                },
                                                                                                "next": {
                                                                                                  "block": {
                                                                                                    "type": "evn_wait",
                                                                                                    "inputs": {
                                                                                                      "TIME": {
                                                                                                        "shadow": {
                                                                                                          "type": "math_number",
                                                                                                          "fields": {
                                                                                                            "NUM": 200
                                                                                                          }
                                                                                                        }
                                                                                                      }
                                                                                                    }
                                                                                                  }
                                                                                                }
                                                                                              }
                                                                                            }
                                                                                          },
                                                                                          "next": {
                                                                                            "block": {
                                                                                              "type": "evn_comment",
                                                                                              "fields": {
                                                                                                "TEXT": "back to all six colours"
                                                                                              },
                                                                                              "next": {
                                                                                                "block": {
                                                                                                  "type": "evn_colorsensor_detect",
                                                                                                  "fields": {
                                                                                                    "PORT": "1",
                                                                                                    "RED": "TRUE",
                                                                                                    "YELLOW": "TRUE",
                                                                                                    "GREEN": "TRUE",
                                                                                                    "BLUE": "TRUE",
                                                                                                    "WHITE": "TRUE",
                                                                                                    "NONE": "TRUE"
                                                                                                  }
                                                                                                }
                                                                                              }
                                                                                            }
                                                                                          }
                                                                                        }
                                                                                      }
                                                                                    }
                                                                                  }
                                                                                }
                                                                              }
                                                                            }
                                                                          }
                                                                        }
                                                                      }
                                                                    }
                                                                  }
                                                                }
                                                              }
                                                            }
                                                          }
                                                        }
                                                      }
                                                    }
                                                  }
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}
