Skip to content

Instantly share code, notes, and snippets.

@myazakky
Last active September 10, 2021 00:04
Show Gist options
  • Save myazakky/9ce3dab5520c8f93874034279f81f12c to your computer and use it in GitHub Desktop.
Save myazakky/9ce3dab5520c8f93874034279f81f12c to your computer and use it in GitHub Desktop.
wasabi.ino
#include <M5Stack.h>
#include <WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Ambient.h"
#define ONE_WIRE_BUS 22
#define FAN 5
#define OUT1 21
#define OUT2 19
WiFiClient client;
Ambient ambient;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const char* ssid = "";
const char* password = "";
unsigned int channelId = 0;
const char* writeKey = "";
void connect_wifi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
M5.Lcd.print(".");
}
M5.Lcd.print("\nIP: ");
M5.Lcd.println(WiFi.localIP());
}
void setup(){
M5.begin();
M5.Lcd.println("Wasabi!");
pinMode(FAN, OUTPUT);
pinMode(OUT1, OUTPUT);
pinMode(OUT2, OUTPUT);
connect_wifi();
ambient.begin(channelId, writeKey, &client);
sensors.begin();
}
void loop() {
float temp = water_temprature();
if (temp != -127) {
send_data_ambient(temp);
M5.Lcd.setCursor(0, 20);
M5.Lcd.print("temp: ");
M5.Lcd.println(temp);
}
M5.Lcd.setCursor(0, 30);
if (M5.BtnA.wasPressed()) {
M5.Lcd.println("Cool ");
be_cool();
}
if (M5.BtnB.wasPressed()) {
M5.Lcd.println("Hot ");
be_hot();
}
if (M5.BtnC.wasPressed()) {
M5.Lcd.println("Neutral");
be_neutral();
}
M5.update();
}
float water_temprature() {
sensors.requestTemperatures();
return sensors.getTempCByIndex(0);
}
void send_data_ambient(int temp) {
ambient.set(1, temp);
ambient.send();
}
void be_neutral() {
digitalWrite(FAN, LOW);
digitalWrite(OUT1, LOW);
digitalWrite(OUT2, LOW);
}
void be_hot() {
digitalWrite(FAN, HIGH);
digitalWrite(OUT1, HIGH);
digitalWrite(OUT2, LOW);
}
void be_cool() {
digitalWrite(FAN, HIGH);
digitalWrite(OUT1, HIGH);
digitalWrite(OUT2, HIGH);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment