-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgestured_controlled_motor.ino
108 lines (99 loc) · 2.1 KB
/
gestured_controlled_motor.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// include the library code:
#include <LiquidCrystal.h>
int f1 = 0;
int f2 = 1;
int f3 = 2;
int f4 = 3;
int f5 = 4;
int val1;
int val2;
int val3;
int val4;
int val5;
int motor1 = 6;
int motor2 = 9;
int valm1;
int valm2;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
lcd.print("Gesture controlled");
}
void loop() {
val1 = analogRead(f1);
val2 = analogRead(f2);
val3 = analogRead(f3);
val4 = analogRead(f4);
val5 = analogRead(f5);
//Serial.println(val1);
Serial.println(val2);
//Serial.println(val3);
//Serial.println(val4);
//Serial.println(val5);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
if (val1<7){
lcd.print("o");
}
else {
lcd.print("I");
}
lcd.setCursor(1, 1);
// print the number of seconds since reset:
if (val2<7){
lcd.print("o");
}
else {
lcd.print("I");
}
lcd.setCursor(2, 1);
// print the number of seconds since reset:
if (val3<7){
lcd.print("o");
}
else {
lcd.print("I");
}
lcd.setCursor(3, 1);
// print the number of seconds since reset:
if (val4<7){
lcd.print("o");
}
else {
lcd.print("I");
}
lcd.setCursor(4, 1);
// print the number of seconds since reset:
if (val5<7){
lcd.print("o");
}
else {
lcd.print("I");
}
if (val1<7){
int speed = (12-val2); //Receive Value from serial monitor
valm1 = map(speed, 0, 12, 0, 255);
analogWrite(motor1, valm1);
analogWrite(motor2, 0);
Serial.println("valm1");
Serial.println(valm1);
Serial.print(" ");
}
else {
int speed = (12-val2); //Receive Value from serial monitor
valm1 = map(speed, 0, 12, 0, 255);
analogWrite(motor1, 0);
analogWrite(motor2, valm1);
Serial.println("valm1");
Serial.println(valm1);
Serial.print(" ");
}
}