Partile Dev to handle all firmware operations (screen, LEDs and Peltier devices)
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_SSD1306.h>
#include "Adafruit_GFX.h"
//Control the mosfets for each peltier
int t1 = D1;
int t2 = D2;
//Power level 1 (0 to 99%)
int p1 = 0;
int p2 = 0;
//These are value from 0 to 255 that actually control the MOSFET via PWM
int p_level1 = map(p1, 0, 99, 0, 255);
int p_level2 = map(p2, 0, 99, 0, 255);
//variable holding input from twitter
String command = "a";
//leds
int l1 = D0;
int l2 = D6;
int l3 = D7;
//OLED Screen Control
#define OLED_DC D3
#define OLED_CS D4
#define OLED_RESET D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
String pName = "Politherm"; //variable to hold politician name
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC);
display.display();
delay(1000);
display.clearDisplay();
Serial.begin(9600);
Particle.subscribe("searches", finds);
Particle.variable("p1",p1);
Particle.variable("p2",p2);
Particle.variable("command",command);
pinMode(t1, OUTPUT);
pinMode(t2,OUTPUT);
pinMode(l1, OUTPUT);
pinMode(l2, OUTPUT);
pinMode(l3, OUTPUT);
}
void finds(const char *event, const char *data){
//receiving command
String d = data;
command = d.substring(0,1);
pName = d.substring(1);
Serial.print("infinds=");
Serial.println(pName);
Serial.println(command);
//turning command into output
if(command =="a")
{
p1 = 40;
p2 = 0;
digitalWrite(l1, HIGH);
delay(100);
digitalWrite(l2, HIGH);
delay(100);
digitalWrite(l3, HIGH);
delay(100);
}
else if(command == "b")
{
p1 = 0;
p2 = 40;
digitalWrite(l1, LOW);
delay(100);
digitalWrite(l2, LOW);
delay(100);
digitalWrite(l3, LOW);
}
else if(command == "o")
{
p1 = 0;
p2 = 0;
digitalWrite(l3, LOW);
delay(100);
digitalWrite(l3, LOW);
delay(100);
digitalWrite(l3, LOW);
}
p_level1 = map(p1, 0, 100, 0, 255);
p_level2 = map(p2,0,100,0,255);
// write to the appropriate pin
analogWrite(t1, p_level1); //Write this new value out to the port
analogWrite(t2, p_level2);
Serial.print(" p1=");
Serial.print(p_level1);
Serial.print(" p2=");
Serial.println(p_level2);
delay(1000);
}
void loop() {
display.clearDisplay();
display.setCursor(0,0);
display.setTextColor(WHITE);
display.setTextSize(2);
display.println(pName);
display.display();
display.startscrollright(0,21);
}
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. .