// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT_Particle.h>
#define DHTPIN A0
#define DHTTYPE DHT11
#define SNDPIN A1
#define FRCPIN A2
#define R1PIN D3
#define B1PIN D4
#define R2PIN D5
#define B2PIN D6
#define UPDATE 500ms
//Change this to the max expected value of sound input
float soundMax = 4096;
//Change this to the max expected value of force input
float forceMax = 4096;
DHT dht(DHTPIN, DHT11, 8);
void setup() {
Particle.publish("Testing logging");
dht.begin();
pinMode(SNDPIN, INPUT);
pinMode(FRCPIN, INPUT);
pinMode(R1PIN, OUTPUT);
pinMode(B1PIN, OUTPUT);
pinMode(R2PIN, OUTPUT);
pinMode(B2PIN, OUTPUT);
}
void loop() {
int temp = dht.getTempCelcius(); // read temperature
Particle.publish("Temperature", String(temp));
int sound = analogRead(SNDPIN);
Particle.publish("Sound", String(sound));
int force = analogRead(FRCPIN);
Particle.publish("Force", String(force));
String out = String::format("{\"temperature\":%d,\"sound\":%d,\"force\":%d}",temp, sound, force);
//Posts to a webhook linked to a google webapp script
Particle.publish("blob", out , PRIVATE, WITH_ACK);
float soundFactor = sound/soundMax;
float forceFactor = force/forceMax;
setRB(soundFactor * (temp*10), soundFactor * (255 - (temp*10)), R1PIN, B1PIN);
delay(UPDATE);
setRB(forceFactor * (temp*10), forceFactor * (255 - (temp*10)), R2PIN, B2PIN);
delay(UPDATE);
}
void setRB(int red, int blue, int pinR, int pinB) {
if(red < 0) {
red = 0;
}
if(red > 255) {
red = 255;
}
if(blue < 0) {
blue = 0;
}
if(blue > 255) {
blue = 255;
}
analogWrite(pinR, red);
analogWrite(pinB, blue);
}
Comments