Fire Army 4/1/14

– we started to create a code with the joystick and servo motors, later we will us stepper motor
– we finished building the mobile platform

Joystick+Stepper Code

#include
const int VERT = 0; // analog
const int HORIZ = 1; // analog
const int SEL = 2; // digital

// Also connect the joystick VCC to Arduino 5V, and joystick GND to Arduino GND.

// This sketch outputs serial data at 9600 baud (open Serial Monitor to view).

#include

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object

// make the SEL line an input
pinMode(SEL,INPUT);
// turn on the pull-up resistor for the SEL line (see http://arduino.cc/en/Tutorial/DigitalPins)
digitalWrite(SEL,HIGH);

// set up serial port for output
Serial.begin(9600);
}

void loop()
{
int vertical, horizontal, select;

// read all values from the joystick

vertical = analogRead(VERT); // will be 0-1023
horizontal = analogRead(HORIZ); // will be 0-1023
select = digitalRead(SEL); // will be HIGH (1) if not pressed, and LOW (0) if pressed

// print out the values

Serial.print("vertical: ");
Serial.print(vertical,DEC);
Serial.print(" horizontal: ");
Serial.print(horizontal,DEC);
Serial.print(" select: ");
if(select == HIGH)
Serial.println("not pressed");
else
Serial.println("PRESSED!");

if(vertical = 0 && horizontal = 514) {
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s