-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.js
175 lines (137 loc) · 4.18 KB
/
func.js
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
var Gpio = require('pigpio').Gpio, //include pigpio to interact with the GPIO
ledRed = new Gpio(4, {mode: Gpio.OUTPUT}), //use GPIO pin 4 as output for RED
ledGreen = new Gpio(17, {mode: Gpio.OUTPUT}), //use GPIO pin 17 as output for GREEN
ledBlue = new Gpio(27, {mode: Gpio.OUTPUT}), //use GPIO pin 27 as output for BLUE
redRGB = 255, //set starting value of RED variable to off (255 for common anode)
greenRGB = 255, //set starting value of GREEN variable to off (255 for common anode)
blueRGB = 255; //set starting value of BLUE variable to off (255 for common anode)
//RESET RGB LED
ledRed.digitalWrite(1); // Turn RED LED off
ledGreen.digitalWrite(1); // Turn GREEN LED off
ledBlue.digitalWrite(1); // Turn BLUE LED off
//
const motor_onoff = new Gpio(18, {mode: Gpio.OUTPUT});
const motor_left = new Gpio(19, {mode: Gpio.OUTPUT});
const motor_right = new Gpio(26, {mode: Gpio.OUTPUT});
// 스피커기능
var player = require('play-sound')(opts = {})
// 주요 기능들에 따른 함수를 호출할 예정입니다.
exports.onLed = function main( argument1 ) {
// led
// Do Something
if( argument1 === 'on'){ //스피커 ON
/* a~g까지 알파벳들을 입력받아서 */
console.log("mainfunc");
ledRed.pwmWrite(redRGB); //set RED LED to specified value
ledGreen.pwmWrite(greenRGB); //set GREEN LED to specified value
ledBlue.pwmWrite(blueRGB); //set BLUE LED to specified value
return 1;
}
if( argument1 === 'off'){ //스피커 ON
/* a~g까지 알파벳들을 입력받아서 */
console.log("mainfunc");
ledRed.digitalWrite(1); // Turn RED LED off
ledGreen.digitalWrite(1); // Turn GREEN LED off
ledBlue.digitalWrite(1); // Turn BLUE LED off
return 1;
}
}
var audio
exports.onSpeaker = function main2 (argument1,audio){
if( argument1 === 'stop'){ //스피커 OFF
audio.kill()
}
else if( argument1 === 'start1'){
audio = player.play('./sound_file/a.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start2'){
audio = player.play('./sound_file/b.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start3'){
audio = player.play('./sound_file/c.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start4'){
audio = player.play('./sound_file/d.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start5'){
audio = player.play('./sound_file/e.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start6'){
audio = player.play('./sound_file/f.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start7'){
audio = player.play('./sound_file/g.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start8'){
audio = player.play('./sound_file/h.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start9'){
audio = player.play('./sound_file/i.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'start10'){
audio = player.play('./sound_file/j.mp3', function(err){
if (err) throw err
})
return audio
}
}
exports.onMotor = function main3 (argument1, audio){
if( argument1 === 'motor off'){ //모터 OFF
motor_onoff.pwmWrite(0);
motor_right.pwmWrite(0);
motor_left.pwmWrite(0);
if(audio != null)
audio.kill()
}
else if( argument1 === 'motor right'){
motor_onoff.pwmWrite(255);
motor_right.pwmWrite(255);
motor_left.pwmWrite(0);
if(audio != null){
audio.kill()
}
audio = player.play('./sound_file/i.mp3', function(err){
if (err) throw err
})
return audio
}
else if( argument1 === 'motor left'){
motor_onoff.pwmWrite(255);
motor_right.pwmWrite(0);
motor_left.pwmWrite(255);
if(audio != null){
audio.kill()
}
audio = player.play('./sound_file/h.mp3', function(err){
if (err) throw err
})
return audio
}
}