Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: LinearRailSlide - Source Code compiled for: Arduino Uno - Source Code created on: 2023-11-29 22:10:00 - Source Code generated by: Francesco Alessandro ********* Pleasedontcode.com **********/ /****** DEFINITION OF LIBRARIES *****/ #include
#include
/****** SYSTEM REQUIREMENT 1 *****/ /* A stepper motor drives a 200 mm length linear rail */ /* slide. The motor performs 100 steps/revolution. */ /* Step per mm of Lead screw is 10mm. */ /****** SYSTEM REQUIREMENT 2 *****/ /* Perform a complete continuous travel from right to */ /* left in 12 hour. Then go back from left to right */ /* again in 12 hours. The movement shall be */ /* continuous in 12 hours. Do not use delay function. */ /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t STEPPER_PIN_1_PIN_D2 = 2; const uint8_t STEPPER_PIN_2_PIN_D3 = 3; const uint8_t STEPPER_PIN_3_PIN_D4 = 4; const uint8_t STEPPER_PIN_4_PIN_D5 = 5; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ Stepper myStepper(100, STEPPER_PIN_1_PIN_D2, STEPPER_PIN_2_PIN_D3, STEPPER_PIN_3_PIN_D4, STEPPER_PIN_4_PIN_D5); void setup(void) { // put your setup code here, to run once: pinMode(STEPPER_PIN_1_PIN_D2, OUTPUT); pinMode(STEPPER_PIN_2_PIN_D3, OUTPUT); pinMode(STEPPER_PIN_3_PIN_D4, OUTPUT); pinMode(STEPPER_PIN_4_PIN_D5, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: unsigned long startTime = millis(); // Start time of the 12-hour cycle unsigned long currentTime = 0; // Current time in the 12-hour cycle unsigned long elapsedTime = 0; // Elapsed time since the start of the cycle int direction = 1; // Direction of movement (1 for right to left, -1 for left to right) while (elapsedTime <= 12 * 60 * 60 * 1000) // Run for 12 hours { currentTime = millis() - startTime; // Calculate current time elapsedTime = currentTime % (12 * 60 * 60 * 1000); // Calculate elapsed time myStepper.step(direction); // Move the stepper motor one step delayMicroseconds(1000); // Delay for 1 millisecond } // Reverse direction after 12 hours direction = -direction; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)