Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
44 views5 pages

Degree 0 String Words Servo Servo1 : #Include //include The Servo Library Int

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views5 pages

Degree 0 String Words Servo Servo1 : #Include //include The Servo Library Int

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <Servo.

h> //Include the Servo Library


int degree=0;
String words;
Servo servo1; // "Servos" objects are created
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Servos - Arduino");
//servo1.attach(5); //Default
servo1.attach(5,600,2400);
servo1.write(0);
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available()) { // Read the value sent by the Serial Port
delay(5);
char c = Serial.read(); // Read the characters
words += c; // Convert Characters to character string
}
if (words.length()>0){
degree = words.toInt(); // Convert character string to integers
Serial.print(degree); //Send value in Degrees
Serial.println(" Grados");
delay(5);
servo1.write(degree); // Ajuste de 512 vueltas a los 360 grados
while(servo1.read()<degree-3)
{Serial.println("Desplazando...");}
}
words = ""; // Initialize the string of characters received
}
Cod

#include <Servo.h> //Include the Servo Library

int dir=0,menu=1,opc=0;

char c='<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-


enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-
title="" data-enlighter-group="">#include <Servo.h> //Include the Servo Library

int dir=0,menu=1,opc=0;

char c='\0';

String words;

Servo servo1; // "Servos" objects are created

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

Serial.println("Servo 360 - Arduino");

//servo1.attach(5); //Default

servo1.attach(5);

servo1.write(90);

void loop() {

// put your main code here, to run repeatedly:

if(menu==1){

Serial.println(" ");

Serial.println("------------ DIGUITE UNA OPCIÓN ENTRE 1 Y 3 -------------");

Serial.println("1) Detener Motor");

Serial.println("2) Sentido Horario");

Serial.println("3) Sentido Anti-Horario");

menu=0;

while (Serial.available()) { // Read the value sent by the Serial Port


delay(5);

c = Serial.read(); // Read the characters

words += c; // Convert Characters to character string

opc=words.toInt();

if (opc!=0){

if(opc>=1 && opc<=3){

switch(opc){

case 1:

servo1.write(90);

Serial.println(">>>>> Motor DETENIDO! <<<<<<");

break;

case 2:

servo1.write(0);

Serial.println(">>>>> GIRANDO SENTIDO CW <<<<<<");

break;

case 3:

servo1.write(180);

Serial.println(">>>>> GIRANDO SENTIDO CCW <<<<<<");

break;

}else{

Serial.println(" OPCIÓN INVALIDA!!!! INTENTE NUEVAMENTE");

menu=1;

opc=0;

words = ""; // Initialize the string of characters received

}</pre>';
String words;

Servo servo1; // "Servos" objects are created

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

Serial.println("Servo 360 - Arduino");

//servo1.attach(5); //Default

servo1.attach(5);

servo1.write(90);

void loop() {

// put your main code here, to run repeatedly:

if(menu==1){

Serial.println(" ");

Serial.println("------------ DIGUITE UNA OPCIÓN ENTRE 1 Y 3 -------------");

Serial.println("1) Detener Motor");

Serial.println("2) Sentido Horario");

Serial.println("3) Sentido Anti-Horario");

menu=0;

while (Serial.available()) { // Read the value sent by the Serial Port

delay(5);

c = Serial.read(); // Read the characters

words += c; // Convert Characters to character string

opc=words.toInt();

if (opc!=0){
if(opc>=1 && opc<=3){

switch(opc){

case 1:

servo1.write(90);

Serial.println(">>>>> Motor DETENIDO! <<<<<<");

break;

case 2:

servo1.write(0);

Serial.println(">>>>> GIRANDO SENTIDO CW <<<<<<");

break;

case 3:

servo1.write(180);

Serial.println(">>>>> GIRANDO SENTIDO CCW <<<<<<");

break;

}else{

Serial.println(" OPCIÓN INVALIDA!!!! INTENTE NUEVAMENTE");

menu=1;

opc=0;

words = ""; // Initialize the string of characters received

You might also like