Skip to content

Commit cb0f766

Browse files
author
Stewest
committed
Git init
1 parent 441021f commit cb0f766

File tree

8 files changed

+893
-1
lines changed

8 files changed

+893
-1
lines changed

Diff for: .DS_Store

6 KB
Binary file not shown.

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gitignore.DS_Store
2+
.nyc_output
3+
node_modules
4+
npm-debug.log
5+
wip/
6+
release
7+
coverage
8+
.env

Diff for: .nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Stew West
3+
Copyright (c) 2017 Stew West
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# johnny-five-node-slackbot
2+
A NodeJS Arduino integration with SlackBot.
3+
4+
I wanted to make my Arduino flash certain green or red LEDs, triggered via our deploy's success or failure slack messages.
5+
6+
Creating a Mashup of:
7+
8+
https://github.com/rwaldron/johnny-five
9+
- The JavaScript Robotics Programming Framework
10+
11+
https://github.com/rmcdaniel/node-slackbot
12+
- Slackbot for node.js using RTM API.
13+
14+
As mentioned here: http://lightningtalks.me/simple-slack-of-things-nodejsslackarduino/
15+
16+
What to do:
17+
18+
From https://github.com/rwaldron/johnny-five#setup-and-assemble-arduino
19+
- Download Arduino IDE
20+
- Plug in your Arduino or Arduino compatible microcontroller via USB
21+
- Open the Arduino IDE, select: File > Examples > Firmata > StandardFirmataPlus
22+
-- StandardFirmataPlus is available in Firmata v2.5.0 or greater
23+
- Click the "Upload" button.
24+
25+
If the upload was successful, the board is now prepared and you can close the Arduino IDE.
26+
27+
Then from this repo:
28+
- npm install
29+
- Go to https://api.slack.com/slack-apps and create your app with testing tokens.
30+
- Create and Add SLACK_TOKEN to .env file
31+
-- Like SLACK_TOKEN='xxxxxxx0000000xxxxxxx00000000000.....'
32+
33+
Run:
34+
- node slackbot-app.js
35+
36+
If you haven't Added in your Slack Token, you'll probably see this error:
37+
38+
"Uncaught TypeError: Parameter "url" must be a string, not undefined:
39+
40+
Check your Slack token, it may be missing or needs replacing. https://api.slack.com/custom-integrations/legacy-tokens (As Slacbkbot uses the old RTM tokens)

Diff for: ardi-app.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require('dotenv').config();
2+
// const token = process.env['SLACK_TOKEN'];
3+
// const userToken = process.env['SLACK_USER'];
4+
5+
const five = require("johnny-five");
6+
const board = new five.Board();
7+
8+
board.on("ready", function() {
9+
// I've put 3 separate LEDs on Digital pins 3 Blue, 5 Green, 6 Red.
10+
// And a rgb LED, controlled by 9, 10 , 11.
11+
const rgb = new five.Led.RGB([9, 10, 11]);
12+
13+
// Create a new `photoresistor` hardware instance on Analog 2.
14+
const photoresistor = new five.Sensor({
15+
pin: "A2",
16+
freq: 5000
17+
});
18+
19+
// Inject the `sensor` hardware into
20+
// the Repl instance's context;
21+
// allows direct command line access
22+
board.repl.inject({
23+
pot: photoresistor
24+
});
25+
26+
// "data" get the current reading from the photoresistor
27+
photoresistor.on("data", () => {
28+
console.log(photoresistor.value);
29+
});
30+
31+
let index = 0;
32+
const rainbow = ["FF0000", "FF7F00", "FFFF00", "00FF00", "0000FF", "4B0082", "8F00FF"];
33+
const rgbOn = new five.Leds([12]);
34+
const array = new five.Leds([3, 5, 6]);
35+
const blue = new five.Leds([3]);
36+
const green = new five.Leds([5]);
37+
const red = new five.Leds([6]);
38+
const deployComplete = new five.Leds([3, 5]);
39+
40+
const rainbox = function () {
41+
rgbOn.on();
42+
43+
board.loop(250, () => {
44+
rgb.color(rainbow[index++]);
45+
if (index === rainbow.length) {
46+
index = 0;
47+
}
48+
});
49+
50+
setTimeout(() => {
51+
rgbOn.off();
52+
}, 5000);
53+
console.log('Ended Rainbow');
54+
}
55+
56+
/**
57+
*
58+
* @param {*} colour
59+
* usage example: pulseLed(green);
60+
*/
61+
const pulseLed = function (colour) {
62+
colour.pulse();
63+
64+
setTimeout(function () {
65+
colour.stop().off();
66+
}, 5000);
67+
}
68+
69+
// Turn on Rainbow.
70+
// To turn off: array.stop().off();
71+
rainbox();
72+
73+
pulseLed(array);
74+
});

0 commit comments

Comments
 (0)