As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.
Showing posts with label servo. Show all posts
Showing posts with label servo. Show all posts

Friday, June 13, 2014

Code and Diagram

Controlling a servo with a tact switch, and LED blinking tied to moisture sensor.






// Latest code June 4th
‪#‎include‬ <Servo.h>
Servo servoMain; // Define our Servo
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0;
int pos = 0; // variable to store the servo position
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
const int led = 13; // turn on
const int led2 = 3; // blinking
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 1000;
void setup() {
// declare the ledPin as an OUTPUT:
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
servoMain.attach(10); // servo on digital pin 10
pinMode(buttonPin, INPUT);
servoMain.write(90);
}
void loop() {
sensorValue = analogRead(sensorPin);
delay(1000);
Serial.print("sensor = " );
Serial.println(sensorValue);
if (sensorValue <= 200) { //350-390 range => blinking
digitalWrite(led, LOW);
// Only allowed button to be pressed if no water
// read the state of the pushbutton value:
//buttonState = ;
if (digitalRead(buttonPin) == 1) { // Ground
Serial.println(buttonState);
Serial.println(buttonPin);
servoMain.write(0);
delay(5000);
servoMain.write(90);
delay(500);
} else {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(led2, ledState);
}
}
} else if (sensorValue >= 350) {
digitalWrite(led2, LOW); // turn off the other LED first
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
} else {
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW
}
}