Ave Maria, cheia de graça, o Senhor é convosco, bendita sois vós entre as mulheres e bendito é o fruto do vosso ventre, Jesus.
Santa Maria, Mãe de Deus, rogai por nós pecadores, agora e na hora da nossa morte. Amém.
sábado, 2 de abril de 2022
Micro Servo Motor SG90 controlado por Monitor Serial e controlado por Po...
Serial.begin(9600); servo1.attach(8); servo1.write(180); delay(500); servo1.write(0); delay(100); Serial.println("Digite: \n1 para 0 graus \n2 para 30 graus \n3 para 45 graus \n4 para 60 graus \n5 para 90 graus \n6 para 135 graus \n7 para 180 graus");
}
void loop() {
if (Serial.available() > 0) { n = Serial.read(); delay(15); Serial.print(n);
/* 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(100); // waits 15 ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15 ms for the servo to reach the position }*/ }
2 comentários:
#include
Servo servo1;
char n = ' ';
void setup() {
Serial.begin(9600);
servo1.attach(8);
servo1.write(180);
delay(500);
servo1.write(0);
delay(100);
Serial.println("Digite: \n1 para 0 graus \n2 para 30 graus \n3 para 45 graus \n4 para 60 graus \n5 para 90 graus \n6 para 135 graus \n7 para 180 graus");
}
void loop() {
if (Serial.available() > 0)
{
n = Serial.read();
delay(15);
Serial.print(n);
if(n == '1')
{
servo1.write(-180);
delay(500);
}
if (n == '2')
{
servo1.write(30);
delay(500);
}
if(n == '3')
{
servo1.write(45);
delay(500);
}
if(n == '4')
{
servo1.write(60);
delay(500);
}
if(n == '5')
{
servo1.write(90);
delay(500);
}
if(n == '6')
{
servo1.write(135);
delay(500);
}
if(n == '7')
{
servo1.write(180);
delay(500);
}
}
Serial.flush();
}
/* Sweep
by BARRAGAN
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep
*/
#include
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos=0; // variable to store the servo position
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(0);
}
void loop() {
if(Serial.available() > 0){
while (Serial.available() > 0){
pos = Serial.parseInt();
Serial.println(pos);
if(pos>177){
pos=177;
}
delay(50);
myservo.write(pos);
pos = Serial.parseInt();
}
}
/*
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(100); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15 ms for the servo to reach the position
}*/
}
Postar um comentário