Sketchbook di Andrea
=====================
-Esempi per i corsi su Arduino.
+Codice esempi per i corsi su Arduino.
Le ultime versioni sono disponibili su: git.andreamanni.com
- http://git.andreamanni.com/
- Interfaccia web: http://git.andreamanni.com/web
--- /dev/null
+ /*
+ Adafruit Arduino - Lesson 15. Bi-directional Motor
+
+ Pilotare un motore DC brushed con un H-bridge mediante
+ un integrato L293D
+
+
+ Schemi e istruzioni:
+ - https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing/overview
+
+ */
+
+ int enablePin = 11;
+ int in1Pin = 10;
+ int in2Pin = 9;
+ int switchPin = 7;
+ int potPin = 0;
+
+ void setup()
+ {
+ pinMode(in1Pin, OUTPUT);
+ pinMode(in2Pin, OUTPUT);
+ pinMode(enablePin, OUTPUT);
+ pinMode(switchPin, INPUT_PULLUP);
+ }
+
+ void loop()
+ {
+ int speed = analogRead(potPin) / 4;
+ boolean reverse = digitalRead(switchPin);
+ setMotor(speed, reverse);
+ }
+
+ void setMotor(int speed, boolean reverse)
+ {
+ analogWrite(enablePin, speed);
+ digitalWrite(in1Pin, ! reverse);
+ digitalWrite(in2Pin, reverse);
+ }
/*
Simple Motor : Potenziometro con minimo
-
+
Motore DC con variazione della velocita' impostata
- tramite un potenziometro 10k ohms
+ tramite un potenziometro 10k ohms,
+ settato un valore minimo sotto il quale il motore
+ non viene attivato.
Schema: http://lab.piffa.net/schemi/motor_pot_bb.png
/* Domande
-1. Cosa succede quando il motore ha riceve un carico molto basso?
+1. Cosa succede quando il motore riceve poca corrente?
2. Impostare un valore minimo per la partenza del motore,
sotto al quale il motore non parte.
*/
if (motValue > 60) { // Valore minimo per far partire il motore
analogWrite(motorPin,motValue); //
}
- else analogWrite(motorPin,0); // Se non super il valore minimo
+ else analogWrite(motorPin,0); // Se non supera il valore minimo
// deve restare fermo
delay(3); // Pause, stabilizza la lettura del Pot
--- /dev/null
+
+/*
+ CDROM stepper
+
+ Pilotare lo step di un lettore CDROM mediante
+ il motor shield.
+
+ - http://wiki.piffa.net/index.php/CNC_ROM
+
+Pin on top, plastica sotto
+
+ 1 2 2 5 1 3 1 e' il piu' vicino al capacitor
+ 3 4
+
+*/
+
+#include <AFMotor.h>
+
+// Connect a stepper motor with 48 steps per revolution (7.5 degree)
+// to motor port #2 (M3 and M4)
+AF_Stepper motor(200, 2); //Motor with 200 steps per rev (1.8 degree)
+
+void setup() {
+ Serial.begin(9600); // set up Serial library at 9600 bps
+ Serial.println("Stepper test!");
+
+ motor.setSpeed(20); // max 400
+}
+
+void loop() {
+
+ //motor.step(340, FORWARD, MICROSTEP);
+ //motor.step(340, BACKWARD, MICROSTEP);
+
+ for (int lenght = 340; lenght > 40; lenght -= 40)
+ {
+ motor.step(lenght, FORWARD, MICROSTEP);
+ motor.step(lenght - 20, BACKWARD, MICROSTEP);
+ }
+ motor.step(150, BACKWARD, MICROSTEP);
+}
--- /dev/null
+
+
+/*
+ BYJ48 Stepper motor code
+ Connect :
+ IN1 >> D8
+ IN2 >> D9
+ IN3 >> D10
+ IN4 >> D11
+ VCC ... 5V Prefer to use external 5V Source
+ Gnd
+ written By :Mohannad Rawashdeh
+ http://www.instructables.com/member/Mohannad+Rawashdeh/
+ 28/9/2013
+ */
+
+#define IN1 8
+#define IN2 9
+#define IN3 10
+#define IN4 11
+int Steps = 0;
+boolean Direction = true;// gre
+unsigned long last_time;
+unsigned long currentMillis ;
+int steps_left=4095;
+long time;
+void setup()
+{
+ Serial.begin(115200);
+ pinMode(IN1, OUTPUT);
+ pinMode(IN2, OUTPUT);
+ pinMode(IN3, OUTPUT);
+ pinMode(IN4, OUTPUT);
+ // delay(1000);
+
+}
+void loop()
+{
+ while(steps_left>0){
+ currentMillis = micros();
+ if(currentMillis-last_time>=1000){
+ stepper(1);
+ time=time+micros()-last_time;
+ last_time=micros();
+ steps_left--;
+ }
+ }
+ Serial.println(time);
+ Serial.println("Wait...!");
+ delay(2000);
+ Direction=!Direction;
+ steps_left=4095;
+}
+
+void stepper(int xw){
+ // Impostato ad Half Steps
+ for (int x=0;x<xw;x++){
+ switch(Steps){
+ case 0:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 1:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 2:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 3:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 4:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 5:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 6:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 7:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ default:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ }
+ SetDirection();
+ }
+}
+void SetDirection(){
+ if(Direction==1){
+ Steps++;
+ }
+ if(Direction==0){
+ Steps--;
+ }
+ if(Steps>7){
+ Steps=0;
+ }
+ if(Steps<0){
+ Steps=7;
+ }
+}
+
+
--- /dev/null
+
+
+/*
+ BYJ48 Stepper motor code
+ Connect :
+ IN1 >> D8
+ IN2 >> D9
+ IN3 >> D10
+ IN4 >> D11
+ VCC ... 5V Prefer to use external 5V Source
+ Gnd
+ written By :Mohannad Rawashdeh
+ http://www.instructables.com/member/Mohannad+Rawashdeh/
+ 28/9/2013
+ */
+
+#define IN1 8
+#define IN2 9
+#define IN3 10
+#define IN4 11
+int Steps = 0;
+boolean Direction = true;// gre
+unsigned long last_time;
+unsigned long currentMillis ;
+int steps_left=4095;
+long time;
+void setup()
+{
+ Serial.begin(115200);
+ pinMode(IN1, OUTPUT);
+ pinMode(IN2, OUTPUT);
+ pinMode(IN3, OUTPUT);
+ pinMode(IN4, OUTPUT);
+ // delay(1000);
+
+}
+void loop()
+{
+ while(steps_left>0){
+ currentMillis = micros();
+ if(currentMillis-last_time>=1000){
+ stepper(1);
+ time=time+micros()-last_time;
+ last_time=micros();
+ steps_left--;
+ }
+ }
+ Serial.println(time);
+ Serial.println("Wait...!");
+ delay(2000);
+ Direction=!Direction;
+ steps_left=4095;
+}
+
+void stepper(int xw){
+ // Impostato ad Half Steps
+ for (int x=0;x<xw;x++){
+ switch(Steps){
+ case 0:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 1:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 2:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 3:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 4:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 5:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 6:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 7:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ default:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ }
+ SetDirection();
+ }
+}
+void SetDirection(){
+ if(Direction==1){
+ Steps++;
+ }
+ if(Direction==0){
+ Steps--;
+ }
+ if(Steps>7){
+ Steps=0;
+ }
+ if(Steps<0){
+ Steps=7;
+ }
+}
+
+
--- /dev/null
+
+
+/*
+ BYJ48 Stepper motor code
+ Connect :
+ IN1 >> D8
+ IN2 >> D9
+ IN3 >> D10
+ IN4 >> D11
+ VCC ... 5V Prefer to use external 5V Source
+ Gnd
+ written By :Mohannad Rawashdeh
+ http://www.instructables.com/member/Mohannad+Rawashdeh/
+ 28/9/2013
+ */
+
+#define IN1 8
+#define IN2 9
+#define IN3 10
+#define IN4 11
+int Steps = 0;
+boolean Direction = true;// gre
+unsigned long last_time;
+unsigned long currentMillis ;
+int steps_left=4095;
+long time;
+void setup()
+{
+ Serial.begin(115200);
+ pinMode(IN1, OUTPUT);
+ pinMode(IN2, OUTPUT);
+ pinMode(IN3, OUTPUT);
+ pinMode(IN4, OUTPUT);
+ // delay(1000);
+
+}
+void loop()
+{
+ while(steps_left>0){
+ currentMillis = micros();
+ if(currentMillis-last_time>=1000){
+ stepper(1);
+ time=time+micros()-last_time;
+ last_time=micros();
+ steps_left--;
+ }
+ }
+ Serial.println(time);
+ Serial.println("Wait...!");
+ delay(2000);
+ Direction=!Direction;
+ steps_left=4095;
+}
+
+void stepper(int xw){
+ for (int x=0;x<xw;x++){
+ switch(Steps){
+ case 0:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 1:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, HIGH);
+ break;
+ case 2:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 3:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, HIGH);
+ digitalWrite(IN4, LOW);
+ break;
+ case 4:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 5:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, HIGH);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 6:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ case 7:
+ digitalWrite(IN1, HIGH);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, HIGH);
+ break;
+ default:
+ digitalWrite(IN1, LOW);
+ digitalWrite(IN2, LOW);
+ digitalWrite(IN3, LOW);
+ digitalWrite(IN4, LOW);
+ break;
+ }
+ SetDirection();
+ }
+}
+void SetDirection(){
+ if(Direction==1){
+ Steps++;
+ }
+ if(Direction==0){
+ Steps--;
+ }
+ if(Steps>7){
+ Steps=0;
+ }
+ if(Steps<0){
+ Steps=7;
+ }
+}
+
+
--- /dev/null
+/*
+ Step
+
+ Utilizzo della libreria Step
+
+*/
+#include <Stepper.h>
+ int passi = 32 ; // Passi del motore
+ int rapporto = 64 ; // Rapporto di riduzione
+// numeri di steps * rapporto di riduzione
+ // (usiamo 4 step in full step drive)
+
+//Stepper motore(2048, 8, 10, 9, 11);
+Stepper motore(passi, 8, 10, 9, 11);
+
+
+void setup() {
+}
+
+void loop()
+{
+// Rotazione completa CW
+ motore.setSpeed(1); // Impostiamo la velocita'
+ motore.step(4);
+ delay(500);
+
+ delay(1000);
+ motore.setSpeed(1); // Impostiamo la velocita'
+ motore.step(-3);
+ delay(500);
+}
+++ /dev/null
-/* YourDuino.com Example Software Sketch
- Small Stepper Motor and Driver V1.3 11/30/2013
- http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126
- Shows 4-step sequence, Then 1/2 turn and back different speeds
- terry@yourduino.com */
-
-/*-----( Import needed libraries )-----*/
-#include <Stepper.h>
-
-/*-----( Declare Constants, Pin Numbers )-----*/
-//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
-#define STEPS_PER_MOTOR_REVOLUTION 32
-
-//---( Steps per OUTPUT SHAFT of gear reduction )---
-#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048
-
-/*-----( Declare objects )-----*/
-// create an instance of the stepper class, specifying
-// the number of steps of the motor and the pins it's
-// attached to
-
-//The pin connections need to be 4 pins connected
-// to Motor Driver In1, In2, In3, In4 and then the pins entered
-// here in the sequence 1-3-2-4 for proper sequencing
-Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
-
-
-/*-----( Declare Variables )-----*/
-int Steps2Take;
-
-void setup() /*----( SETUP: RUNS ONCE )----*/
-{
-// Nothing (Stepper Library sets pins as outputs)
-}/*--(end setup )---*/
-
-void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
-{
- small_stepper.setSpeed(1); // SLOWLY Show the 4 step sequence
- Steps2Take = 4; // Rotate CW
- small_stepper.step(Steps2Take);
- delay(2000);
-
- Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CW 1/2 turn
- small_stepper.setSpeed(100);
- small_stepper.step(Steps2Take);
- delay(1000);
-
- Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CCW 1/2 turn
- small_stepper.setSpeed(700); // 700 a good max speed??
- small_stepper.step(Steps2Take);
- delay(2000);
-
-}/* --(end main loop )-- */
-
-/* ( THE END ) */
-
--- /dev/null
+/*
+ Step
+
+ Utilizzo della libreria Step
+
+*/
+#include <Stepper.h>
+ int passi = 32 ; // Passi del motore
+ int rapporto = 64 ; // Rapporto di riduzione
+// numeri di steps * rapporto di riduzione
+ // (usiamo 4 step in full step drive)
+
+//Stepper motore(2048, 8, 10, 9, 11);
+Stepper motore(passi, 8, 10, 9, 11);
+
+
+void setup() {
+
+
+}
+
+void loop()
+{
+// Rotazione completa CW
+ motore.setSpeed(300); // Impostiamo la velocita'
+ motore.step(passi * rapporto);
+ delay(1000);
+
+// Rotazione completa Anti-CW
+ motore.setSpeed(700); // Re impostiamo la velocita'
+ motore.step(-passi * rapporto);
+ delay(2000);
+}
+++ /dev/null
-
-
-/*
- BYJ48 Stepper motor code
- Connect :
- IN1 >> D8
- IN2 >> D9
- IN3 >> D10
- IN4 >> D11
- VCC ... 5V Prefer to use external 5V Source
- Gnd
- written By :Mohannad Rawashdeh
- http://www.instructables.com/member/Mohannad+Rawashdeh/
- 28/9/2013
- */
-
-#define IN1 8
-#define IN2 9
-#define IN3 10
-#define IN4 11
-int Steps = 0;
-boolean Direction = true;// gre
-unsigned long last_time;
-unsigned long currentMillis ;
-int steps_left=4095;
-long time;
-void setup()
-{
- Serial.begin(115200);
- pinMode(IN1, OUTPUT);
- pinMode(IN2, OUTPUT);
- pinMode(IN3, OUTPUT);
- pinMode(IN4, OUTPUT);
- // delay(1000);
-
-}
-void loop()
-{
- while(steps_left>0){
- currentMillis = micros();
- if(currentMillis-last_time>=1000){
- stepper(1);
- time=time+micros()-last_time;
- last_time=micros();
- steps_left--;
- }
- }
- Serial.println(time);
- Serial.println("Wait...!");
- delay(2000);
- Direction=!Direction;
- steps_left=4095;
-}
-
-void stepper(int xw){
- for (int x=0;x<xw;x++){
- switch(Steps){
- case 0:
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, LOW);
- digitalWrite(IN3, LOW);
- digitalWrite(IN4, HIGH);
- break;
- case 1:
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, LOW);
- digitalWrite(IN3, HIGH);
- digitalWrite(IN4, HIGH);
- break;
- case 2:
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, LOW);
- digitalWrite(IN3, HIGH);
- digitalWrite(IN4, LOW);
- break;
- case 3:
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, HIGH);
- digitalWrite(IN3, HIGH);
- digitalWrite(IN4, LOW);
- break;
- case 4:
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, HIGH);
- digitalWrite(IN3, LOW);
- digitalWrite(IN4, LOW);
- break;
- case 5:
- digitalWrite(IN1, HIGH);
- digitalWrite(IN2, HIGH);
- digitalWrite(IN3, LOW);
- digitalWrite(IN4, LOW);
- break;
- case 6:
- digitalWrite(IN1, HIGH);
- digitalWrite(IN2, LOW);
- digitalWrite(IN3, LOW);
- digitalWrite(IN4, LOW);
- break;
- case 7:
- digitalWrite(IN1, HIGH);
- digitalWrite(IN2, LOW);
- digitalWrite(IN3, LOW);
- digitalWrite(IN4, HIGH);
- break;
- default:
- digitalWrite(IN1, LOW);
- digitalWrite(IN2, LOW);
- digitalWrite(IN3, LOW);
- digitalWrite(IN4, LOW);
- break;
- }
- SetDirection();
- }
-}
-void SetDirection(){
- if(Direction==1){
- Steps++;
- }
- if(Direction==0){
- Steps--;
- }
- if(Steps>7){
- Steps=0;
- }
- if(Steps<0){
- Steps=7;
- }
-}
-
-
--- /dev/null
+/* YourDuinoStarter Example: 2 Stepper Motors
+ - WHAT IT DOES: Runs 2 28BYJ-48 stepper motors with AccelStepper Library
+ - Motors accelerate and decelerate simultaneously in opposite rotations
+ - SEE the comments after "//" on each line below
+ - Derived from example code by Mike McCauley
+ - modified by Celem for single stepper
+ - modified by lowres for two steppers
+ NOTE: This may not run 2 motors from USB.
+ May need separate +5 Supply for motors
+ - CONNECTIONS: See Pin definitions below
+
+ - V1.01 11/30/2013
+ Questions: terry@yourduino.com */
+
+/*-----( Import needed libraries )-----*/
+#include <AccelStepper.h>
+/*-----( Declare Constants and Pin Numbers )-----*/
+#define FULLSTEP 4
+#define HALFSTEP 8
+// motor pins
+
+
+#define motorPin5 8 // Blue - 28BYJ48 pin 1
+#define motorPin6 9 // Pink - 28BYJ48 pin 2
+#define motorPin7 10 // Yellow - 28BYJ48 pin 3
+#define motorPin8 11 // Orange - 28BYJ48 pin 4
+ // Red - 28BYJ48 pin 5 (VCC)
+/*-----( Declare objects )-----*/
+// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
+
+AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
+
+/*-----( Declare Variables )-----*/
+//none
+
+void setup() /****** SETUP: RUNS ONCE ******/
+{
+ stepper2.setMaxSpeed(1000.0);
+ stepper2.setAcceleration(50.0);
+ stepper2.setSpeed(200);
+ stepper2.moveTo(-2048); // 1 revolution
+
+}//--(end setup )---
+
+
+void loop() /****** LOOP: RUNS CONSTANTLY ******/
+{
+ //Change direction at the limits
+ if (stepper2.distanceToGo() == 0)
+ stepper2.moveTo(-stepper2.currentPosition());
+
+ stepper2.run();
+
+}//--(end main loop )---
+
+/*-----( Declare User-written Functions )-----*/
+//none
+//*********( THE END )***********
--- /dev/null
+// ConstantSpeed.pde
+// -*- mode: C++ -*-
+//
+// Shows how to run AccelStepper in the simplest,
+// fixed speed mode with no accelerations
+/// \author Mike McCauley (mikem@airspayce.com)
+// Copyright (C) 2009 Mike McCauley
+// $Id: ConstantSpeed.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
+#define FULLSTEP 4
+#define HALFSTEP 8
+
+#define motorPin5 8 // Blue - 28BYJ48 pin 1
+#define motorPin6 9 // Pink - 28BYJ48 pin 2
+#define motorPin7 10 // Yellow - 28BYJ48 pin 3
+#define motorPin8 11 // Orange - 28BYJ48 pin 4
+
+#include <AccelStepper.h>
+
+AccelStepper stepper(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
+void setup()
+{
+ stepper.setMaxSpeed(1000);
+ stepper.setSpeed(50);
+}
+void loop()
+{
+ stepper.runSpeed();
+}
+
+++ /dev/null
-/* YourDuinoStarter Example: 2 Stepper Motors
- - WHAT IT DOES: Runs 2 28BYJ-48 stepper motors with AccelStepper Library
- - Motors accelerate and decelerate simultaneously in opposite rotations
- - SEE the comments after "//" on each line below
- - Derived from example code by Mike McCauley
- - modified by Celem for single stepper
- - modified by lowres for two steppers
- NOTE: This may not run 2 motors from USB.
- May need separate +5 Supply for motors
- - CONNECTIONS: See Pin definitions below
-
- - V1.01 11/30/2013
- Questions: terry@yourduino.com */
-
-/*-----( Import needed libraries )-----*/
-#include <AccelStepper.h>
-/*-----( Declare Constants and Pin Numbers )-----*/
-#define FULLSTEP 4
-#define HALFSTEP 8
-// motor pins
-#define motorPin1 4 // Blue - 28BYJ48 pin 1
-#define motorPin2 5 // Pink - 28BYJ48 pin 2
-#define motorPin3 6 // Yellow - 28BYJ48 pin 3
-#define motorPin4 7 // Orange - 28BYJ48 pin 4
- // Red - 28BYJ48 pin 5 (VCC)
-
-#define motorPin5 8 // Blue - 28BYJ48 pin 1
-#define motorPin6 9 // Pink - 28BYJ48 pin 2
-#define motorPin7 10 // Yellow - 28BYJ48 pin 3
-#define motorPin8 11 // Orange - 28BYJ48 pin 4
- // Red - 28BYJ48 pin 5 (VCC)
-/*-----( Declare objects )-----*/
-// NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
-AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
-AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
-
-/*-----( Declare Variables )-----*/
-//none
-
-void setup() /****** SETUP: RUNS ONCE ******/
-{
- stepper1.setMaxSpeed(1000.0);
- stepper1.setAcceleration(50.0);
- stepper1.setSpeed(200);
- stepper1.moveTo(2048); // 1 revolution
-
- stepper2.setMaxSpeed(1000.0);
- stepper2.setAcceleration(50.0);
- stepper2.setSpeed(200);
- stepper2.moveTo(-2048); // 1 revolution
-
-}//--(end setup )---
-
-
-void loop() /****** LOOP: RUNS CONSTANTLY ******/
-{
- //Change direction at the limits
- if (stepper1.distanceToGo() == 0)
- stepper1.moveTo(-stepper1.currentPosition());
- if (stepper2.distanceToGo() == 0)
- stepper2.moveTo(-stepper2.currentPosition());
-
- stepper1.run();
- stepper2.run();
-
-}//--(end main loop )---
-
-/*-----( Declare User-written Functions )-----*/
-//none
-//*********( THE END )***********
+++ /dev/null
-
-/*
- Stepper Motor Control - one revolution
-
- Revisionato per i motori 5v 28YBJ-48 con controller board
- - http://arduino-info.wikispaces.com/SmallSteppers
-
- This program drives a unipolar or bipolar stepper motor.
- The motor is attached to digital pins 8 - 11 of the Arduino.
-
- The motor should revolve one revolution in one direction, then
- one revolution in the other direction.
-
-
- Created 11 Mar. 2007
- Modified 30 Nov. 2009
- by Tom Igoe
-
- */
-
-#include <Stepper.h>
-
-const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
-// for your motor
-// 2048 = 360deg = 32*64 in 4-step sequence as in Step Library
-// 1025 = 180deg
-// 512.5 = 90deg
-// 5.6944 = 1deg
-
-// initialize the stepper library on pins 8 through 11:
-Stepper myStepper(stepsPerRevolution,8,10,9,11);
-// Sequence is 1-3-2-4
-// Valid values: (8,10,11,9), (9,11,8,10), (10,8,9,11), and (11,9,10,8)
-// 1N1 on pin 8
-// 1N2 on pin 9
-// 1N3 on pin 10
-// 1N4 on pin 11
-// powered via 5v
-// Max speed is 14RPM @ 5v
-
-void setup() {
- // set the speed at 60 rpm:
- myStepper.setSpeed(14); // Max speed is 14RPM @5v
- // initialize the serial port:
- Serial.begin(9600);
-}
-
-void loop() {
- // step one revolution in one direction:
- Serial.println("clockwise");
- myStepper.step(stepsPerRevolution);
- delay(500);
-
- // step one revolution in the other direction:
- Serial.println("counterclockwise");
- myStepper.step(-stepsPerRevolution);
- delay(500);
-}
-