Coding for Soylent Dispenser
#include "Adafruit_GFX.h"
#include "Adafruit_SSD1306.h"
#define OLED_DC D3
#define OLED_CS D4
#define OLED_RESET D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16
int calo;
static const unsigned char logo16_glcd_bmp[] =
{ 0B00000000, 0B11000000,
0B00000001, 0B11000000,
0B00000001, 0B11000000,
0B00000011, 0B11100000,
0B11110011, 0B11100000,
0B11111110, 0B11111000,
0B01111110, 0B11111111,
0B00110011, 0B10011111,
0B00011111, 0B11111100,
0B00001101, 0B01110000,
0B00011011, 0B10100000,
0B00111111, 0B11100000,
0B00111111, 0B11110000,
0B01111100, 0B11110000,
0B01110000, 0B01110000,
0B00000000, 0B00110000 };
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay(); // clears the screen and buffer
Particle.subscribe("himanshu2016/lat",myHandler);
Serial.begin(9600);
}
void loop()
{
Serial.println("started");
if(calo<8)
{
Serial.println("<8");
display.setTextSize(2);
display.setTextColor(BLACK, WHITE);
display.setCursor(0,2); // 128(<>,◊)64
display.println("LESS WORK");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10,20); // 128(<>,◊)64
display.println("DISPENSE");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(20,50); // 128(<>,◊)64
display.println("200 ml");
display.display();
Serial.print (calo);
delay(1000);
}
else if(calo>8)
{
// if(calories<15)
Serial.println(">8");
display.setTextSize(2);
display.setTextColor(BLACK, WHITE);
display.setCursor(0,2); // 128(<>,◊)64
display.println("MORE WORK");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10,20); // 128(<>,◊)64
display.println("DISPENSE");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(20,50); // 128(<>,◊)64
display.println("500 ml");
display.display();
delay(1000);
Serial.print (calo);
//void myHandler(const char *event, const char *data);
}
//Serial.print(calories);
//Serial.print(" cal ");
}
void myHandler(const char *event, const char *data)
{
Serial.println("received =");
Serial.println( data );
Serial.println( event );
// conver the data to a String type.
String dataStr = data;
// check for error stuff
// if there isn't data do nothing
//if (!data) return;
// We only want to handle events
// From our paired device
// We're not interested in stuff that's come from
// this device ...
//String myID = System.deviceID();
// if the device that sent is this device... ignore. return exits this function
//if( dataStr.indexOf( myID ) > -1 ) return;
// If we get to here, it's an event we care about
//Serial.println( "Not from another ... ");
// Extract the angle from the data string
// by chopping off the piece before the comma
//int index = dataStr.indexOf(",");
//String value = dataStr.substring( 0, index );
int calo = dataStr.toInt();
Serial.println(calo);
}
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. .