Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include the Arduino Stepper Library
- //sysiphean robot. .. I think Im making it too complex though. this is a scratch page
- #include <Stepper.h>
- // Number of steps per output rotation
- const int stepsPerRevolution = 100;
- // Create Instance of Stepper library
- Stepper myStepper(stepsPerRevolution, 2,3,4,5);
- /*
- 2,3,4,5 --yes
- */
- int fw = 6;
- int rv = 7;
- int pot= A9;
- int T = 0; //run time corrosponds to theta but who cares
- void Forward(int T);
- void Reverse(int T);
- void Stap();
- void setup(){
- // set the speed at 60 rpm:
- myStepper.setSpeed(100);
- pinMode(6, OUTPUT);
- pinMode(7, OUTPUT);
- // initialize the serial port:
- Serial.begin(9600);
- while (Serial.available() == 1){ // dont start moving untill the usb is unplugged.
- delay(5000);
- }
- Forward(10000);
- }
- void loop(){
- int sensor = analogRead(pot);
- Serial.println(sensor);
- //delay(1);
- myStepper.setSpeed(sensor);
- if(sensor > 701){
- myStepper.step(-stepsPerRevolution);
- }
- if(sensor < 700 && sensor > 500){
- myStepper.halt();
- }if(sensor < 500){
- myStepper.step(stepsPerRevolution);
- }
- }
- void Forward(int T){ //if the other direction is high, turn it off.
- if(digitalRead(rv)){
- Stap();
- }
- digitalWrite(fw, HIGH);
- delay(T);
- digitalWrite(fw, LOW);
- }
- void Reverse(){
- if(digitalRead(fw)){
- Stap();
- }
- digitalWrite(rv, HIGH);
- delay(T);
- digitalWrite(fw, LOW);
- }
- void Stap(){
- digitalWrite(fw, LOW);
- digitalWrite(rv, LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement