Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#define AIA 5 //mandroso
#define AIB 6 //mihemotra
#define BIA 8 //havia
#define BIB 7 //havanana
#define MS 12 // mijanona ny moteur direction
#define JI 10 // jiro
#define KX 9 //klaxon
char vertical; //mandroso sa mihemotra
char horizontal; //havia sa havanana
int ds = 0; //direction state
byte speed = 130;
char cmd; // incoming data
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(AIA, OUTPUT);
pinMode(AIB, OUTPUT);
pinMode(BIA, OUTPUT);
pinMode(BIB, OUTPUT);
pinMode(MS, INPUT);
pinMode(JI, OUTPUT);
digitalWrite(AIA, LOW);
digitalWrite(AIB, LOW);
analogWrite(BIA, 0);
analogWrite(BIA, 0);
digitalWrite(JI, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0)
{
cmd = Serial.read();
switch (cmd)
{
case 'F':
digitalWrite(AIA, HIGH);
break;
case 'B':
digitalWrite(AIB, HIGH);
break;
case 'L':
analogWrite(BIA, 0);
analogWrite(BIB, speed);
break;
case 'R':
analogWrite(BIA, speed);
analogWrite(BIB, 0);
break;
case 'G':
digitalWrite(AIA, HIGH);
analogWrite(BIA, 0);
analogWrite(BIB, speed);
break;
case 'I':
digitalWrite(AIA, HIGH);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
break;
case 'H':
digitalWrite(AIB, HIGH);
analogWrite(BIA, 0);
analogWrite(BIB, speed);
break;
case 'J':
digitalWrite(AIB, HIGH);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
break;
default:
digitalWrite(AIA, LOW);
digitalWrite(AIB, LOW);
analogWrite(BIA, 0);
analogWrite(BIB, 0);
break;
}
if(cmd == 'W')
{
digitalWrite(JI, HIGH);
Serial.println("Jiro ok");
}
if(cmd == 'w')
{
digitalWrite(JI, LOW);
}
if(cmd == 'V')
{
tone(KX, 1000);
}
if(cmd == 'v')
{
noTone(KX);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.