//Feeling the warmth side code//
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
int PeltierPin = D2;
int TouchPin = A3;
int touch = 0;
int touchreading =0;
int count2 = -1;
int i = 0;
#define PIXEL_PIN D4
//define the pin neopixel is connected to
#define PIXEL_COUNT 7
//define the pixel count of the neopixel
#define PIXEL_TYPE WS2812
//define neopixel type
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
//Define again that this is a adafruit neopixel
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int timeGreen = 1000 * 60 *1;
int timeFeel = 1000 * 60 *1;
float expave = 0;
float weight = 0.8;
int roundedexpave = 0;
//long timerStartedAt = -1 ;
//int timeToStart = 0;
void setup()
{
Particle.publish( "ready to feel the warmth" );
pinMode(TouchPin, INPUT);
//Initiate Touch Pin as Input Pin
pinMode(PeltierPin, OUTPUT);
//Initiate Peltier Pin as Output Pin
Particle.variable("TouchDetect", &touch, INT);
Particle.variable("count", &count2, INT);
Particle.variable("i", &i, INT);
strip.begin();
strip.clear();
strip.show();
//strip.clear();
}
void UpdateNeo(){
//i = level % 7;
//i = i +1;
i = count2;
//show red pixel
uint32_t c = strip.Color(255, 0, 0);
if (i <= 2){
strip.setPixelColor(i, c);
strip.show();
}
//show blue pixels
c = strip.Color(0, 0, 255);
if ((i >= 3) and (i <= 6)){
//strip.setBrightness(255/(i+1));
//setBrightness funciton will slowly dim the LED strip
strip.setPixelColor(i, c);
strip.show();
}
//show white pixel
c = strip.Color(255, 255, 255);
if ( i >= 7){
//strip.setBrightness(255/(i+1));
strip.setPixelColor(i, c);
strip.show();
}
}
void loop()
{
//read the touch value and assign to touch variable
count2 = count2 + 1;
//Particle.publish("count", String(count2));
touch = analogRead(TouchPin);
//delay(6000);
//touchreading = map( touch, 0, 4095, 0, 255);
if (touch > 3000){
//Heat Peltier
digitalWrite(PeltierPin, HIGH);
//Update Neo with sequence
UpdateNeo();
//initialize the peltier now itself
if (count2 == 8){
count2 = 0;
}
}else{
//Reset count
count2 = -1;
//Turn off Neo
digitalWrite(PeltierPin, LOW);
strip.clear();
strip.show();
}
delay(2000);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .