Láser

 








int laserPin = 10; // Pin de conexión del diodo láser
int buttonPin = 7; // Pin de conexión del botón
int buttonState = 0;

void setup() {
  pinMode(laserPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    digitalWrite(laserPin, HIGH); // Enciende el láser
  } else {
    digitalWrite(laserPin, LOW); // Apaga el láser
  }
}

**********************************************************************
//SERVO

#include <Servo.h> // Incluye la librería Servo


Servo myservo;  // Crea un objeto servo


int angle = 0;  // Ángulo inicial del servomotor


void setup() {

  myservo.attach(9);  // Conecta el servomotor al pin 9 (cambia si usas otro pin)

}


void loop() {

  // Mueve el servomotor desde 0 hasta 180 grados

  for (angle = 0; angle <= 180; angle++) {

    myservo.write(angle);  // Mueve el servo al ángulo especificado

    delay(15);  // Espera para que el servomotor se mueva

  }


  // Mueve el servomotor desde 180 hasta 0 grados

  for (angle = 180; angle >= 0; angle--) {

    myservo.write(angle);  // Mueve el servo al ángulo especificado

    delay(15);  // Espera para que el servomotor se mueva

  }

}


Comentarios