This repository was archived by the owner on Mar 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples for utilization of GPIO
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "GPIOlib.h" | ||
|
||
using namespace GPIO; | ||
|
||
int main() | ||
{ | ||
init(); | ||
|
||
//Move forward | ||
controlLeft(FORWARD,50); | ||
controlRight(FORWARD,50); | ||
delay(1000); | ||
|
||
//Stop | ||
stopLeft(); | ||
stopRight(); | ||
delay(1000); | ||
|
||
//Move backward | ||
controlLeft(BACKWARD,50); | ||
controlRight(BACKWARD,50); | ||
delay(1000); | ||
|
||
//Stop | ||
stopLeft(); | ||
stopRight(); | ||
delay(1000); | ||
|
||
//2 motors can work at different speeds. | ||
controlLeft(FORWARD,30); | ||
controlRight(FORWARD,40); | ||
delay(1000); | ||
|
||
//Stop | ||
stopLeft(); | ||
stopRight(); | ||
delay(1000); | ||
|
||
//Even directions can differ from each other. | ||
controlLeft(BACKWARD,35); | ||
controlRight(FORWARD,20); | ||
delay(1000); | ||
|
||
//Don't forget to stop all motors before exiting. | ||
stopLeft(); | ||
stopRight(); | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <cstdio> | ||
#include <cmath> | ||
#include "GPIOlib.h" | ||
|
||
using namespace std; | ||
using namespace GPIO; | ||
|
||
int readingLeft=0,readingRight=0; | ||
|
||
int main() | ||
{ | ||
init(); | ||
|
||
controlLeft(FORWARD,30); | ||
controlRight(BACKWARD,40); | ||
|
||
for(int i=0;i<10;i++) | ||
{ | ||
resetCounter(); | ||
delay(1000); | ||
getCounter(&readingLeft,&readingRight); | ||
if(readingLeft==-1||readingRight==-1) | ||
{ | ||
printf("Error!\n"); | ||
continue; | ||
} | ||
//Distance is in mm. | ||
double distanceLeft=readingLeft*63.4*M_PI/390; | ||
double distanceRight=readingRight*63.4*M_PI/390; | ||
printf("Left wheel moved %.2lf cm, right wheel moved %.2lf cm in last second.\n",distanceLeft/10,distanceRight/10); | ||
} | ||
stopLeft(); | ||
stopRight(); | ||
return 0; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "GPIOlib.h" | ||
|
||
using namespace GPIO; | ||
|
||
int main() | ||
{ | ||
init(); | ||
|
||
//THIS IS THE SAFE RANGE! | ||
for(int i=-45;i<=45;i+=15) | ||
{ | ||
turnTo(i); | ||
delay(1000); | ||
} | ||
|
||
turnTo(0); | ||
return 0; | ||
} |