-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
101 lines (89 loc) · 3.23 KB
/
main.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
var twitter = require('mtwitter');
var colors = require('colors');
var moment = require('moment');
var newMessage = false;
var lastTweet = '21:35:5';
var twit = new twitter({
consumer_key : 'xxxxx',
consumer_secret : 'xxx',
access_token_key : 'xxx',
access_token_secret : 'xxxx'
});
var mraa = require('mraa'); //require mraa
console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the Intel XDK console
var RedLED = new mraa.Gpio(5);
RedLED.dir(mraa.DIR_OUT); //set the gpio direction to output
var GreenLED = new mraa.Gpio(6);
GreenLED.dir(mraa.DIR_OUT); //set the gpio direction to output
var BlueLED = new mraa.Gpio(7);
BlueLED.dir(mraa.DIR_OUT);
var Buzzer = new mraa.Gpio(4);
Buzzer.dir(mraa.DIR_OUT);
console.log('Starting'.cyan);
setInterval(function() {
twit.get('search/tweets', {q: '#iothackpdx'}, function(err, item) {
if(item != null && item !== undefined) {
console.log(item)
console.log(item.statuses[0].created_at.substring(11, 18).cyan);
console.log(lastTweet);
console.log("From isNew(): ", newMessage);
if(item.statuses[0].created_at.substring(11, 18) === lastTweet) {
console.log("Not a new tweet. Not Lighting things up");
newMessage = false;
}
else{
newMessage = true
console.log("New tweet. Lighting things up");
lightUpThings(true);
lastTweet = item.statuses[0].created_at.substring(11, 18);
}
}
});
}, 30000);
function lightUpThings(flag){
console.log("I am ready to light up");
var totalLEDs = 3; // total number of LEDs
var totalRounds = 1; // total rounds of LED lights blinking
var totalLEDLightBlinks = totalLEDs * totalRounds;
var seconds = 1; // number of seconds we want to pause
var pauseTime = 1000 * seconds; // number of milliseconds to pause
// Blink each LED light: Green, Red, and Blue, one after another
// in each round, for the total number of rounds specified in totalRounds
// For a grand total of totalLEDLightBlinks
// Pause for pauseTime between transitions
var i = 0;
var round = 1;
var waiting = setInterval(function() {
if (i == totalLEDLightBlinks)
{
console.log("Rounds complete");
GreenLED.write(0);
RedLED.write(0);
BlueLED.write(0);
Buzzer.write(0);
clearInterval(waiting);
}
else if (i % totalLEDs == 0)
{
console.log("Round number: " + round);
GreenLED.write(1);
Buzzer.write(1);
RedLED.write(0);
BlueLED.write(0);
round++;
}
else if (i % totalLEDs == 1)
{
GreenLED.write(0);
RedLED.write(1);
BlueLED.write(0);
}
else // i % totalLEDs == 2
{
GreenLED.write(0);
RedLED.write(0);
BlueLED.write(1);
}
i++;
}, pauseTime);
}