Jump to content
ELFORUM - Forumul electronistilor

Dancing minibot


Recommended Posts

Am gasit ceva superamuzant si interesant:

E si schema, mai putin .hex-ul....

Credeti ca s-ar putea crea un .hex pt asa ceva? Sau cu un alt micorcontroler?

 

L.E. Am gasit un asm:

 

// Pins connected to the motor driver. The PWM pins control the speed, and the

// other pins are used to select the current operation of the left/right

// channels of the driver- forward, reverse, stopped, or brake.

#define LEFT_PWM 3

#define LEFT_1 2

#define LEFT_2 4

#define RIGHT_PWM 6

#define RIGHT_1 7

#define RIGHT_2 5

 

void setup()

{

Serial.begin(57600); // This isn’t actually used anywhere; it’s here because

// once you start modifying the code and need to add

// print statements, you’ll forget to put this back in.

pinSetup(); // Configure the pins for the application. If we are in

// test mode, this will also configure the pins needed

// to support the addtional test functionality.

driveStop(); // Just to be good citizens, make sure the motors aren’t

// going to just randomly start turning.

}

 

void loop()

{

driveFwd(128);

delay(3000);

 

driveStop();

delay(500);

 

driveRev(128);

delay(2000);

 

leftFwd(128);

rightRev(128);

delay(1000);

 

leftRev(128);

rightFwd(128);

delay(1000);

 

}

 

void pinSetup()

{

pinMode(LEFT_PWM, OUTPUT);

pinMode(LEFT_1, OUTPUT);

pinMode(LEFT_2, OUTPUT);

pinMode(RIGHT_PWM, OUTPUT);

pinMode(RIGHT_1, OUTPUT);

pinMode(RIGHT_2, OUTPUT);

}

 

// Stop mode is simply a hi-z state. The motor will coast for some time if it

// is running at the time when this mode is activated.

void driveStop()

{

leftStop();

rightStop();

}

 

// Brake mode actually connects the two pins of the motor together, which will

// cause it to stop more quickly and to resist moving to some extent.

void driveBrake()

{

leftBrake();

rightBrake();

}

 

// Forward and reverse ground one pin and then toggle the other at the rate

// defined by the PWM inputs.

void driveFwd(byte spd)

{

leftFwd(spd);

rightFwd(spd);

}

 

void driveRev(byte spd)

{

leftRev(spd);

rightRev(spd);

}

 

// The left/right Rev/Fwd functions are set forth in the datasheet. Worth

// noting- this is relative to the preferred assembly of the Minibot kit. If

// you wire up your motors in another way, expect different results.

void leftRev(byte spd)

{

digitalWrite(LEFT_1, HIGH);

digitalWrite(LEFT_2, LOW);

analogWrite(LEFT_PWM, spd);

}

 

void leftFwd(byte spd)

{

digitalWrite(LEFT_1, LOW);

digitalWrite(LEFT_2, HIGH);

analogWrite(LEFT_PWM, spd);

}

 

void rightRev(byte spd)

{

digitalWrite(RIGHT_1, HIGH);

digitalWrite(RIGHT_2, LOW);

analogWrite(RIGHT_PWM, spd);

}

 

void rightFwd(byte spd)

{

digitalWrite(RIGHT_1, LOW);

digitalWrite(RIGHT_2, HIGH);

analogWrite(RIGHT_PWM, spd);

}

 

void leftBrake()

{

digitalWrite(LEFT_1, HIGH);

digitalWrite(LEFT_2, HIGH);

analogWrite(LEFT_PWM, 0);

}

 

void rightBrake()

{

digitalWrite(RIGHT_1, HIGH);

digitalWrite(RIGHT_2, HIGH);

analogWrite(RIGHT_PWM, 0);

}

 

void leftStop()

{

digitalWrite(LEFT_1, LOW);

digitalWrite(LEFT_2, LOW);

analogWrite(LEFT_PWM, 0);

}

 

void rightStop()

{

digitalWrite(RIGHT_1, LOW);

digitalWrite(RIGHT_2, LOW);

analogWrite(RIGHT_PWM, 0);

}

 

Il poate compila cineva in hex? Eu nu am assamblerul de la MPLAB instalat...

Si eventual, verificat, va rog? daca e pt pic-ul folosit?

Multumesc frumos.

post-71315-139829782799_thumb.jpg

Link to comment
  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Codul pe care l-ai postat mai sus nu e asm ci c (mikroc??).Hexul pe care l-ai postat nu contine nimic (nu-s decat FF-uri).

Am inteles. De aia n-a compilat nimic, trebuia asm.Ma poate ajuta cineva cu compilarea? Multumesc anticipat.
Link to comment

Părerea mea umilă , de începător în C , este că acel cod nu e complet . Par a lipsi definițiile unor funcții care se aflau probabil în alt fișier. N-am vrut să mă bag , dar dacă n-a răspuns nimeni mai priceput ...Cu rezerva că s-ar putea să greșesc.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines