New electric imp user here. I’m trying to add analog reading pin2 water sensor to the sensor tweet exercise in the explorer tutorials.
I’m missing something since I don’t understand the reading versus conditions part of the function. Any help would be appreciated:
#require “HTS221.class.nut:1.0.0”
#require “LPS22HB.class.nut:1.0.0”
#require “WS2812.class.nut:3.0.0”
// Define constants
const sleepTime = 30;
// Declare Global Variables
tempSensor <- null;
pressureSensor <- null;
led <- null
waterSensor <- hardware.pin2;
// Define functions
function takeReading(){
local conditions = {};
local reading = tempSensor.read();
conditions.temp <- reading.temperature;
conditions.humid <- reading.humidity;
reading = pressureSensor.read();
conditions.press <- reading.pressure;
reading = waterSensor.read();
// Send 'conditions' to the agent
agent.send("reading.sent", conditions);
// Flash the LED
flashLed();
// Set the imp to sleep when idle, ie. program complete
imp.onidle(function() {
server.sleepfor(sleepTime);
});
}
function flashLed() {
led.set(0, [100,0,28]).draw();
imp.sleep(2);
led.set(0, [0,0,0]).draw();
}
// Start of program
// Configure I2C bus for sensors
local i2c = hardware.i2c89;
i2c.configure(CLOCK_SPEED_400_KHZ);
tempSensor = HTS221(i2c);
tempSensor.setMode(HTS221_MODE.ONE_SHOT);
pressureSensor = LPS22HB(i2c);
pressureSensor.softReset();
// Configure SPI bus and powergate pin for RGB LED
local spi = hardware.spi257;
spi.configure(MSB_FIRST, 7500);
hardware.pin1.configure(DIGITAL_OUT, 1);
waterSensor.configure(ANALOG_IN);
led <- WS2812(spi, 1);
// Take a reading
takeReading();