-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestLearn.21.ino
70 lines (58 loc) · 1.21 KB
/
TestLearn.21.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Arduino.h"
#define PIN_MOTOR1_DIR_A 38
#define PIN_MOTOR1_PWR 12
#define PIN_MOTOR1_DIR_B 40
void setup()
{
pinMode(PIN_MOTOR1_DIR_A, OUTPUT);
pinMode(PIN_MOTOR1_DIR_B,OUTPUT);
pinMode(PIN_MOTOR1_PWR,OUTPUT);
}
void loop()
{
for (int i = -255; i < 255; i++)
{
motorAn(i);
delay(10);
}
for (int i = 255; i > -255; i--)
{
motorAn(i);
delay(10);
}
// void loop()
// {
// digitalWrite (pinDirA1,HIGH);
// digitalWrite (40,LOW);
// for (int a = 0; a < 256; a++)
// {
// analogWrite(12,a);
// delay(20);
// }
// for (int i = 255; i >= 0; i--)
// {
// analogWrite(12,i);
// delay(20);
// }
}
void motorAn(int power)
{
if (power<0)
{
digitalWrite (PIN_MOTOR1_DIR_A, LOW);
digitalWrite (PIN_MOTOR1_DIR_B,HIGH);
power = -power;
}
else
{
digitalWrite (PIN_MOTOR1_DIR_A, HIGH);
digitalWrite (PIN_MOTOR1_DIR_B,LOW);
}
analogWrite (PIN_MOTOR1_PWR,power);
}
void motorAus()
{
digitalWrite (PIN_MOTOR1_DIR_A, LOW);
digitalWrite (PIN_MOTOR1_DIR_B,LOW);
digitalWrite (PIN_MOTOR1_PWR,LOW);
}