DC Motor Test - PWM
int ledPin = 13; // LED connected to digital pin 13int h=1;
int h = 1;
int h2=0;
int h3=0;
int h4=0;
int h5=0;
int h6=0; // direction memory motor 1
int h7=0; // direction memory motor 2
void setup() // run once, when the sketch starts
{
pinMode(4, OUTPUT); // pwm motor 1
pinMode(6, OUTPUT); // pwm motor 2
pinMode(5, OUTPUT); // direction motor 1
pinMode(7, OUTPUT); // direction motor 2
pinMode(13, OUTPUT); // PWM INDICATOR LED
pinMode(2, INPUT); // direction motor 1 - input test switch
pinMode(3, INPUT); // direction motor 2 - input test switch
digitalWrite(4, LOW); // motor 1 off
digitalWrite(6, LOW); // motor 2 off
digitalWrite(5, LOW); // motor 1 direction L - low
digitalWrite(7, LOW); // motor 2 direction L - low
}
void loop() // run over and over again
{
h5 = digitalRead(2); // motor 1 direction
if (h5!=h6)
{
h6=h5;
digitalWrite(4, LOW); // motor 1 pwm low - stop
delay(1000);
digitalWrite(5, h5); //
delay(1000);
}
h5 = digitalRead(3); // motor 2 direction
if (h5!=h7)
{
h7=h5;
digitalWrite(6, LOW); // motor 2 pwm low - stop
delay(1000);
digitalWrite(7, h5); //
delay(1000);
}
digitalWrite(4, HIGH); // motor 1 2 pwm high
digitalWrite(6, HIGH); //
digitalWrite(13, HIGH); //
h5 = analogRead(0); // read the value from the sensor
while(h5>0){
h2 = analogRead(0); // read the value from the sensor
while(h2>0){
h2--;
}
h5--;
}
digitalWrite(4, LOW); // motor 1 2 pwm low
digitalWrite(6, LOW); //
digitalWrite(13, LOW); //
h4 = analogRead(1)*2; // read the value from the sensor
while(h4>0){
h3 = analogRead(1); // read the value from the sensor
while(h3>0){
h3--;
}
h4--;
}
}
DC Motor Test - PWM
int ledPin = 13; // LED connected to digital pin 13int h=1;
int h = 1;
int h2=0;
int h3=0;
int h4=0;
int h5=0;
int h6=0; // direction memory motor 1
int h7=0; // direction memory motor 2
void setup() // run once, when the sketch starts
{
pinMode(4, OUTPUT); // pwm motor 1
pinMode(6, OUTPUT); // pwm motor 2
pinMode(5, OUTPUT); // direction motor 1
pinMode(7, OUTPUT); // direction motor 2
pinMode(13, OUTPUT); // PWM INDICATOR LED
pinMode(2, INPUT); // direction motor 1 - input test switch
pinMode(3, INPUT); // direction motor 2 - input test switch
digitalWrite(4, LOW); // motor 1 off
digitalWrite(6, LOW); // motor 2 off
digitalWrite(5, LOW); // motor 1 direction L - low
digitalWrite(7, LOW); // motor 2 direction L - low
}
void loop() // run over and over again
{
h5 = digitalRead(2); // motor 1 direction
if (h5!=h6)
{
h6=h5;
digitalWrite(4, LOW); // motor 1 pwm low - stop
delay(1000);
digitalWrite(5, h5); //
delay(1000);
}
h5 = digitalRead(3); // motor 2 direction
if (h5!=h7)
{
h7=h5;
digitalWrite(6, LOW); // motor 2 pwm low - stop
delay(1000);
digitalWrite(7, h5); //
delay(1000);
}
digitalWrite(4, HIGH); // motor 1 2 pwm high
digitalWrite(6, HIGH); //
digitalWrite(13, HIGH); //
h5 = analogRead(0); // read the value from the sensor
while(h5>0){
h2 = analogRead(0); // read the value from the sensor
while(h2>0){
h2--;
}
h5--;
}
digitalWrite(4, LOW); // motor 1 2 pwm low
digitalWrite(6, LOW); //
digitalWrite(13, LOW); //
h4 = analogRead(1)*2; // read the value from the sensor
while(h4>0){
h3 = analogRead(1); // read the value from the sensor
while(h3>0){
h3--;
}
h4--;
}
}