Team Fire Army: Week 3 Prototyping

Hey, Teach peoples!

 

Today, we split up into (2) groups, some of us worked on building the motor-platform and the rest of us worked on programming the joystick portion of our project. We  used an Arduino coding program to code the basic cardinal directions for the joystick. As far as the building goes, today we focused on constructing the wheels and body of our motor platform to help build a solid base.

The Code:

 

#include <Servo.h>
const int VERT = A1; // analog
const int HORIZ = A0; // 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

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!”);

//this if statement is LEFT
if(vertical == 513 && horizontal == 0) {
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
}
}
//this statement is for RIGHT
if(vertical == 513 && horizontal == 1023) {
for(pos = 180; pos > 0; pos -= 1){
myservo.write(pos);
delay(5);
}

}

//this statement is for DOWN
if(vertical == 1023 && horizontal == 508) {
for(pos = 90; pos > 0; pos-=1){
myservo.write(pos);
delay(7);
}

}

//this statement is for UP
if(vertical == 0 && horizontal == 508) {
for(pos = 20; pos > 0; pos -= 1){
myservo.write(pos);
delay(0);
}
}
}

 

20140408_173031 20140408_173023

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