Catégories
Liens
Ceci est une ancienne révision du document !
Photos ou guide pas à pas
// Include the Stepper Library #include <Stepper.h> // VARAIABLES INTERESSANTES int leds_up = 0; // int wait = 29000; // blablablabla int lamp_up = 29000; // int motor_up = 7 ; // = 7 giris = 42 sec if speed = 5 int motor_break = 7000 ;// after leds down int lamp_down = 5000; int motor_down = 7 ; // = 7 giris = sec if speed = 40 // ============================= // const int leds = 6; const int lamp = 5; // Map our pins to constants to make things easier to keep track of const int pwmA = 3; const int pwmB = 11; const int brakeA = 9; const int brakeB = 8; const int dirA = 12; const int dirB = 13; // The amount of steps for a full revolution of your motor. // 360 / stepAngle const int STEPS = 200; // Initialize the Stepper class Stepper myStepper(STEPS, dirA, dirB); void setup() { // Set the RPM of the motor myStepper.setSpeed(60); // Turn on pulse width modulation pinMode(pwmA, OUTPUT); pinMode(pwmB, OUTPUT); digitalWrite(pwmA, HIGH); digitalWrite(pwmB, HIGH); // Turn off the brakes pinMode(brakeA, OUTPUT); pinMode(brakeB, OUTPUT); digitalWrite(brakeA, LOW); digitalWrite(brakeB, LOW); // Log some shit Serial.begin(9600); // LEDS variano da 0 (spento) a 255 (acceso full) analogWrite(leds, 10); // LAMP varia da 0 a 255 analogWrite(lamp, 0); } void motorON() { digitalWrite(pwmA, HIGH); digitalWrite(pwmB, HIGH); } void motorOFF() { digitalWrite(pwmA, LOW); digitalWrite(pwmB, LOW); } void fadeout (int _pin, int _intensity, int _time){ int time = (int) (_time / 255); for (int i = 0; i <= 255; i++) { int lampBright = 255 - i; analogWrite(_pin, map(lampBright, 0, 255, 0, _intensity)); delay(time); } } void fadein (int _pin, int _intensity, int _time){ int time = (int) (_time / 255); for (int i = 0; i <= 255; i++) { analogWrite(_pin, map(i, 0, 255, 0, _intensity)); delay(time); } } void loop() { delay(wait); fadein(lamp, 200, lamp_up); // pin (leds or lamp), intensity max, temps total motorON(); myStepper.setSpeed(2); // 5 giri al minuto ==> 1 giri = 3 sec. myStepper.step(STEPS * motor_up); delay(motor_break); fadeout(lamp, 200, lamp_down); motorOFF(); }