This script is supposed to activate a rainbow with neopixels and a sound with a buzzer using temperature as an input. All the three scripts work separately and this one is verified with no errors. When flashed, nothing happens.
Anyone know what the problem can be? Thank you.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT_Particle.h>
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
/*
* This is a minimal example, see extra-examples.cpp for a version
* with more explantory documentation, example routines, how to
* hook up your pixels and all of the pixel types that are supported.
*
*/
#include "Particle.h"
#include "neopixel.h"
// Declare some variables
int timeCounter = 0;
int publishCounter = 0;
int publishTemp = 0;
double tempC = 0;
// Create a software timer to publish at an interval
Timer publishTemperature(1500, publish);
SYSTEM_MODE(AUTOMATIC);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D6
#define PIXEL_COUNT 12
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// Prototypes for local build, ok to leave in for Build IDE
void rainbow(uint8_t wait);
uint32_t Wheel(byte WheelPos);
void setup()
{
strip.begin();
strip.show();
// Make the A0 pin an INPUT
pinMode(A0, INPUT);
// Particle Cloud Subscribe to Event
Particle.subscribe("PublishTemp", subscribeHandler);
// Publish temperature reading
publishTemperature.start();// Initialize all pixels to 'off'
}
void loop()
{
publishTemp = analogRead(A0);
//Convert to Celcius
tempC = (((publishTemp *3.3)/4095)-0.5)*100;
//update Temp every .2 seconds
delay(200);
if (tempC < -20)
{
rainbow(20);
}
if (tempC > -65)
{
sound();
}
if (tempC > -21)
{
rainbow(20);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
void sound (){
analogWrite(D3, 200);
}
void publish(){
// Publish something
Particle.publish("PublishTemp", String(tempC));
// Increment counter
publishTemp;
}
// Handler function for event subscription
void subscribeHandler(const char *event, const char *data){
}