use argc and rename PIN_MOTOR-Flags
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
#include<string.h>
|
||||
#include "gpio.h"
|
||||
|
||||
#define PIN_MOTOR1_FORWARD "20"
|
||||
#define PIN_MOTOR1_REVERSE "13"
|
||||
#define PIN_MOTOR2_FORWARD "19"
|
||||
#define PIN_MOTOR2_REVERSE "26"
|
||||
#define PIN_MOTOR_RECHTS_FORWARD "20"
|
||||
#define PIN_MOTOR_RECHTS_REVERSE "13"
|
||||
#define PIN_MOTOR_LINKS_REVERSE "19"
|
||||
#define PIN_MOTOR_LINKS_FORWARD "26"
|
||||
|
||||
#define MOTOR_ON 1
|
||||
#define MOTOR_OFF 0
|
||||
@@ -19,16 +19,16 @@ void forward(int motorNumber)
|
||||
{
|
||||
if(motorNumber == 1)
|
||||
{
|
||||
writeOutput(PIN_MOTOR1_FORWARD, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_RECHTS_FORWARD, MOTOR_ON);
|
||||
}
|
||||
else if(motorNumber == 2)
|
||||
{
|
||||
writeOutput(PIN_MOTOR2_FORWARD, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_LINKS_FORWARD, MOTOR_ON);
|
||||
}
|
||||
else if(motorNumber == 3)
|
||||
{
|
||||
writeOutput(PIN_MOTOR1_FORWARD, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR2_FORWARD, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_RECHTS_FORWARD, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_LINKS_FORWARD, MOTOR_ON);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,48 +36,50 @@ void reverse(int motorNumber)
|
||||
{
|
||||
if(motorNumber == 1)
|
||||
{
|
||||
writeOutput(PIN_MOTOR1_REVERSE, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_RECHTS_REVERSE, MOTOR_ON);
|
||||
}
|
||||
else if(motorNumber == 2)
|
||||
{
|
||||
writeOutput(PIN_MOTOR2_REVERSE, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_LINKS_REVERSE, MOTOR_ON);
|
||||
}
|
||||
else if(motorNumber == 3)
|
||||
{
|
||||
writeOutput(PIN_MOTOR1_REVERSE, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR2_REVERSE, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_RECHTS_REVERSE, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_LINKS_REVERSE, MOTOR_ON);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
registerOutput(PIN_MOTOR1_FORWARD);
|
||||
registerOutput(PIN_MOTOR1_REVERSE);
|
||||
registerOutput(PIN_MOTOR2_FORWARD);
|
||||
registerOutput(PIN_MOTOR2_REVERSE);
|
||||
if(strcmp(argv[1],"1")==0)
|
||||
registerOutput(PIN_MOTOR_RECHTS_FORWARD);
|
||||
registerOutput(PIN_MOTOR_RECHTS_REVERSE);
|
||||
registerOutput(PIN_MOTOR_LINKS_FORWARD);
|
||||
registerOutput(PIN_MOTOR_LINKS_REVERSE);
|
||||
if(argc > 0)
|
||||
{
|
||||
forward(1);
|
||||
if(strcmp(argv[1],"1")==0)
|
||||
{
|
||||
forward(1);
|
||||
}
|
||||
else if(strcmp(argv[1],"2")==0)
|
||||
{
|
||||
forward(2);
|
||||
}
|
||||
else if(strcmp(argv[1],"3")==0)
|
||||
{
|
||||
reverse(1);
|
||||
}
|
||||
else if(strcmp(argv[1],"4")==0)
|
||||
{
|
||||
reverse(2);
|
||||
}
|
||||
else if(strcmp(argv[1],"0")==0)
|
||||
{
|
||||
freePin(PIN_MOTOR_RECHTS_FORWARD);
|
||||
freePin(PIN_MOTOR_RECHTS_REVERSE);
|
||||
freePin(PIN_MOTOR_LINKS_FORWARD);
|
||||
freePin(PIN_MOTOR_LINKS_REVERSE);
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1],"2")==0)
|
||||
{
|
||||
forward(2);
|
||||
}
|
||||
else if(strcmp(argv[1],"3")==0)
|
||||
{
|
||||
reverse(1);
|
||||
}
|
||||
else if(strcmp(argv[1],"4")==0)
|
||||
{
|
||||
reverse(2);
|
||||
}
|
||||
else if(strcmp(argv[1],"0")==0)
|
||||
{
|
||||
freePin(PIN_MOTOR1_FORWARD);
|
||||
freePin(PIN_MOTOR1_REVERSE);
|
||||
freePin(PIN_MOTOR2_FORWARD);
|
||||
freePin(PIN_MOTOR2_REVERSE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user