Lab_interaccio/2016/Chami/Chami.ino

50 lines
1.3 KiB
Arduino
Raw Permalink Normal View History

2025-02-25 21:29:42 +01:00
#define pasos 2000
#define tiempo_paso 1000
#define tiempo_entre_giro 1000
#define enable 4
#define step 5
#define dir 6
void setup() {
pinMode(enable,OUTPUT); // Enable
pinMode(step,OUTPUT); // Step
pinMode(dir,OUTPUT); // Dir
digitalWrite(enable,LOW); // Set Enable low
}
void giro_derecha(int paso)
{
digitalWrite(dir,HIGH); // Set Dir high
for(int x = 0; x < paso; x++) // Loop 200 times
{
digitalWrite(step,HIGH); // Output high
delayMicroseconds(tiempo_paso); // Wait 1/2 a ms
digitalWrite(step,LOW); // Output low
delayMicroseconds(tiempo_paso); // Wait 1/2 a ms
}
}
void giro_izquierda(int paso)
{
digitalWrite(dir,LOW); // Set Dir low
for(int x = 0; x < paso; x++) // Loop 2000 times
{
digitalWrite(step,HIGH); // Output high
delayMicroseconds(tiempo_paso); // Wait 1/2 a ms
digitalWrite(step,LOW); // Output low
delayMicroseconds(tiempo_paso); // Wait 1/2 a ms
}
}
void loop()
{
giro_derecha(pasos);
// delay(tiempo_entre_giro); // pause one second
// giro_izquierda(pasos);
// delay(tiempo_entre_giro); // pause one second
// giro_derecha(pasos/2);
// delay(tiempo_entre_giro/2); // pause one second
// giro_izquierda(pasos/2);
// delay(tiempo_entre_giro/2); // pause one second
}