-
Notifications
You must be signed in to change notification settings - Fork 1
/
audio.js
104 lines (81 loc) · 2.73 KB
/
audio.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
'use strict';
const path = require('path');
const av = require('./node_modules/tessel-av/lib/index');
const mp31 = path.join(__dirname, 'yoda-mudhole.mp3');
const mp32 = path.join(__dirname, 'baby.mp3');
const mp33 = path.join(__dirname, 'GetToDaChoppa.mp3');
const mp34 = path.join(__dirname, 'YouSonOfABitch.mp3');
const mp35 = path.join(__dirname, 'over9000.mp3');
const mp36 = path.join(__dirname, 'NotATumah.mp3');
const mp37 = path.join(__dirname, 'Stop_Whining.mp3');
const mp38 = path.join(__dirname, 'DoItNow3.mp3');
const mp311 = path.join(__dirname, 'IAmThePartyPoopah.mp3');
const mp312 = path.join(__dirname, 'sob.mp3');
const sound = new av.Player();
var tessel = require('tessel');
var rfidlib = require('rfid-pn532');
var rfid = rfidlib.use(tessel.port['A']);
rfid.on('ready', function (version) {
console.log('Ready to read RFID card');
rfid.on('data', function(card) {
var num = Math.floor(Math.random() * 9);
const mp31 = path.join(__dirname, 'yoda-mudhole.mp3');
const soundFileArray = [
mp32,
mp33,
mp34,
mp35,
mp36,
mp37,
mp38,
mp311,
mp312
]
console.log('UID:', card.uid.toString('hex'));
sound.play(soundFileArray[num], "0");
});
});
rfid.on('error', function (err) {
console.error(err);
});
var servolib = require('servo-pca9685');
var servo = servolib.use(tessel.port['B']);
var servo1 = 1; // We have a servo plugged in at position 1
servo.on('ready', function () {
var position = 0; // Target position of the servo between 0 (min) and 1 (max).
// Set the minimum and maximum duty cycle for servo 1.
// If the servo doesn't move to its full extent or stalls out
// and gets hot, try tuning these values (0.05 and 0.12).
// Moving them towards each other = less movement range
// Moving them apart = more range, more likely to stall and burn out
servo.configure(servo1, 0.05, 0.12, function () {
servo.move(servo1, 0);
setInterval(function() {
servo.move(16, 0);
setTimeout(function() {
servo.move(16, 1);
}, 500)
}, 1000)
function playSound () {
servo.move(servo1, 0.7);
setTimeout(function() {
servo.move(servo1, 0);
}, 500);
const wait = Math.floor(Math.random() * 10) + 4000;
setTimeout(function() {
playSound();
}, wait)
}
playSound();
// setInterval(function () {
// console.log('Position (in range 0-1):', position);
// // Set servo #1 to position pos.
// servo.move(servo1, position);
// // Increment by 10% (~18 deg for a normal servo)
// position += 0.1;
// if (position > 1) {
// position = 0; // Reset servo position
// }
// }, 500); // Every 500 milliseconds
});
});