Kezdőoldal » Számítástechnika » Programozás » Arduino hoz kérhetek egy kis...

Arduino hoz kérhetek egy kis segítséget?

Figyelt kérdés

2016. máj. 23. 17:01
 1/6 A kérdező kommentje:

Ezt csinálom: [link]

A problémám az, hogy egy lépés helyett egy teljes kört tesz meg kis lépésenként a motor. Tudnátok segíteni?

2016. máj. 23. 17:03
 2/6 anonim ***** válasza:
49%
Bocs, elromlott a kristálygömböm, így holnapig nem tudok segíteni, csak, ha mutatod a kódot.
2016. máj. 25. 15:34
Hasznos számodra ez a válasz?
 3/6 A kérdező kommentje:
A kód ott van a leírásban, de mutatom
2016. máj. 26. 06:50
 4/6 A kérdező kommentje:

int LaserState = LOW; // The variable that stores the state of the laser beam.

int sensor = 8 ; // Change this value to calibrate your harp's sensor

int delaylaser = 5; // If you increase this, the laser will be brighter, but the harp will be less fluid

int delaymotor = 3; // This variable affects the speed, and fluidity of the harp.


int LaserPin = 7; // Tell the arduino that the laser is on pin 7


int motorPin1 = 8; //Use these names for the pin numbers.

int motorPin2 = 9;

int motorPin3 = 10;

int motorPin4 = 11;


int note9 = 0x61;

int note8 = 0x63;

int note7 = 0x64;

int note6 = 0x66;

int note5 = 0x68;

int note4 = 0x70;

int note3 = 0x71;

int note2 = 0x40;

int note1 = 0x47;


int a, b, c, d, e, f, g, h, i = 0; // Iniating the note status markers.


void setup()

{



pinMode(8, OUTPUT); // Setup for the motor.

pinMode(9, OUTPUT);

pinMode(10, OUTPUT);

pinMode(11, OUTPUT);



pinMode(LaserPin, OUTPUT); // Setup for laser.



pinMode(13, OUTPUT); // Setup for status led.



Serial.begin(31250); // Start a serial communication channel for MIDI

}


void noteOn(int cmd, int pitch, int velocity) // Function to play the notes

{

Serial.write(cmd);

Serial.write(pitch);

Serial.write(velocity);

}


void loop()

{


digitalWrite(LaserPin, HIGH); // Turn on the laser for the 1st beam.

delay(delaylaser);


if ( (analogRead(0) > sensor ) && (a == 0) ) // If the sensor gets a signal, and the not is not playing:


{

digitalWrite(13, HIGH); // Switch on status led.

noteOn(0x90, note1, 0x7F); // Play note 1

a++; // Change the status variable to one.

}



else if(analogRead(0) < sensor ) // If the sensor does not get a signal:


{

digitalWrite(13, LOW); // Switch off the status led.

noteOn(0x90, note1, 0x00); // Stop playing note 1.

a = 0; // Change the status variable to zero.

}



digitalWrite(LaserPin, LOW); // Turn off the Laser.



digitalWrite(motorPin1, HIGH); // Move the motor to create the second beam.( One step forward)

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor); // Small pause



digitalWrite(LaserPin, HIGH); // Turn on the laser for the 2nd beam.

delay(delaylaser);


if( (analogRead(0) > sensor ) && (b == 0) ) // If the sensor gets a signal, and the not is not playing:


{

digitalWrite(13, HIGH); // Switch on status led.

noteOn(0x90, note2, 0x7F); // Play note 2

b++; // Change the status variable to one.

}



else if(analogRead(0) < sensor ) // If the sensor does not get a signal:


{

digitalWrite(13, LOW); // Switch off the status led.

noteOn(0x90, note2, 0x00); // Stop playing note 2.

b = 0; // Change the status variable to zero.

}


digitalWrite(LaserPin, LOW); // Turn off the Laser.



digitalWrite(motorPin1, LOW); // Move the motor to create the second beam.( One step forward)

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor); // Small pause



digitalWrite(LaserPin, HIGH); // Turn on the laser for the 3rd beam.

delay(delaylaser);


if( (analogRead(0) > sensor ) && (c == 0) ) // If the sensor gets a signal, and the not is not playing:


{

digitalWrite(13, HIGH); // Switch on status led.

noteOn(0x90, note3, 0x7F); // Play note 3

c++; // Change the status variable to one.

}



else if(analogRead(0) < sensor ) // If the sensor does not get a signal:

{

digitalWrite(13, LOW); // Switch off the status led.

noteOn(0x90, note3, 0x00); // Stop playing note 2.

c = 0; // Change the status variable to zero.

}


digitalWrite(LaserPin, LOW); // Turn off the Laser.


digitalWrite(motorPin1, LOW); // Move the motor to create the third beam.( One step forward)

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

delay(delaymotor); // Small pause


// Contiue in the same way for the rest of the code.


