Created
December 16, 2019 10:11
-
-
Save Electronza/af64388e024f8f1c1556f3a914a04308 to your computer and use it in GitHub Desktop.
Programming the Mikroe Buggy in MPIDE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Mikroe Buggy - testing the LED's on the Buggy | |
*/ | |
// LEDs on the Clicker2 for PIC32MX | |
#define CLICK_LED1 3 | |
#define CLICK_LED2 69 | |
// LEDs on the Buggy | |
#define Headlights 22 | |
#define Main_Beam 42 | |
#define Brake 28 | |
#define Turn_L 62 | |
#define Turn_R 24 | |
void setup() { | |
// initialize the digital pins as an output. | |
pinMode(CLICK_LED1, OUTPUT); | |
pinMode(CLICK_LED2, OUTPUT); | |
pinMode(Headlights, OUTPUT); | |
pinMode(Main_Beam, OUTPUT); | |
pinMode(Brake, OUTPUT); | |
pinMode(Turn_L, OUTPUT); | |
pinMode(Turn_R, OUTPUT); | |
} | |
void loop() { | |
digitalWrite(CLICK_LED1, HIGH); // flash the LEDs on the Clicker2 | |
digitalWrite(CLICK_LED2, HIGH); | |
delay(2000); // wait for two seconds | |
digitalWrite(CLICK_LED1, LOW); // flash the LEDs on the Clicker2 | |
digitalWrite(CLICK_LED2, LOW); | |
delay(1000); // wait for one second | |
digitalWrite(Headlights, HIGH); // headlights on | |
delay(5000); // wait for five seconds | |
digitalWrite(Main_Beam, HIGH); // flash main beam | |
delay(1000); | |
digitalWrite(Main_Beam, LOW); | |
delay(1000); | |
digitalWrite(Main_Beam, HIGH); | |
delay(1000); | |
digitalWrite(Main_Beam, LOW); | |
delay(1000); | |
digitalWrite(Headlights, LOW); // all lights off | |
delay(2000); | |
digitalWrite(Brake, HIGH); // brake lighhts on for five seconds | |
delay(5000); | |
digitalWrite(Brake, LOW); | |
delay(1000); | |
for (int flash = 1; flash < 10; flash++) { // flash the turn signals | |
// turn the signals on: | |
digitalWrite(Turn_L, HIGH); | |
digitalWrite(Turn_R, HIGH); | |
delay(500); | |
// turn the signals off: | |
digitalWrite(Turn_L, LOW); | |
digitalWrite(Turn_R, LOW); | |
delay(500); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
MikroElektronika Buggy | |
A code example to control the motors | |
This example code is in the public domain. | |
*/ | |
void setup() { | |
// initialize the digital pins as an output. | |
pinMode(25, OUTPUT); | |
pinMode(29, OUTPUT); | |
pinMode(37, OUTPUT); | |
pinMode(53, OUTPUT); | |
// Full stop | |
analogWrite(25, 0); | |
analogWrite(29, 0); | |
analogWrite(37, 0); | |
analogWrite(53, 0); | |
delay(3000); | |
// start moving forward | |
analogWrite(25, 0); | |
analogWrite(29, 255); | |
analogWrite(37, 0); | |
analogWrite(53, 255); | |
delay(2000); | |
// Full stop | |
analogWrite(25, 0); | |
analogWrite(29, 0); | |
analogWrite(37, 0); | |
analogWrite(53, 0); | |
delay(3000); | |
// start moving backward | |
analogWrite(25, 255); | |
analogWrite(29, 0); | |
analogWrite(37, 255); | |
analogWrite(53, 0); | |
delay(2000); | |
// Full stop | |
analogWrite(25, 0); | |
analogWrite(29, 0); | |
analogWrite(37, 0); | |
analogWrite(53, 0); | |
delay(3000); | |
// Let's complicate things | |
// Start moving forward at full speed | |
// to overcome inertia | |
analogWrite(25, 0); | |
analogWrite(29, 255); | |
analogWrite(37, 0); | |
analogWrite(53, 255); | |
delay(50); | |
// Then slow down a bit | |
analogWrite(25, 0); | |
analogWrite(29, 70); | |
analogWrite(37, 0); | |
analogWrite(53, 70); | |
delay(1000); | |
// Full stop | |
analogWrite(25, 0); | |
analogWrite(29, 0); | |
analogWrite(37, 0); | |
analogWrite(53, 0); | |
delay(3000); | |
// Start moving backwards at full speed | |
// to overcome inertia | |
analogWrite(25, 255); | |
analogWrite(29, 0); | |
analogWrite(37, 255); | |
analogWrite(53, 0); | |
delay(50); | |
// Then slow down a bit and perform a slight turn | |
analogWrite(25, 70); | |
analogWrite(29, 0); | |
analogWrite(37, 100); | |
analogWrite(53, 0); | |
delay(1000); | |
// Full stop | |
analogWrite(25, 0); | |
analogWrite(29, 0); | |
analogWrite(37, 0); | |
analogWrite(53, 0); | |
delay(3000); | |
// Turn around | |
analogWrite(25, 255); | |
analogWrite(29, 0); | |
analogWrite(37, 0); | |
analogWrite(53, 255); | |
delay(1000); | |
// Full stop | |
analogWrite(25, 0); | |
analogWrite(29, 0); | |
analogWrite(37, 0); | |
analogWrite(53, 0); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment