Never go without an UX
#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;
}
}
}
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
import controlP5.*;
ControlP5 cp5;
int myServoValue ;
int sliderValue = 0;
int sliderTicks1 = 100;
Slider a;
Serial myPort;
void setup() {
size(700,400);
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.write("S"+0+"\n");
noStroke();
cp5 = new ControlP5(this);
// add a horizontal sliders, the value of this slider will be linked
// to variable 'sliderValue'
cp5.addSlider("Angle")
.setPosition(100,50)
.setRange(0,180)
;
}
void draw() {
background(sliderTicks1);
fill(sliderValue);
rect(0,0,width,100);
}
void Angle (int angleValue) {
myServoValue = angleValue;
myPort.write("S"+myServoValue+"\n");
}
Summary :
This assignment was really frustrating for one and only one reason...I have just lost two nights of debugging because of a faulty jumper wire, I'm eager to do something more ambitious with the final project but the basic idea is there