Telescope Controller

by kabirnaik in Circuits > Arduino

1977 Views, 4 Favorites, 0 Comments

Telescope Controller

p1106aw.jpg

try this awsome scope controller

here is my code to move the telescope

#include

Servo servoLeft; Servo servoRight;

void setup() { servoLeft.attach(10); servoRight.attach(9); }

void loop() { forward(); delay(2000); reverse(); delay(2000); turnRight(); delay(2000); turnLeft(); delay(2000); stopRobot(); delay(2000); }

// Motion routines for forward, reverse, turns, and stop void forward() { servoLeft.write(0); servoRight.write(180); }

void reverse() { servoLeft.write(180); servoRight.write(0); }

void turnRight() { servoLeft.write(180); servoRight.write(180); } void turnLeft() { servoLeft.write(0); servoRight.write(0); }

void stopRobot() { servoLeft.write(90); servoRight.write(90); }

Step Two Controller

Arduino connected to phone

[quote]
#include #include <[color=#CC6600]SPI[/color].h>

[color=#7E7E7E]// Each object on screen needs to be declared like this[/color]

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {

setInitialData(); [color=#7E7E7E]// Call this function to define your objects[/color] }

[color=#CC6600]void[/color] setInitialData()

{

bluerange.setType(DATA_OUT); [color=#7E7E7E]// Defines object as a display box[/color] nameOfObjectA.setLocation(0,0,FULL); [color=#7E7E7E]// First row, left-most, full width[/color] nameOfObjectA.setTitle([color=#006699]"This is for the title bar"[/color]); nameOfObjectA.setData([color=#006699]"This is for the data area"[/color]); nameOfObjectA.setUnit([color=#006699]"This is meant for the text area at the bottom of your box"[/color]);

nameOfObjectB.setId(1); [color=#7E7E7E]// Each object must be assigned a unique ID number[/color] nameOfObjectB.setType(DATA_OUT); [color=#7E7E7E]// Defines object as a display box[/color] nameOfObjectB.setLocation(1,0,FULL); [color=#7E7E7E]// Second row, left-most, full width[/color] nameOfObjectB.setTitle([color=#006699]"Hello"[/color]); nameOfObjectB.setData([color=#006699]"World!"[/color]); [color=#7E7E7E]// setUnit is optional. You don't need to display it all the time[/color]

}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() { nameOfObjectA.update(); [color=#7E7E7E]// Call update() to make it appear on screen[/color] nameOfObjectB.update(); [color=#7E7E7E]// and to refresh its display[/color]

[color=#CC6600]delay[/color](500); [color=#7E7E7E]// Delay for 500ms (0.5 seconds) before repeating code above[/color] }

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() { Andee.[color=#CC6600]begin[/color](); [color=#7E7E7E]// Setup communication between Annikken Andee and Arduino[/color] Andee.[color=#CC6600]clear[/color](); [color=#7E7E7E]// Clear the screen of any previous displays[/color] currentPosition = 0; [color=#7E7E7E]// Initialise position to 0[/color] theServo.[color=#CC6600]attach[/color](servoPin); [color=#7E7E7E]// Tell Arduino which pin the servo is connected to[/color] theServo.[color=#CC6600]write[/color](currentPosition); [color=#7E7E7E]// Set servo to position 0[/color] setInitialData(); [color=#7E7E7E]// Define object types and their appearance[/color] } [color=#CC6600]void[/color] setInitialData() { btnTurnLeft.setId(0); btnTurnLeft.setType(BUTTON_IN); btnTurnLeft.setLocation(0,0,HALF); btnTurnLeft.setTitle([color=#006699]"Turn Left"[/color]); btnTurnLeft.requireAck([color=#CC6600]false[/color]); [color=#7E7E7E]// You need this line to allow for multiple button presses[/color] btnTurnRight.setId(1); btnTurnRight.setType(BUTTON_IN); btnTurnRight.setLocation(0,1,HALF); btnTurnRight.setTitle([color=#006699]"Turn Right"[/color]); btnTurnRight.requireAck([color=#CC6600]false[/color]); [color=#7E7E7E]// You need this line to allow for multiple button presses [/color] btnCustomPosition.setId(2); btnCustomPosition.setType(KEYBOARD_IN); [color=#7E7E7E]// Sets object as a text input button[/color] btnCustomPosition.setLocation(1,0,FULL); btnCustomPosition.setTitle([color=#006699]"Quickly Go to Custom Position (0 - 180)"[/color]); btnCustomPosition.setKeyboardType(ANDEE_NUMERIC_A);

displaybox.setId(3); displaybox.setType(DATA_OUT); [color=#7E7E7E]// Sets object as a text input button[/color] displaybox.setLocation(2,0,FULL); displaybox.setTitle([color=#006699]"Current Position"[/color]); displaybox.setData(0); } [color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() { [color=#CC6600]if[/color]( btnCustomPosition.[color=#CC6600]isPressed[/color]() ) { memset(userPos, 0x00, 4); [color=#7E7E7E]// Empty the contents of the string before receiving user input[/color] btnCustomPosition.ack(); [color=#7E7E7E]// Acknowledge button press or else phone will be left waiting[/color] btnCustomPosition.getKeyboardMessage(userPos); [color=#7E7E7E]// Display keyboard and store input into userInput[/color]

newPosition = atoi(userPos); [color=#7E7E7E]// Convert string value to integer value[/color] [color=#7E7E7E]// Tell Arduino x Andee what to do if user keys in ridiculous values[/color] [color=#CC6600]if[/color](newPosition < 0) newPosition = 0; [color=#CC6600]if[/color](newPosition > 180) newPosition = 180; currentPosition = newPosition; [color=#7E7E7E]// This is how you do a quick turn[/color] theServo.[color=#CC6600]write[/color](currentPosition); [color=#7E7E7E]// Turn servo to new position[/color] displaybox.setData(currentPosition); [color=#7E7E7E]// Update new position[/color] } [color=#CC6600]if[/color]( btnTurnLeft.getButtonPressCount() > 0 ) [color=#7E7E7E]// As long as left button is pressed[/color] { btnTurnLeft.ack(); [color=#7E7E7E]// Acknowledge button press or else phone will be left waiting[/color] newPosition = currentPosition - turnResolution; [color=#7E7E7E]// Set new position[/color] [color=#CC6600]if[/color](newPosition < 0) newPosition = 0; [color=#7E7E7E]// Set to 0 if new position goes below 0[/color] [color=#7E7E7E]// This is how you do a slow turn:[/color] [color=#CC6600]for[/color](currentPosition; currentPosition > newPosition; currentPosition--) { theServo.[color=#CC6600]write[/color](currentPosition); displaybox.setData(currentPosition); [color=#7E7E7E]// Update servo position on screen as it turns[/color] displaybox.update(); [color=#CC6600]delay[/color](15); [color=#7E7E7E]// You can change the delay value. Larger value means slower turns[/color] [color=#7E7E7E]// Do not set your delay to 0 when you're doing this. You run the possibility of [/color] [color=#7E7E7E]// damaging the servo. Or you might just make it become more cranky.[/color] } } [color=#CC6600]if[/color]( btnTurnRight.getButtonPressCount() > 0 ) [color=#7E7E7E]// As long as right button is pressed[/color] { btnTurnRight.ack(); [color=#7E7E7E]// Acknowledge button press or else phone will be left waiting[/color] newPosition = currentPosition + turnResolution; [color=#7E7E7E]// Set new position[/color] [color=#CC6600]if[/color](newPosition > 180) newPosition = 180; [color=#7E7E7E]// Set to 180 if new position goes above 180[/color] [color=#CC6600]for[/color](currentPosition; currentPosition < newPosition; currentPosition++) { theServo.[color=#CC6600]write[/color](currentPosition); displaybox.setData(currentPosition); [color=#7E7E7E]// Update servo position on screen as it turns[/color] displaybox.update(); [color=#CC6600]delay[/color](15); [color=#7E7E7E]// You can change the delay value. Larger value means slower turns[/color] } } btnTurnLeft.update(); [color=#7E7E7E]// Always remember to update so that new content will be displayed[/color] btnTurnRight.update(); btnCustomPosition.update(); displaybox.update(); [color=#CC6600]delay[/color](500); }

[/quote]