arduino mega, fotocellule e stepper motor

mega e stepper

per la residenza artistica Alter che comincia il 26 luglio a Chiaramonte Gulfi (RG), sto preparando dei motori stepper che verranno azionati dalla luce.

Userò un Arduino mega perché necessito di molti pin…qui di seguito il codice, prima di vedere come funzionerà nei giorni 1, 2 e 3 agosto 2015
/*
Stepper Motor Control – speed control
credits http://www.tigoe.com/

This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 4 – 7 of the Arduino.
The motor is attached to digital pins 8 – 11 of the Arduino.
A photoresistor is connected to analog input 0
A photoresistor is connected to analog input 1
A photoresistor is connected to analog input 2
A photoresistor is connected to analog input 3

The motor will rotate in a clockwise direction. The higher the potentiometer value,
the faster the motor speed. Because setSpeed() sets the delay between steps,
you may notice the motor is less responsive to changes in the sensor value at
low speeds.

Created 30 Nov. 2009
Modified 28 Oct 2010
by Tom Igoe

my version: summer 2015. Mainenti http://www.soundobject.eu

*/

#include <Stepper.h>
const int stepsPerRevolution = 500; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 4 through 7:
Stepper myStepper1(stepsPerRevolution, 4, 5, 6, 7);
// initialize the stepper library on pins 8 through 11:
Stepper myStepper2(stepsPerRevolution, 8, 9, 10, 11);
// initialize the stepper library on pins 22 through 25:
Stepper myStepper3(stepsPerRevolution, 22, 23, 24, 25);
// initialize the stepper library on pins 30 through 33:
Stepper myStepper4(stepsPerRevolution, 30, 31, 32, 33);

//int stepCount = 0; // number of steps the motor has taken

void setup() {
// nothing to do inside the setup
}

void loop() {
// read the sensor value:
int sensorReading1 = analogRead(A0);
// map it to a range from 0 to 100:
int sensorReading2 = analogRead(A1);
// map it to a range from 0 to 200:
// read the sensor value:
int sensorReading3 = analogRead(A2);
// map it to a range from 0 to 300:
int sensorReading4 = analogRead(A3);
// map it to a range from 0 to 400:

// int val = map(analogRead(0), 0, 1023, 48, 0);
int motorSpeed1 = map(sensorReading1, 100, 1023, 0, 100);
// set the motor speed:
int motorSpeed2 = map(sensorReading2, 50, 1023, 0, 250);
// set the motor speed:
int motorSpeed3 = map(sensorReading3, 150, 1023, 0, 370);
// set the motor speed:
int motorSpeed4 = map(sensorReading4, 300, 1023, 0, 500);
// set the motor speed:

if (motorSpeed1 > 0) {
myStepper1.setSpeed(motorSpeed1);
// step 1/100 of a revolution:
myStepper1.step(stepsPerRevolution / 100);
}
if (motorSpeed2 > 0) {
myStepper2.setSpeed(motorSpeed2);
// step 1/100 of a revolution:
myStepper2.step(stepsPerRevolution / 250);
}
if (motorSpeed3 > 0) {
myStepper3.setSpeed(motorSpeed3);
// step 1/100 of a revolution:
myStepper3.step(stepsPerRevolution / 370);
}
if (motorSpeed4 > 0) {
myStepper4.setSpeed(motorSpeed4);
// step 1/100 of a revolution:
myStepper4.step(stepsPerRevolution / 500);

//stepCount = val;
//delay(5);

}
}