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
// This code has yet to be tested | |
// There most likely will need to be some more adjustments made | |
// when our group meets again on Saturday (11/30/12) so that the | |
// Machine works as intended. As of now it compiles and should run. | |
#include <Servo.h> | |
int potPin = A0; // PotPin is set to A0 | |
int potVal = 0; | |
int RightButton = 0; | |
int LeftButton = 0;// Declares LeftButton as an int and assigns it the value 0 | |
int inPinR = 7; | |
int inPinL = 6; | |
int FanVal; | |
int FanPin = 3; // Asigns pin 3 to the Fan | |
Servo Cart; // The servo on the rail that is going back and forth is named Servo Cart | |
Servo Cup; // The servo at the bottom of the deoderant stick is Cup | |
void setup() | |
{ | |
Cart.attach(5); // Attaches the servo Cart to pin 5 | |
Cup.attach(9); // Attaches the Servo Cup to pin 9 | |
pinMode(inPinR, INPUT); | |
pinMode(inPinL, INPUT); | |
pinMode(FanPin, OUTPUT); | |
Cart.write(90); // The Cart is initially at rest | |
Cup.write(90); // The Cup is initally at rest | |
Serial.begin(9600); // I don't think I need this line of code but to be safe I added it | |
} | |
void loop() | |
{ | |
RightButton = digitalRead(inPinR); | |
LeftButton = digitalRead(inPinL); | |
potVal = analogRead(potPin); | |
if ((RightButton == LOW) && (LeftButton == HIGH)) | |
{ Cart.write(0); // Moves the Cart to the left | |
delay(2100); // runs for 2100 mS | |
int x = 90; | |
Cart.write(x); | |
delay(3000); | |
if (x = 90) | |
{ FanVal = 255; | |
analogWrite(FanPin, FanVal); //Runs the fan at max speed. | |
} | |
if ((RightButton == HIGH) && (LeftButton == LOW)) | |
{ FanVal = 100; | |
analogWrite(FanPin, FanVal); // The fan remains running but | |
// not as fast. | |
Cart.write(180); | |
delay(1900); | |
int x = 90; | |
Cart.write(x); | |
delay(7000); // Could not be enough time for the | |
//bubble solution to rise to the wand | |
// the following code will probably give me a lot of | |
// headaches and I have a feeling I'm gonna be spending a | |
// lot of time fixing it. | |
if (x = 90){ | |
int z = potVal; | |
if ( z <= 260)// If the potometer reads less than 260 | |
{z = 180;} // The servo will spin the cup up | |
if (( z > 260) && (z <770)) // If the pot is beterrn 260-770 | |
{ z = 90;} // The servo won't move | |
if (z >=770) | |
{ z = 180;} | |
Cup.write(z); | |
} | |
if ((RightButton == LOW) && (LeftButton == LOW)){ | |
FanVal = 255; // fan will run at max speed | |
analogWrite(FanPin, FanVal); | |
Cart.write(90); // Servo will not run when both buttons are pressed | |
} | |
if ((RightButton == HIGH) && (LeftButton == HIGH)){ | |
FanVal = 255; // fan will run at max speed | |
analogWrite(FanPin, FanVal); | |
Cart.write(90); // Servo will not run when no buttons are pressed | |
} | |
} | |
} | |
} | |
No comments:
Post a Comment