Tuesday, December 2, 2014

Below is a test code used for this project. Int led is used to tell the program to use pin 9 on the board. I chose led for the pin because it's what I've used in every other code. All the other int are time variables. The smaller ones, on the order of seconds is intended for testing and demonstration, while the longer time periods are used to set hours. The servo library is used for the servo variables. 

I looked at one of the sample codes in order to figure out how to set up the servo. In the void loop, it starts off with having the pin give a low signal for the "TIMEVARIABLE". In this place, you put in the int to determine how long until the servo turns. Then, the pinMode turns to high, providing power to the servo. The details after make the servo turn 180 degrees forward, then back to the original position. Since it is a loop, it can be set to fifteen or thirty seconds in order to show multiple shots for testing. However, each time, you still need to pull back the rubber band and load a projectile. 

#include <Servo.h>
Servo servo1;  // servo control object
int led = 9;
int fiveseconds = 5000;
int fifteenseconds = 15000;
int thirtyseconds = 30000;
int oneminute = 60000;
int tenminutes = 600000;
int thirtyminutes = 1800000;
int onehour = 3600000;
int onehourthirtyminutes = 5400000;
int twohour = 7200000;
int twohourthirtyminutes = 9000000;
int threehours = 1800000000;
int threehourthirtyminutes = 36000000;
int fourhours = 54000000;
int fourhourthirtyminutes = 72000000;
int fivehours = 90000000;

void setup () {
  servo1.attach(9);
}

void loop() {

  pinMode(led, LOW);
  delay(TIMEVARIABLE);
  pinMode(led, HIGH);
  
  servo1.write(180);    

  delay(1000);         

  servo1.write(90);   

  delay(1000);         



}

No comments:

Post a Comment