Advertisement
pleasedontcode

AnalemmaGPSArduino rev_02

Nov 17th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: AnalemmaGPSArduino
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-18 00:41:53
  15.     - Source Code generated by: gianluca
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Servo.h>
  21.  
  22. Servo myservo;
  23.  
  24. // GPS variables
  25. unsigned long previousMillis = 0;
  26. const long interval = 10000;  // move the servo every 10 seconds
  27. const int servoMinAngle = 0; // minimum servo angle
  28. const int servoMaxAngle = 180; // maximum servo angle
  29. int servoAngle = servoMinAngle;
  30.  
  31. void setup() {
  32.   myservo.attach(9); // Replace 9 with the actual pin number
  33. }
  34.  
  35. void loop() {
  36.   // put your main code here, to run repeatedly:
  37.  
  38.   unsigned long currentMillis = millis();
  39.  
  40.   if (currentMillis - previousMillis >= interval) {
  41.     // move the servo every 10 seconds
  42.     previousMillis = currentMillis;
  43.  
  44.     // update the servo angle
  45.     if (servoAngle == servoMinAngle) {
  46.       servoAngle = servoMaxAngle; // move the servo to maximum angle
  47.     } else {
  48.       servoAngle = servoMinAngle; // move the servo to minimum angle
  49.     }
  50.  
  51.     // set the servo angle
  52.     myservo.write(servoAngle);
  53.   }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement