Add Arduino firmware
This commit is contained in:
parent
15e06d9b0c
commit
928692334c
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
modified on Apr 10, 2021
|
||||
Modified by MehranMaleki from Arduino Examples
|
||||
Home
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "DFRobot_SHT20.h"
|
||||
|
||||
DFRobot_SHT20 sht20;
|
||||
|
||||
void fanOn() {
|
||||
digitalWrite(7, HIGH);
|
||||
}
|
||||
|
||||
void fanOff() {
|
||||
digitalWrite(7, LOW);
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(4, OUTPUT);
|
||||
pinMode(7, OUTPUT);
|
||||
digitalWrite(7, LOW);
|
||||
|
||||
Serial.begin(115200);
|
||||
//Serial.println("SHT20 Example!");
|
||||
//Serial.println("temperature,humidity");
|
||||
sht20.initSHT20(); // Init SHT20 Sensor
|
||||
delay(100);
|
||||
//sht20.checkSHT20(); // Check SHT20 Sensor
|
||||
}
|
||||
|
||||
void toggle() {
|
||||
digitalWrite(4, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(4, LOW);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (Serial.available()) {
|
||||
const int c = Serial.read();
|
||||
if (c == 's') {
|
||||
// TODO dump the current status
|
||||
float humd = sht20.readHumidity(); // Read Humidity
|
||||
float temp = sht20.readTemperature(); // Read Temperature
|
||||
float volts = (5.0f/1024.0f)*analogRead(A2);
|
||||
Serial.print(humd);
|
||||
Serial.print(",");
|
||||
Serial.print(temp);
|
||||
Serial.print(",");
|
||||
Serial.println(volts);
|
||||
} else if (c == 'h') {
|
||||
toggle();
|
||||
}
|
||||
}
|
||||
delay(50);
|
||||
}
|
Loading…
Reference in New Issue