Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inderpreet/294d90c98fb12d91c2e1c445e4263126 to your computer and use it in GitHub Desktop.
Save inderpreet/294d90c98fb12d91c2e1c445e4263126 to your computer and use it in GitHub Desktop.
MSP430 Robot Trail 1
/*
Energia Porgram to Control the MSP430 Robot
Exercise 1.
*/
#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 forward1(int a){
analogWrite(pEnable1, 255);
analogWrite(pEnable2, 255);
delay(a);
analogWrite(pEnable1, 0);
analogWrite(pEnable2, 0);
}
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, BKW);
analogWrite(pEnable1, 0x00); // Set initial speed to zero
analogWrite(pEnable2, 0x00);
}
void loop() {
delay(5000);
// set the iSpeed of pin 9:
analogWrite(pEnable1, 255);
analogWrite(pEnable2, 255);
delay(700);
analogWrite(pEnable1, 0);
analogWrite(pEnable2, 0);
digitalWrite(pDir1, !digitalRead(pDir1));
analogWrite(pEnable1, 255);
analogWrite(pEnable2, 255);
delay(500);
digitalWrite(pDir1, !digitalRead(pDir1));
analogWrite(pEnable1, 255);
analogWrite(pEnable2, 255);
delay(300);
analogWrite(pEnable1, 00);
analogWrite(pEnable2, 0);
forward1(1000);
while(1){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment