So I've put together some code using a waterproof ds18b20 sensor and the digiled for feedback.
If the temp is above my setpoint it goes red, below it goes blue and normal it's green.
Code is below the weird thing is that it works perfectly if plugged in to my laptop for power but if I plug it in to an anker 5 port usb charger it only displays blue any idea why that may be?
Thanks.
Ben
// Based on NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license
#include <Adafruit_NeoPixel.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Which pin on the Digispark is connected to the DigiLED?
#define PIN 5
// How many DigiLEDs are attached to the Digispark?
#define NUMPIXELS 1
// Data wire is plugged into pin 12 on the Arduino
#define ONE_WIRE_BUS 12
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// For the WS2812B type through hole LED used by the DigiLED, NEO_RGB + NEO_KHZ800 is the correct data format
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
int delayval = 10000; // delay for 10 seconds
//float
int temp_setpoint = 26; // ideal temperature is this
void setup()
{
// Start up the library
sensors.begin();
pixels.begin(); // This initializes the NeoPixel library.
pixels.show(); // Initialize all pixels to 'off'
}
void loop()
{
//read temperature from 1 wire device
sensors.requestTemperatures();
//float
int read_temp = sensors.getTempCByIndex(0);
if (read_temp < (temp_setpoint - 2)) //if temp is less than 25 make led blue
{
// blue
//Serial.print("Blue");
pixels.setPixelColor(0, pixels.Color(0, 0, 255)); //blue
pixels.show();
delay(delayval);
}
else if (read_temp > (temp_setpoint + 2)) //if temp is higher than 27 make led red
{
// red
//Serial.print("Red");
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); //red
pixels.show();
delay(delayval);
}
else //temp is ok so make it green
{
// green
//Serial.print("Green");
pixels.setPixelColor(0, pixels.Color(0, 255, 0)); //green
pixels.show();
delay(delayval);
}
}