digitalWrite(LaserPin, HIGH); //This is beam 4

delay(delaylaser);


if( (analogRead(0) > sensor ) && (d == 0) )

{

digitalWrite(13, HIGH);

noteOn(0x90, note4, 0x7F);

d++;

}



else if(analogRead(0) < sensor )

{

digitalWrite(13, LOW);

noteOn(0x90, note4, 0x00);

d = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 5

delay(delaylaser);


if( (analogRead(0) > sensor ) && (e == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note5, 0x7F);

e++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note5, 0x00);

e = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 6

delay(delaylaser);


if( (analogRead(0) > sensor ) && (f == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note6, 0x7F);

f++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note6, 0x00);

f = 0;

}


digitalWrite(LaserPin, LOW);


digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 7

delay(delaylaser);


if( (analogRead(0) > sensor ) && (g == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note7, 0x7F);

g++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note7, 0x00);

g = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 8

delay(delaylaser);


if( (analogRead(0) > sensor ) && (h == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note8, 0x7F);

h++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note8, 0x00);

h = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 9

delay(delaylaser);


if( (analogRead(0) > sensor ) && (i == 0) )

{

digitalWrite(13, HIGH);

noteOn(0x90, note9, 0x7F);

i++;

}


else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note9, 0x00);

i = 0;

}



digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

delay(delaymotor);


digitalWrite(LaserPin, HIGH); //This is beam 8

delay(delaylaser);


if( (analogRead(0) > sensor ) && (h == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note8, 0x7F);

h++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note8, 0x00);

h = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 7

delay(delaylaser);


if( (analogRead(0) > sensor ) && (g == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note7, 0x7F);

g++;

}



else if(analogRead(0) < sensor )

{

digitalWrite(13, LOW);

noteOn(0x90, note7, 0x00);

g = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 6

delay(delaylaser);


if( (analogRead(0) > sensor ) && (f == 0) )


{


digitalWrite(13, HIGH);

noteOn(0x90, note6, 0x7F);

f++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note6, 0x00);

f = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 5

delay(delaylaser);


if( (analogRead(0) > sensor ) && (e == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note5, 0x7F);

e++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note5, 0x00);

e = 0;

}


digitalWrite(LaserPin, LOW);


digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 4

delay(delaylaser);


if( (analogRead(0) > sensor ) && (d == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note4, 0x7F);

d++;

}


else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note4, 0x00);

d = 0;

}


digitalWrite(LaserPin, LOW);


digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor);



digitalWrite(LaserPin, HIGH); //This is beam 3

delay(delaylaser);


if( (analogRead(0) > sensor ) && (c == 0) )

{

digitalWrite(13, HIGH);

noteOn(0x90, note3, 0x7F);

c++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note3, 0x00);

c = 0;

}


digitalWrite(LaserPin, LOW);


digitalWrite(motorPin1, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

delay(delaymotor);


digitalWrite(LaserPin, HIGH); //This is beam 2

delay(delaylaser);


if( (analogRead(0) > sensor ) && (b == 0) )


{

digitalWrite(13, HIGH);

noteOn(0x90, note2, 0x7F);

b++;

}



else if(analogRead(0) < sensor )


{

digitalWrite(13, LOW);

noteOn(0x90, note2, 0x00);

b = 0;

}


digitalWrite(LaserPin, LOW);



digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

delay(delaymotor);



// Back to top.


}

2016. máj. 26. 06:53
 5/6 anonim ***** válasza:
Jaj OK, azt hittem, magadtól írtad meg, és valószínű lett volna akkor, hogy valamit elrontottál benne, ezért mondtam. Arra tippelnék, hogy a te alakatrészeidnél valamilyen alapértelmezett érték más, esetleg a MIDI konvertálással van gond.
2016. máj. 26. 14:29
Hasznos számodra ez a válasz?
 6/6 anonim ***** válasza:

"egy lépés helyett egy teljes kört tesz meg kis lépésenként a motor"


(A motor léptetésének megoldása szörnyű, legalábbis a forráskód. Magát a léptetés mintázatok kezelését ennél praktikusabban is meg lehet oldani.)

Ciklust nem látok a progiban, csak a loop függvényt, ami nem tudom, hogy hívódik meg. De elvileg a loop végén egy olyan pozícióban kellene lennie a motornak, amiből a kezdeti pozícióba áll vissza, ha elölről kezd futni a függvény, szóval az szerintem okés. (Mert ha jól értem az a gond, hogy a ciklusmag elején nem ugyanott áll meg a motor, mint az előző ciklusban.)

2016. jún. 23. 10:55
Hasznos számodra ez a válasz?

Kapcsolódó kérdések:





Minden jog fenntartva © 2024, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu

A weboldalon megjelenő anyagok nem minősülnek szerkesztői tartalomnak, előzetes ellenőrzésen nem esnek át, az üzemeltető véleményét nem tükrözik.
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!