Ambiente y sensores
Sensores que miden condiciones del entorno. Casi todos emiten data (periódico) y
change (al cambiar), y muchos requieren elegir el chip con la opción controller
(ver Introducción).
Light (luz)
Sección titulada «Light (luz)»new five.Light(pin) o new five.Light({ controller, ... }).
Controllers: DEFAULT (LDR/fotorresistencia en un pin analógico), TSL2561,
BH1750, ALSPT19 (por I2C).
Propiedades: value (crudo), level (0–1 normalizado), lux (en chips que dan
lux reales).
Eventos: data → { level, lux }; change → { level, lux }.
const luz = new five.Light("A0"); // LDR en A0luz.on("change", () => { varG.nivelLuz = luz.level; // 0–1});new five.Color({ controller }). No tiene controller por defecto: hay que
indicarlo.
Controllers: ISL29125 (I2C), EVS_EV3, EVS_NXT.
Propiedades: value, rgb → { red, green, blue }.
Eventos: data → { rgb }; change → { rgb }.
const color = new five.Color({ controller: "ISL29125" });color.on("data", () => { varG.rgb = color.rgb; // { red, green, blue }});Motion (movimiento)
Sección titulada «Motion (movimiento)»new five.Motion(pin) o new five.Motion({ controller }). Detecta presencia/movimiento.
Controllers: PIR (default, sensor PIR en un pin digital) y la familia Sharp
GP2Y0D805/GP2Y0D810/GP2Y0D815/GP2Y0A60SZLF (con alias como HCSR501).
Propiedades: detectedMotion (bool), isCalibrated (bool).
Eventos
| Evento | Cuándo | Qué recibe |
|---|---|---|
calibrated | cuando el sensor termina de calibrarse | sin payload |
motionstart | al empezar a detectar movimiento | sin payload |
motionend | cuando cesa el movimiento | sin payload |
data | periódico | { timestamp, detectedMotion, isCalibrated } |
change | al cambiar la detección | { timestamp, detectedMotion, isCalibrated } |
const pir = new five.Motion(7);pir.on("motionstart", () => { varG.presencia = true; });pir.on("motionend", () => { varG.presencia = false; });Proximity (distancia)
Sección titulada «Proximity (distancia)»new five.Proximity(pin) o new five.Proximity({ controller }). Mide distancia.
Propiedades: cm / centimeters, in / inches.
Eventos: data → { cm, centimeters, in, inches }; change → igual.
Controllers
| Tipo | Controllers | Estado |
|---|---|---|
| Por I2C | SRF10, HCSR04I2CBACKPACK, LIDARLITE | funcionan |
| Analógicos (IR/ultrasonido por ADC) | familia GP2Y0A… (Sharp IR), MB1000/MB1003/MB1230 (MaxSonar) | funcionan |
| EVShield | EVS_EV3_IR, EVS_EV3_US | funcionan |
const prox = new five.Proximity({ controller: "HCSR04I2CBACKPACK" });prox.on("data", () => { varG.distancia = prox.cm;});Thermometer (temperatura)
Sección titulada «Thermometer (temperatura)»new five.Thermometer({ controller, pin }). Por defecto, ANALOG (un sensor de
temperatura en un pin analógico).
Controllers (~25): ANALOG (default), LM35, LM335, TMP36, TMP102,
DS18B20, MAX31850K, MCP9808, BMP180, BMP280, BME280, MPL115A2,
MPL3115A2, MS5611, SHT31D, HTU21D, HIH6130, SI7020, TH02, MPU6050,
BNO055, DHT_I2C_NANO_BACKPACK, entre otros.
Propiedades: celsius / C, fahrenheit / F, kelvin / K, freq
(intervalo, reasignable).
Métodos: enable() / disable() (reanuda/detiene las lecturas).
Eventos: data → { celsius, C, fahrenheit, F, kelvin, K }; change → igual.
(error en DS18B20/MAX31850K si hay más de un sensor sin indicar address.)
const termo = new five.Thermometer({ controller: "BMP280" });termo.on("change", () => { varG.temperatura = termo.celsius; pushData("temperaturas", termo.celsius);});Hygrometer (humedad)
Sección titulada «Hygrometer (humedad)»new five.Hygrometer({ controller }). No tiene controller por defecto.
Controllers: SHT31D, HTU21D, HIH6130, SI7020, TH02, BME280,
DHT_I2C_NANO_BACKPACK.
Propiedades: relativeHumidity / RH (humedad relativa en %).
Eventos: data → { relativeHumidity, RH }; change → igual.
const higro = new five.Hygrometer({ controller: "HTU21D" });higro.on("change", () => { varG.humedad = higro.relativeHumidity; // %});Barometer (presión)
Sección titulada «Barometer (presión)»new five.Barometer({ controller }). No tiene controller por defecto.
Controllers: MPL115A2, MPL3115A2, BMP180, BMP280, BME280, MS5611.
Propiedades: pressure (en kPa).
Eventos: data → { pressure }; change → igual.
const baro = new five.Barometer({ controller: "BMP280" });baro.on("data", () => { varG.presion = baro.pressure; // kPa});Altimeter (altitud)
Sección titulada «Altimeter (altitud)»new five.Altimeter({ controller, elevation }). No tiene controller por defecto.
Algunos chips aceptan elevation (altitud de referencia) para mejorar la medida.
Controllers: MPL3115A2, MS5611, BMP180, BMP280, BME280.
Propiedades: meters / m, feet / ft.
Eventos: data → { meters, m, feet, ft }; change → igual.
const alti = new five.Altimeter({ controller: "BMP280" });alti.on("change", () => { varG.altitud = alti.meters;});