I'm very new at this C# programming , so I'm asking for some help.
The program itself is mainly a copy of some other DC motor controlling program, but seems to be working. When I control the motor directly from Serial monitor it's working just fine, but when I plug in my bluetooth and try, nothing happens. I know that the bluetooth connection is working, because I tested it with a simple LED ON, LED OFF program.
#include <Stepper.h>
int in1Pin = 8; // C0
int in2Pin = 12; // C1
int in3Pin = 13; // C2
int in4Pin = 14; // C3
int state;
int flag=0;
Stepper motor(200, in1Pin, in2Pin, in3Pin, in4Pin);
void setup()
{// Pins=Outputs
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
Serial.begin(9600); //Initialize serial communication at 9600 bits/s
motor.setSpeed(2); //set motor speed
}
void loop()
{
//if some date is sent, reads it and saves in state
if (Serial.available() > 0)
{
state = Serial.read();
flag=0;
}
// if the state is '0' the DC motor will turn off
if (state == '0')
{
int steps = 0; //number of steps
motor.step(steps);
if(flag == 0)
{
Serial.println("Motor: off");
flag=1;
}
}
// if the state is '1' the motor go forwards
else if (state == '1')
{
int steps = 5; //number of steps
motor.step(steps);
if(flag == 0)
{
Serial.println("Motor: Forward");
flag=1;
}
}
// if the state is '2' the motor will turn left
else if (state == '2')
{
int steps = -5;
motor.step(steps);
if(flag == 0)
{
Serial.println("Motor: Backwards");
flag=1;
}
}
}
and here is the program for android