Created
October 8, 2012 22:32
-
-
Save lizkhoo/3855399 to your computer and use it in GitHub Desktop.
butter my bread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//butter machine for Arduino | |
#include <Servo.h> //add servo motor library | |
const int photoPin = A0; //input pin for photosensor | |
const int ledPin = 9; | |
int photoMin = 1023; | |
int photoMax = 0; | |
int photoValue = 1023; | |
Servo servoMotor; | |
const int servoPin = 2; | |
int servoAngle[]={ | |
30,149}; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(9, OUTPUT); | |
digitalWrite(9, HIGH); | |
while (millis() < 2000){ | |
photoValue = analogRead(photoPin); | |
if (photoValue > photoMax){ | |
photoMax = photoValue; | |
Serial.print("photoMax = "); | |
Serial.println(photoMax); | |
} | |
if (photoValue < photoMin){ | |
photoMin = photoValue; | |
Serial.print("photoMin = "); | |
Serial.println(photoMin); | |
} | |
} | |
digitalWrite(9,LOW); | |
servoMotor.attach(servoPin); | |
} | |
void loop(){ | |
photoValue = analogRead(photoPin); | |
photoValue = map(photoValue, photoMin, photoMax, 0, 179); | |
photoValue = constrain(photoValue,0,179); | |
Serial.print("photoValue = "); | |
Serial.println(photoValue); | |
for(int i = 0; i < 2; i++){ | |
if (photoValue < 10 && millis() > 2000){ | |
digitalWrite(9,HIGH); | |
servoMotor.write(servoAngle[i]); | |
Serial.print("servoAngle = "); | |
Serial.println(servoAngle[i]); | |
delay(1000); | |
} else { | |
digitalWrite(9,LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment