Nodebots Workshop Sydney

Wilson Mendes

@willmendesneto

Google Developer Expert Web Technologies

1. Access https://goo.gl/PibUcQ

2. Decrease the price until the minimum

3. Enjoy

Nodebots book free!

So, let's start?

1. About Javascript

Chrome browser

Devtools

 

What is required?

Different examples

but

Same behaviour

...

var nodebots = 'NodeGirls + Nodebots = <3';

console.log(nodebots);
...

Variables

...

var nodebots = [
  'NodeGirls',
  '+',
  'Nodebots',
  '=',
  '<3'
];

console.log(nodebots.join(' '));
...

Array

function nodebotsMessage() {
  
  var addThisTextBetweenTheWords = ' ';
  var nodebots = [
    'NodeGirls',
    '+',
    'Nodebots',
    '=',
    '<3'
  ];

  return nodebots.join(addThisTextBetweenTheWords);
}

console.log(nodebotsMessage());

Function

Same idea + logic

=

S2

function nodebotsMessage(messageComplement) {
  
  var addThisTextBetweenTheWords = ' ';

  var nodebots = [
    'NodeGirls',
    '+',
    'Nodebots',
    '='
  ];
  
  if (messageComplement) {
    nodebots.push(messageComplement);
  }

  return nodebots.join(addThisTextBetweenTheWords);
}

console.log(nodebotsMessage('<3'));

2. About Nodebots

+

=

Workshop setup

Arduino IDE

Code editor

Command line NodeJS installed

 

What is required?

Arduino IDE

File > Examples > Firmata > StandardFirmata

Download, install and open file

Code editor

Command line

On VSCode editor: "View > Toggle Integrated Terminal"

**

NodeJS installed

https://nodejs.org/en/download/

Download NodeJS version via project website

First example: Hello world

Material

How to connect sensors

// Blink a LED
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {

  // Number of the pin connected on the board
  var pinNumbers = [12];

  // Starting the LED
  var leds = new five.Leds(pinNumbers);

  // And here is the magic! \o/
  leds.blink();
});

Let's make it

better!

click the button

turn on the lights

magic happens!

Second example

Material

+

How to connect sensors

// Blink a LED
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var pinButtons = [13];
  var buttons = new five.Buttons(pinButtons);

  buttons.on("press", function(button) {
    console.log("Pressed: ", button.pin);
  });

  buttons.on("release", function(button) {
    console.log("Released: ", button.pin);
  });
});
// Make button controls the LED
var five = require('johnny-five');
var board = new five.Board();

board.on('ready', function() {
  var leds = new five.Leds([12]);
  var buttons = new five.Buttons({
    pins: [13],
    invert: true
  });

  buttons.on('press', function(button) {
    var index = buttons.indexOf(button);
    leds[index].on();
    console.log('presssed', leds[index].pin);
  });

  buttons.on('release', function(button) {
    var index = buttons.indexOf(button);
    leds.off();
    console.log('released');
  });
});

Third example

turn on the lights + beep when​ a button is clicked

Material

How to connect sensors

// Make button controls the LED and PIEZO
var five = require('johnny-five');
var board = new five.Board();

board.on('ready', function() {
  var leds = new five.Leds([12]);
  var buttons = new five.Buttons({
    pins: [13],
    invert: true
  });
  var piezo = new five.Piezo(11);

  buttons.on('press', function(button) {
    var index = buttons.indexOf(button);
    leds[index].on();
    piezo.play({ song: 'C4' });
  });

  buttons.on('release', function(button) {
    var index = buttons.indexOf(button);
    leds[index].off();
    piezo.off();
  });
});

Now let's have fun!

Simon game

Be calm, ok?

Material

Yes, they are the same as the third example

**

How to connect sensors

Download the main template for our Simon Game


board.on('ready', function() {

  leds = new five.Leds([12, 3]);
  var buttons = new five.Buttons([13, 2]);
  piezo = new five.Piezo(11);

  buttons.on('press', function(button) {
    var index = buttons.indexOf(button);
    leds[index].on();
    piezo.play({ song: piezoSongs[index] });
    console.log('Pressed: button', button.pin);
  });

  // Starting the game
  startGame();
  ...
});
  ...
  buttons.on('release', function(button) {
    var index = buttons.indexOf(button);

    console.log('Released: button', button.pin);

    leds.off();
    piezo.off();
    ...
  });
  ...

Where ​can I find these examples?

reminder

reminder

reminder

1. Access https://goo.gl/PibUcQ

2. Decrease the price until the minimum

3. Enjoy

Nodebots book free!

Thank you!

#thanksMate

#gracias

#obrigado

Wilson Mendes

@willmendesneto

Nodebots Workshop

By willmendesneto

Nodebots Workshop

  • 1,917
Loading comments...

More from willmendesneto