-
Notifications
You must be signed in to change notification settings - Fork 0
/
C1_PWM.ino
78 lines (62 loc) · 1.36 KB
/
C1_PWM.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
71
72
73
74
75
76
77
78
/// Motor A connections
//one fourth
int enA = 3;
int in1 = 4;
int in2 = 5;
// Motor B connections
int enB = 9;
int in3 = 6;
int in4 = 7;
int num=0;
//int fibo[10]={0,1,1,2,3,5,8,13,21,34};
int fibo[2]={3,8};
//int sca_fibo[10];
int sca_fibo[2] = {200,250};
void setup() {
// Set all the motor control pins to outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
analogWrite(enA, 0);
analogWrite(enB, 0);
// int i;
// for(i=0;i<2;i++)
// sca_fibo[i]=map(fibo[i],0,8,0,255);
}
void loop() {
// lightControl();
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
analogWrite(enA, 50);
analogWrite(enB, 50);
delay(2000);
analogWrite(enA, 200);
analogWrite(enB, 200);
delay(2000);
}
void lightControl() {
// Set motors to maximum speed
// For PWM maximum possible values are 0 to 255
analogWrite(enA, sca_fibo[num]);
analogWrite(enB, sca_fibo[num]);
num++;
// if(num==10)
if(num==2)
num=0;
// Turn on motor A & B
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);
}