Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function writeToScreen(screen, message) {
screen.setCursor(0,0);
screen.write(message);
}
function postDataNow() {
// Build the post string from an object
var post_data = {
'device': 'edison',
'devs': 'Troy Anderson & Desiree Salgado',
'message' : 'Hi from Edison - we pushed a button!'
};
var postData = JSON.stringify(post_data);
var chatMessage = JSON.stringify({'text': "Hey, I'm on the internet!"});
// An object of options to indicate where to post to
var post_options = {
host: 'cfdevicejam.azure-mobile.net',
port: '80',
path: '/tables/checkins',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postData.length
}
};
// An object of options to indicate where to post to
var postChatRoomOptions = {
host: 'hooks.slack.com',
port: '443',
path: '/services/STUFF_HERE',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': postData.length
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
var postRoom = http.request(postChatRoomOptions, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('Response: ' + chunk);
});
});
console.log("trying to post...");
// post the data
//postRoom.write(chatMessage);
post_req.write(postData);
post_req.end();
}
var cylon = require('cylon');
var querystring = require('querystring');
var http = require('http');
var words = ["Hola","Hello","How are you?","Como estas?","have a nice day!! :)","Que tenga un buen dia!! ;)","Life is good!","La buena vida!", "Good luck", "Buena suerte" ];
cylon.robot({
connection: { name: 'edison', adaptor: 'intel-iot' },
device: [
{ name: 'led', driver: 'led', pin: 4, connection: 'edison' },
{ name: 'touch', driver: 'button', pin: 3, connection: 'edison' },
{ name: 'screen', driver: 'upm-jhd1313m1', connection: 'edison' },
{ name: 'servo', driver: 'servo', pin: 2 }
]
})
.on('ready', function(my) {
writeToScreen(my.screen, "Ready!");
var angle = 45 ;
my.servo.angle(angle);
every((1).second(), function() {
angle = angle + 45 ;
if (angle > 135) {
angle = 45
}
my.servo.angle(angle);
});
my.touch.on('press', function() {
my.led.turnOn();
//writeToScreen(my.screen, "Hola!");
console.log("starting");
//postDataNow();
var word = words[Math.floor(Math.random()*words.length)];
writeToScreen(my.screen, word);
});
my.touch.on('release', function() {
my.led.turnOff();
writeToScreen(my.screen, " ");
});
})
.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.