-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding notes to a new proyect with two servo motors and a joystick to…
… handle them
- Loading branch information
Showing
3 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions
77
Notes/6. Hardware/Arduino/Arduino Proyects/5. Micro robot laser.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Componentes necesarios | ||
|
||
- Arduino (Cualquier modelo compatible). | ||
- x2 Servomotor. | ||
- Análogico de joystick. | ||
- Cables jumpers, macho macho y macho hembra (en este caso puede variar la cantidad de cables a utilizar dependiendo del cuidado al llevar a cabo en el circuito). | ||
|
||
---- | ||
# Código desarrollado | ||
|
||
El proyecto consiste en realizar la configuración de un joystick para posteriormente hacer uso de dos servomotres enlazados entre si para poder controlar un servomotor cunado el joystick se mueva en el eje X y otro servomotor para cuando el joystick se mueva en el eje Y, de esta manera lograriamos un completo rango de movimiento con un "brazo robot" (Dos servomotores enlazados) que en la puntan podrían tener un lazer a gusto. | ||
|
||
```C | ||
#include <Servo.h> | ||
|
||
# Used pines | ||
int joystickXPin = A0; | ||
int joystickYPin = A1; | ||
int joystickSwPin = 2; | ||
int servoXPin = 12; | ||
int servoYPin = 13; | ||
|
||
# Vars to analog values from joystick (X and Y) and vars to save the angles for servos | ||
float joystickXVal, joystickYVal, servoXAngle, servoYAngle; | ||
int joystickSwVal; | ||
|
||
# Declare the two servos | ||
Servo ServoX; | ||
Servo ServoY; | ||
|
||
# Print the joystick movements | ||
void printJoystickValues(){ | ||
Serial.print("X: "); | ||
Serial.print(joystickXVal); | ||
Serial.print(" Y: "); | ||
Serial.print(joystickYVal); | ||
Serial.print(" SW: "); | ||
Serial.println(joystickSwVal); | ||
delay(200); | ||
} | ||
|
||
void setup() { | ||
// put your setup code here, to run once: | ||
Serial.begin(9600); | ||
pinMode(joystickXPin, INPUT); | ||
pinMode(joystickYPin, INPUT); | ||
pinMode(joystickSwPin, INPUT); | ||
# Set de joystick swtich to 1 to get 0 wen is pressed. | ||
digitalWrite(joystickSwPin, HIGH); | ||
# Attach the servo pines to servos | ||
ServoX.attach(servoXPin); | ||
ServoY.attach(servoYPin); | ||
} | ||
|
||
void loop() { | ||
// put your main code here, to run repeatedly: | ||
joystickXVal = analogRead(joystickXPin); | ||
joystickYVal = analogRead(joystickYPin); | ||
joystickSwVal = analogRead(joystickSwPin); | ||
|
||
printJoystickValues(); | ||
|
||
# Make a logic to get de 180° possible from 1023 analog values from joystick (X and Y) | ||
servoXAngle = (180./1023.) * joystickXVal; | ||
servoYAngle = (180./1023.) * joystickYVal; | ||
|
||
# Move the servos to calculated angle | ||
ServoX.write(servoXAngle); | ||
ServoY.write(servoYAngle); | ||
} | ||
|
||
``` | ||
---- | ||
# Configuración electrónica desarrollada | ||
![[servos_with_joystick.jpg|1200]] |