let's make something move!
#include <DHT.h>
#include <DHT_U.h>
#include <Servo.h>
#define DHTTYPE DHT11
#define DHT0PIN 5
#define DHT1PIN 6
#define DHT2PIN 7
#define SERVO0PIN 10
#define SERVO1PIN 9
#define SERVO2PIN 8
#define PHOTO0PIN A0
#define PHOTO1PIN A1
#define PHOTO2PIN A2
#define BUTTON0PIN 2
#define BUTTON1PIN 3
#define BUTTON2PIN 4
Servo mservo;
DHT dht2(DHT2PIN, DHTTYPE);
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
mservo.attach(SERVO0PIN);
dht2.begin();
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
void loop() {
if (stringComplete) {
switch (inputString.charAt(0)) {
case 'S':
setServo(inputString);
break;
default:
break;
}
inputString = "";
stringComplete = false;
}
}
void setServo(String command) {
int pos = command.substring(1).toInt();
mservo.write(pos);
delay(1000);
}
float oldH;
float oldT;
void readDHT() {
float h = dht2.readHumidity();
float t = dht2.readTemperature();
if (isnan(h) || isnan(t)) {
}
else {
if (h != oldH) {
Serial.print("H");
Serial.println(h);
oldH = h;
}
if (t != oldT) {
Serial.print("T");
Serial.println(t);
oldT = t;
}
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
Summary :
This assignment was really nice since the final project board is working almost directly, I'm eager to do something more ambitious and connected! I have just lost two evenings of debugging because of a faulty jumper wire....