Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inderpreet/f885a0bce168d8f0bb4f72d8acad1eb9 to your computer and use it in GitHub Desktop.
Save inderpreet/f885a0bce168d8f0bb4f72d8acad1eb9 to your computer and use it in GitHub Desktop.
MSP430 Robot Control 2
/*
MSP430 Robot Control
*/
#define FWD HIGH
#define BKW LOW
int fadeAmount = 5; // how many points to fade the LED by
int iSpeed = 0; // Variable to store Speed
/* ---------------------------------------------------
The left wheel is connected to Pin 1.6 and 1.0
The right wheel is connected to Pin 1.2 and 1.1
*/
const int pEnable1 = P1_6; // Right wheel speed control
const int pEnable2 = P1_2; // Left Wheel speed control
const int pDir1 = P1_0;
const int pDir2 = P1_1;
void setup() {
// declare pin 14 to be an output:
pinMode(pEnable1, OUTPUT);
pinMode(pEnable2, OUTPUT);
pinMode( pDir1, OUTPUT);
pinMode( pDir2, OUTPUT);
digitalWrite(pDir1, FWD); // Set Inital Direction to HIGH?
digitalWrite(pDir2, FWD);
analogWrite(pEnable1, 0x00); // Set initial speed to zero
analogWrite(pEnable2, 0x00);
}
void loop() {
// set the iSpeed of pin 9:
analogWrite(pEnable1, iSpeed);
analogWrite(pEnable2, iSpeed);
// change the iSpeed for next time through the loop:
iSpeed = iSpeed + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (iSpeed == 0 || iSpeed == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
//delay(5);
if(iSpeed==0){
digitalWrite(pDir1, !digitalRead(pDir1));
digitalWrite(pDir2, !digitalRead(pDir2));
delay(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment