int ENA=2;
int IN1=3;
int IN2=4;
int IN3=5;
int IN4=6;
int ENB=7;
int timer = 50; // The higher the number, the slower the timing.
int ledPins[] = {
IN1,IN2,IN3,IN4
}; // an array of pin numbers to which LEDs are attached
int pinCount = 4; // the number of pins (i.e. the length of the array)
SoftwareSerial mySerial(10,11); // TX, RX
//RX on Bluetooth to TCX on Arduino through a voltage divider 50ohm from arduino and 100ohm to ground. This is so we can drop the the voltage down to 3.3v (roughly)
while (!mySerial.available()); // stay here so long as COM port is empty
receivedChar = mySerial.read();
switch(receivedChar)
{
case 'A':
digitalWrite(ENA,HIGH);
digitalWrite(ENB,HIGH);// High is start driving car
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(50);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(50);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(20);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
step1:
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(100);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(10);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(10);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(200);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(200);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
goto step1;
}
break;
default:
digitalWrite(ENA,HIGH);
digitalWrite(ENB,HIGH);// High is start driving car
//RX on Bluetooth to TCX on Arduino through a voltage divider 50ohm from arduino and 100ohm to ground. This is so we can drop the the voltage down to 3.3v (roughly)
// Use blueterm on android to get messages
void setup()
{
pinMode(ENA,OUTPUT);//output
pinMode(ENB,OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
pinMode(ENA1,OUTPUT);//output
pinMode(ENB1,OUTPUT);
pinMode(IN11,OUTPUT);
pinMode(IN12,OUTPUT);
pinMode(IN13,OUTPUT);
pinMode(IN14,OUTPUT);
mySerial.begin(9600);
}
void loop() // run over and over
{
while (!mySerial.available()); // stay here so long as COM port is empty
receivedChar = mySerial.read();
if (receivedChar == 'A') {
//digitalWrite(ENA,LOW);
// digitalWrite(ENB,LOW);// High is start driving car
digitalWrite(ENA,HIGH);
digitalWrite(ENB,HIGH);// High is start driving car