[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:10.00,Default,,0000,0000,0000,,[MUSIC] Dialogue: 0,0:00:12.48,0:00:16.14,Default,,0000,0000,0000,,Hi everyone, my name is Patrick, and I'm a\Nweb developer from Sydney. Dialogue: 0,0:00:16.14,0:00:21.14,Default,,0000,0000,0000,,I've recently been looking into using\NJavaScript to control devices such as Dialogue: 0,0:00:21.14,0:00:24.07,Default,,0000,0000,0000,,Arduinos, the Elite Emotion, Ninja Blocks Dialogue: 0,0:00:24.07,0:00:27.09,Default,,0000,0000,0000,,and hopefully very soon this, Pebble\Nwatch. Dialogue: 0,0:00:28.88,0:00:31.46,Default,,0000,0000,0000,,Today I'm gonna be going over the Dialogue: 0,0:00:31.46,0:00:35.86,Default,,0000,0000,0000,,absolute basics of controlling an Arduino\Nusing Node. Dialogue: 0,0:00:35.86,0:00:37.65,Default,,0000,0000,0000,,We're gonna cover connecting up to a Dialogue: 0,0:00:37.65,0:00:40.07,Default,,0000,0000,0000,,computer, getting Node to communicate with\Nthe Dialogue: 0,0:00:40.07,0:00:44.70,Default,,0000,0000,0000,,Arduino, and hopefully, by the very end,\Nblinking this LED light on and off. Dialogue: 0,0:00:46.02,0:00:48.77,Default,,0000,0000,0000,,I'll be sticking to absolute basics here,\Nso we're Dialogue: 0,0:00:48.77,0:00:51.60,Default,,0000,0000,0000,,not going to be doing anything too\Nadvanced, hopefully. Dialogue: 0,0:00:51.60,0:00:54.88,Default,,0000,0000,0000,,In future tutorials, I'll go over this and\Nit gets a little bit more complicated. Dialogue: 0,0:00:54.88,0:00:58.61,Default,,0000,0000,0000,,But, for this one, we're gonna show you\Nhow to get started. Dialogue: 0,0:00:58.61,0:01:01.60,Default,,0000,0000,0000,,So, let's do that and get started. Dialogue: 0,0:01:01.60,0:01:02.58,Default,,0000,0000,0000,,What is an Arduino? Dialogue: 0,0:01:02.58,0:01:05.57,Default,,0000,0000,0000,,A lot of people have read the name online,\Nor they've heard it Dialogue: 0,0:01:05.57,0:01:08.79,Default,,0000,0000,0000,,mentioned, but they've never actually seen\None in action, so this is it. Dialogue: 0,0:01:09.81,0:01:12.29,Default,,0000,0000,0000,,It's a single board micro-controller\Nthat's Dialogue: 0,0:01:12.29,0:01:15.13,Default,,0000,0000,0000,,open source which basically means that you Dialogue: 0,0:01:15.13,0:01:19.19,Default,,0000,0000,0000,,can control electronics using a platform\Nthat anyone can build and tinker with. Dialogue: 0,0:01:19.19,0:01:23.57,Default,,0000,0000,0000,,The people at Arduino are lovely enough to\Nhave open sourced it, which Dialogue: 0,0:01:23.57,0:01:26.98,Default,,0000,0000,0000,,means that anybody can make their own\NArduino boards that really want to. Dialogue: 0,0:01:28.18,0:01:30.88,Default,,0000,0000,0000,,This one here, in particular, is the\NArduino Uno. Dialogue: 0,0:01:30.88,0:01:33.59,Default,,0000,0000,0000,,It's one of a variety, of different models Dialogue: 0,0:01:33.59,0:01:35.75,Default,,0000,0000,0000,,that the lovely people at Arduino have\Nreleased. Dialogue: 0,0:01:37.09,0:01:38.52,Default,,0000,0000,0000,,You can have a whole range of components Dialogue: 0,0:01:38.52,0:01:41.90,Default,,0000,0000,0000,,connected to it, too, like LED light\Nbulbs, sensors, Dialogue: 0,0:01:41.90,0:01:44.90,Default,,0000,0000,0000,,and even shields, which are things you\Nkind of Dialogue: 0,0:01:44.90,0:01:48.11,Default,,0000,0000,0000,,stack on top of Arduinos to add more\Nfunctionality. Dialogue: 0,0:01:48.11,0:01:51.34,Default,,0000,0000,0000,,This one in particular is a MIDI, shield\Nwhich has Dialogue: 0,0:01:51.34,0:01:54.43,Default,,0000,0000,0000,,the ability for, to play sounds, like a\NMIDI Keyboard does. Dialogue: 0,0:01:54.43,0:01:56.61,Default,,0000,0000,0000,, Dialogue: 0,0:01:56.61,0:01:58.74,Default,,0000,0000,0000,,Node.js is a platform that takes Dialogue: 0,0:01:58.74,0:02:01.55,Default,,0000,0000,0000,,JavaScripts, a scripting language most\Ncommonly used Dialogue: 0,0:02:01.55,0:02:05.71,Default,,0000,0000,0000,,for web pages, unless you're writing up\Nnetwork applications such as web servers. Dialogue: 0,0:02:07.17,0:02:11.78,Default,,0000,0000,0000,,We'll be using it today, to run a web\Nserver that'll talk to our Aduino. Dialogue: 0,0:02:12.90,0:02:16.99,Default,,0000,0000,0000,,If you haven't used Node.js before, get\Nstarted by Dialogue: 0,0:02:16.99,0:02:19.80,Default,,0000,0000,0000,,heading over to Node.js.org, which I'm\Nshowing on screen here. Dialogue: 0,0:02:20.88,0:02:22.57,Default,,0000,0000,0000,,Click that Install button and get it\Ninstalled Dialogue: 0,0:02:22.57,0:02:24.17,Default,,0000,0000,0000,,and running on your computer, so that\Nyou'll Dialogue: 0,0:02:24.17,0:02:28.29,Default,,0000,0000,0000,,be able to continue and follow along with\Nthe example code that I'll be putting up. Dialogue: 0,0:02:28.29,0:02:30.37,Default,,0000,0000,0000,,[BLANK_AUDIO] Dialogue: 0,0:02:30.37,0:02:32.41,Default,,0000,0000,0000,,So why Node.js and Arduinos? Dialogue: 0,0:02:32.41,0:02:34.16,Default,,0000,0000,0000,,Why link these two technologies together? Dialogue: 0,0:02:35.38,0:02:38.77,Default,,0000,0000,0000,,Well, one of the strengths of JavaScript\Nis that there are quite a few APIs Dialogue: 0,0:02:38.77,0:02:42.36,Default,,0000,0000,0000,,out there, which you can join in different\Nways to make ideas come to life. Dialogue: 0,0:02:43.91,0:02:45.60,Default,,0000,0000,0000,,Want to develop a robot that takes Dialogue: 0,0:02:45.60,0:02:48.06,Default,,0000,0000,0000,,instructions from your Twitter followers,\Nor a Dialogue: 0,0:02:48.06,0:02:49.69,Default,,0000,0000,0000,,coffee machine that makes you a different Dialogue: 0,0:02:49.69,0:02:51.43,Default,,0000,0000,0000,,style of coffee, depending on the weather\Noutside? Dialogue: 0,0:02:52.72,0:02:55.78,Default,,0000,0000,0000,,If you want to add a Leap Motion as an\Ninput Dialogue: 0,0:02:55.78,0:03:01.23,Default,,0000,0000,0000,,device, or feed in data from your Jawbone\Nor FitBit fitness products. Dialogue: 0,0:03:01.23,0:03:02.76,Default,,0000,0000,0000,,The possibilities are going all the time. Dialogue: 0,0:03:02.76,0:03:05.38,Default,,0000,0000,0000,,And JavaScript is becoming an easy to use\Nbridge between technologies, Dialogue: 0,0:03:05.38,0:03:07.52,Default,,0000,0000,0000,,because we've got a whole bunch of APIs\Nwe've got access to. Dialogue: 0,0:03:09.05,0:03:10.36,Default,,0000,0000,0000,,And what is Johnny-Five? Dialogue: 0,0:03:10.36,0:03:14.25,Default,,0000,0000,0000,,Johnny-Five, is one of those open APIs\Nthat makes JavaScript such Dialogue: 0,0:03:14.25,0:03:17.15,Default,,0000,0000,0000,,a valuable language to be developing this\Nsort of thing in. Dialogue: 0,0:03:18.18,0:03:20.19,Default,,0000,0000,0000,,It allows you to control your Arduino\Nusing Dialogue: 0,0:03:20.19,0:03:22.46,Default,,0000,0000,0000,,very similar functions to those that you'd\Nuse Dialogue: 0,0:03:22.46,0:03:24.56,Default,,0000,0000,0000,,if you were programming it just using the Dialogue: 0,0:03:24.56,0:03:28.18,Default,,0000,0000,0000,,Arduino platform that comes with the\NArduino itself. Dialogue: 0,0:03:31.44,0:03:32.98,Default,,0000,0000,0000,,We'll be doing a lot of this stuff in the Dialogue: 0,0:03:32.98,0:03:36.59,Default,,0000,0000,0000,,tutorial that it's explaining here, so\Ndon't worry too much. Dialogue: 0,0:03:36.59,0:03:37.72,Default,,0000,0000,0000,,But you can see, there's a lot of cool Dialogue: 0,0:03:37.72,0:03:39.57,Default,,0000,0000,0000,,things that people have started to make\Nwith it. Dialogue: 0,0:03:39.57,0:03:44.97,Default,,0000,0000,0000,,Wireless Nodebot Kinnect controlled robot\Narm, and LCD Running Man. Dialogue: 0,0:03:44.97,0:03:48.95,Default,,0000,0000,0000,,So, you know, the possibilities get pretty\Nexciting. Dialogue: 0,0:03:50.52,0:03:55.29,Default,,0000,0000,0000,,Okay, to get started we'll need to connect\Nour, our Arduino to our computer. Dialogue: 0,0:03:56.34,0:04:00.66,Default,,0000,0000,0000,,So, we'll do this by connecting the USB\Nport to our Arduino. Dialogue: 0,0:04:00.66,0:04:03.55,Default,,0000,0000,0000,,It serves as both the power to the\NArduino, Dialogue: 0,0:04:04.61,0:04:07.99,Default,,0000,0000,0000,,and the way to upload software to our\NArduino. Dialogue: 0,0:04:09.02,0:04:11.22,Default,,0000,0000,0000,,As you can see, once you plug it in,\Nyou'll Dialogue: 0,0:04:11.22,0:04:14.70,Default,,0000,0000,0000,,have the on lights flicker on, which is a\Ngood sign. Dialogue: 0,0:04:16.43,0:04:18.86,Default,,0000,0000,0000,,In this demo today, I'll be doing a really Dialogue: 0,0:04:18.86,0:04:23.38,Default,,0000,0000,0000,,basic example of turning this LED light on\Nand off. Dialogue: 0,0:04:23.38,0:04:26.87,Default,,0000,0000,0000,,I've already got the jumper leads in where\Nthey should be. Dialogue: 0,0:04:26.87,0:04:30.83,Default,,0000,0000,0000,,So if you need to pause this to be able to\Nfollow along, feel free to Dialogue: 0,0:04:30.83,0:04:35.32,Default,,0000,0000,0000,,pause it now, and put the jumper leads in,\Nin the way that I've got them. Dialogue: 0,0:04:39.51,0:04:41.17,Default,,0000,0000,0000,,Connecting up the Arduino is pretty\Nsimple. Dialogue: 0,0:04:42.21,0:04:48.06,Default,,0000,0000,0000,,Connect up the green one here, to pin 13\Non your Arduino. Dialogue: 0,0:04:48.06,0:04:51.79,Default,,0000,0000,0000,,Then connect up the red one to the 5 volt\Npin. Dialogue: 0,0:04:54.68,0:05:01.13,Default,,0000,0000,0000,,And finally we connect up the black one,\Nto the ground pin. Dialogue: 0,0:05:01.13,0:05:02.30,Default,,0000,0000,0000,,Doesn't really matter about colors, you\Ncan Dialogue: 0,0:05:02.30,0:05:06.76,Default,,0000,0000,0000,,use whatever color jumper wire you'd like. Dialogue: 0,0:05:06.76,0:05:12.22,Default,,0000,0000,0000,,Now that that's all done, we're ready to\Ngo into the software part Dialogue: 0,0:05:12.22,0:05:17.52,Default,,0000,0000,0000,,of the tutorial with what code we've gotta\Nrun, and where to talk to our Arduino. Dialogue: 0,0:05:19.53,0:05:21.13,Default,,0000,0000,0000,,Node application is extremely simple. Dialogue: 0,0:05:21.13,0:05:25.56,Default,,0000,0000,0000,,We've only got two files, an index\NJavaScript file and a package Jason file. Dialogue: 0,0:05:27.24,0:05:34.70,Default,,0000,0000,0000,,If you are new to Node the package Jason\Nfile is what we use to provide any details Dialogue: 0,0:05:34.70,0:05:38.58,Default,,0000,0000,0000,,about the application, and what other Node\Nmodules are required for that application. Dialogue: 0,0:05:40.07,0:05:43.29,Default,,0000,0000,0000,,So, to start with, I'll go over this\Npackaged Dialogue: 0,0:05:43.29,0:05:46.12,Default,,0000,0000,0000,,up Jason file, and show you what's going\Non. Dialogue: 0,0:05:46.12,0:05:49.61,Default,,0000,0000,0000,,So, here we've got what the name of Dialogue: 0,0:05:49.61,0:05:53.54,Default,,0000,0000,0000,,our application is in this case, Node in\NJohnny-Five. Dialogue: 0,0:05:53.54,0:05:57.93,Default,,0000,0000,0000,,Can name this whatever you'd like, totally\Nup to you, but keep it all to one word. Dialogue: 0,0:05:57.93,0:05:59.46,Default,,0000,0000,0000,,It doesn't seem to like spaces. Dialogue: 0,0:05:59.46,0:06:02.42,Default,,0000,0000,0000,,It'll start complaining at you, so\Ndefinitely stick to one word. Dialogue: 0,0:06:03.87,0:06:05.90,Default,,0000,0000,0000,,We've got a version number. Dialogue: 0,0:06:05.90,0:06:08.02,Default,,0000,0000,0000,,Once again, you can pretty much use any\Nversion Dialogue: 0,0:06:08.02,0:06:11.66,Default,,0000,0000,0000,,number you'd like, really, for simple\Nbasic test applications. Dialogue: 0,0:06:11.66,0:06:16.24,Default,,0000,0000,0000,,I've called it 0.0.1, because really this\Napplication is very, Dialogue: 0,0:06:16.24,0:06:19.13,Default,,0000,0000,0000,,very early stages and isn't going to be\Ndoing too much. Dialogue: 0,0:06:19.13,0:06:21.28,Default,,0000,0000,0000,,So, I'm keeping it at a very early\Nversion. Dialogue: 0,0:06:22.52,0:06:25.27,Default,,0000,0000,0000,,Then the very important thing, which will\Ndefinitely prevent Dialogue: 0,0:06:25.27,0:06:31.25,Default,,0000,0000,0000,,our application working with Arduinos is\Nour dependency section here. Dialogue: 0,0:06:31.25,0:06:34.12,Default,,0000,0000,0000,,This is where we say what other modules we\Nneed, Dialogue: 0,0:06:34.12,0:06:37.71,Default,,0000,0000,0000,,running and in our Node application for\Nthis to work. Dialogue: 0,0:06:37.71,0:06:41.80,Default,,0000,0000,0000,,So, we only need Johnny-Five, which is the\Nmodule I was showing earlier. Dialogue: 0,0:06:42.91,0:06:44.38,Default,,0000,0000,0000,,And this here is the version. Dialogue: 0,0:06:44.38,0:06:49.06,Default,,0000,0000,0000,,So, in this case, we want the latest\NJohnny-Five version of that module. Dialogue: 0,0:06:50.55,0:06:53.68,Default,,0000,0000,0000,,Basically, we're doing such simple stuff,\Njust basic turning Dialogue: 0,0:06:53.68,0:06:56.97,Default,,0000,0000,0000,,an LED light on and off, not likely to\Nchange. Dialogue: 0,0:06:56.97,0:07:00.30,Default,,0000,0000,0000,,So, we're gonna assume that, in every\Nfuture version of Dialogue: 0,0:07:00.30,0:07:04.35,Default,,0000,0000,0000,,Johnny-Five, it'll be compatible with what\Nwe're gonna be doing here. Dialogue: 0,0:07:04.35,0:07:08.58,Default,,0000,0000,0000,,So, there's no need to really be, specific\Non which version we're wanting. Dialogue: 0,0:07:08.58,0:07:12.13,Default,,0000,0000,0000,,Now we'll go on to the index JavaScript\Nfile. Dialogue: 0,0:07:15.60,0:07:17.84,Default,,0000,0000,0000,,Our index JavaScript file contains all Dialogue: 0,0:07:17.84,0:07:20.35,Default,,0000,0000,0000,,of the functionality, but the node\Napplication. Dialogue: 0,0:07:20.35,0:07:24.35,Default,,0000,0000,0000,,So, this pretty much is our note\Napplication Dialogue: 0,0:07:25.51,0:07:28.98,Default,,0000,0000,0000,,in 19 lines, two of which are Console\Nlogs. Dialogue: 0,0:07:28.98,0:07:31.81,Default,,0000,0000,0000,,So, very, very small application here. Dialogue: 0,0:07:32.94,0:07:33.90,Default,,0000,0000,0000,,I'll go through it step by step and Dialogue: 0,0:07:33.90,0:07:35.85,Default,,0000,0000,0000,,explain what everything is and why it's\Nthere. Dialogue: 0,0:07:37.86,0:07:40.19,Default,,0000,0000,0000,,Firstly, we've got our five variable. Dialogue: 0,0:07:40.19,0:07:44.03,Default,,0000,0000,0000,,Our five variable just requires the\NJohnny-Five module. Dialogue: 0,0:07:44.03,0:07:48.60,Default,,0000,0000,0000,,Once again, the reason that we've got it\Nhere as well as in the package Jason file, Dialogue: 0,0:07:48.60,0:07:54.57,Default,,0000,0000,0000,,is that we're assigning all of the\Ndifferent objects and functionality. Dialogue: 0,0:07:54.57,0:07:57.56,Default,,0000,0000,0000,,That we gain from the Johnny-Five module\Ninto this five Dialogue: 0,0:07:57.56,0:08:00.94,Default,,0000,0000,0000,,variable so we can access it throughout\Nthe node application. Dialogue: 0,0:08:00.94,0:08:04.74,Default,,0000,0000,0000,,An example of that is our next line here,\Nwhich is board. Dialogue: 0,0:08:04.74,0:08:08.79,Default,,0000,0000,0000,,Our board variable, is creating a new\Nboard Dialogue: 0,0:08:08.79,0:08:12.44,Default,,0000,0000,0000,,object which is part of the Johnny-Five\Nmodule. Dialogue: 0,0:08:12.44,0:08:17.31,Default,,0000,0000,0000,,So we're looking into the Johnny-Five\Nobject here, that Dialogue: 0,0:08:17.31,0:08:19.86,Default,,0000,0000,0000,,we've required here, and we're grabbing\Nthe board object. Dialogue: 0,0:08:21.52,0:08:23.24,Default,,0000,0000,0000,,Which is all the part of the Jonny-Five\Nmodule. Dialogue: 0,0:08:23.24,0:08:24.42,Default,,0000,0000,0000,,We don't have to worry about any of this. Dialogue: 0,0:08:24.42,0:08:25.97,Default,,0000,0000,0000,,We don't have to really create any of\Nthis. Dialogue: 0,0:08:25.97,0:08:27.68,Default,,0000,0000,0000,,It's all been there. Dialogue: 0,0:08:27.68,0:08:29.35,Default,,0000,0000,0000,,Thanks to the geniuses who have come\Nbefore us. Dialogue: 0,0:08:32.41,0:08:35.14,Default,,0000,0000,0000,,Next up, we are declaring a few more\Nvariables that we use later on, Dialogue: 0,0:08:35.14,0:08:39.93,Default,,0000,0000,0000,,so we are declaring the LED variable, and\Nwe are declaring toggle state variable. Dialogue: 0,0:08:39.93,0:08:41.19,Default,,0000,0000,0000,,I'll explain these a bit later on. Dialogue: 0,0:08:41.19,0:08:45.41,Default,,0000,0000,0000,,[BLANK_AUDIO] Dialogue: 0,0:08:45.41,0:08:48.24,Default,,0000,0000,0000,,To begin, look at this here actually. Dialogue: 0,0:08:48.24,0:08:49.79,Default,,0000,0000,0000,,This is an important one because this is\Nwhat Dialogue: 0,0:08:49.79,0:08:52.62,Default,,0000,0000,0000,,will come up first, when we run our\Napplication. Dialogue: 0,0:08:52.62,0:08:54.90,Default,,0000,0000,0000,,It's just a console log saying waiting for\Ndevice to connect. Dialogue: 0,0:08:56.00,0:09:01.12,Default,,0000,0000,0000,,What that means is that, that will come up\Nfirst, as soon as the known application Dialogue: 0,0:09:01.12,0:09:04.67,Default,,0000,0000,0000,,is starts up just to let us know that the\Nnew application is at least running. Dialogue: 0,0:09:05.89,0:09:10.07,Default,,0000,0000,0000,,But we don't know yet whether our Arduino\Nhas Dialogue: 0,0:09:10.07,0:09:11.70,Default,,0000,0000,0000,,connected up, and whether we can talk to\Nit. Dialogue: 0,0:09:13.01,0:09:17.82,Default,,0000,0000,0000,,What then happens, is, using this baud\Nvariable here that we created. Dialogue: 0,0:09:17.82,0:09:20.60,Default,,0000,0000,0000,,Which is a Johnny-Five board object. Dialogue: 0,0:09:21.81,0:09:24.33,Default,,0000,0000,0000,,We say, on ready, which means, when we've\Ngot Dialogue: 0,0:09:24.33,0:09:28.00,Default,,0000,0000,0000,,the event of ready fired from the board,\Nwhich means. Dialogue: 0,0:09:28.00,0:09:32.59,Default,,0000,0000,0000,,The board's pretty faster, sends any sort\Nof commands and requests to it. Dialogue: 0,0:09:33.86,0:09:38.03,Default,,0000,0000,0000,,We run this function right here, and this\Nfunction Dialogue: 0,0:09:39.07,0:09:41.11,Default,,0000,0000,0000,,starts off with a console log saying board\Nready. Dialogue: 0,0:09:41.11,0:09:44.46,Default,,0000,0000,0000,,This will just let us know, if we're\Nwatching the console while Dialogue: 0,0:09:44.46,0:09:47.65,Default,,0000,0000,0000,,our node application is running, that the\Nboard is ready to receive. Dialogue: 0,0:09:49.00,0:09:51.12,Default,,0000,0000,0000,,Our request. Dialogue: 0,0:09:51.12,0:09:54.80,Default,,0000,0000,0000,,It also is a good way to devote whether,\Nor not the board is connected properly. Dialogue: 0,0:09:54.80,0:09:55.52,Default,,0000,0000,0000,,You are doing a board. Dialogue: 0,0:09:57.38,0:10:01.82,Default,,0000,0000,0000,,Next up, we use this LED variable that we\Ndeclared earlier, and Dialogue: 0,0:10:01.82,0:10:04.88,Default,,0000,0000,0000,,we create a new LED, once again part of\Nthe Johnny-Five module. Dialogue: 0,0:10:05.91,0:10:10.42,Default,,0000,0000,0000,,We're basically just letting it know that\Nwe've got an LED. Dialogue: 0,0:10:10.42,0:10:13.39,Default,,0000,0000,0000,,At pin 13 which is what we plugged into\Nearlier. Dialogue: 0,0:10:15.77,0:10:20.98,Default,,0000,0000,0000,,Then we get to the JavaScript bit which\Nis, we're setting an interval using the Dialogue: 0,0:10:20.98,0:10:24.33,Default,,0000,0000,0000,,JavaScript function which many of you\Nmight Dialogue: 0,0:10:24.33,0:10:26.85,Default,,0000,0000,0000,,be used to if you are JavaScript gurus. Dialogue: 0,0:10:26.85,0:10:32.44,Default,,0000,0000,0000,,Basically set interval means that we're\Ngonna use this function here, toggle LED. Dialogue: 0,0:10:32.44,0:10:36.53,Default,,0000,0000,0000,,Every 200 milliseconds, and you can play\Naround with this Dialogue: 0,0:10:36.53,0:10:39.92,Default,,0000,0000,0000,,number if you'd like later on, just to\Nexperiment, and change Dialogue: 0,0:10:39.92,0:10:42.81,Default,,0000,0000,0000,,how often the LED light gonna toggle on\Nand off, Dialogue: 0,0:10:42.81,0:10:45.55,Default,,0000,0000,0000,,but basically we're gonna say, run this\Nfunction every 200 milliseconds. Dialogue: 0,0:10:46.77,0:10:49.00,Default,,0000,0000,0000,,What isn't that function well, the\Nfunction here has. Dialogue: 0,0:10:50.67,0:10:55.18,Default,,0000,0000,0000,,Three lines and one life line which is\Njust there for user reading. Dialogue: 0,0:10:55.18,0:10:59.04,Default,,0000,0000,0000,,Basically we use this variable here,\Ntoggle state, Dialogue: 0,0:10:59.04,0:11:01.06,Default,,0000,0000,0000,,which we set up earlier to be false. Dialogue: 0,0:11:02.30,0:11:05.84,Default,,0000,0000,0000,,And each time toggle LED runs, will change\Nthe value of Dialogue: 0,0:11:05.84,0:11:09.12,Default,,0000,0000,0000,,toggle state from true to false or from\Nfalse to true. Dialogue: 0,0:11:09.12,0:11:11.71,Default,,0000,0000,0000,,So, it basically just changes it the\Nopposite of what it was. Dialogue: 0,0:11:13.10,0:11:19.89,Default,,0000,0000,0000,,Then, if total state is true, we turn our\NLED light on, otherwise turn it off. Dialogue: 0,0:11:19.89,0:11:22.70,Default,,0000,0000,0000,,So, basically, we keep changing toggle\Nstate on and off, on and off, Dialogue: 0,0:11:24.12,0:11:27.79,Default,,0000,0000,0000,,in turn, turning our LED light on and off\Nand on and off. Dialogue: 0,0:11:27.79,0:11:30.39,Default,,0000,0000,0000,,[BLANK_AUDIO] Dialogue: 0,0:11:30.39,0:11:31.08,Default,,0000,0000,0000,,You've. Dialogue: 0,0:11:32.08,0:11:33.49,Default,,0000,0000,0000,,You're following this now and kind of, Dialogue: 0,0:11:33.49,0:11:36.06,Default,,0000,0000,0000,,picturing the function running in your\Nhead. Dialogue: 0,0:11:36.06,0:11:39.14,Default,,0000,0000,0000,,If you'll notice there is nothing that\Nturns off Dialogue: 0,0:11:39.14,0:11:42.36,Default,,0000,0000,0000,,this LED, so it will theoretically go on\Nforever continually Dialogue: 0,0:11:42.36,0:11:45.50,Default,,0000,0000,0000,,turning on and off, on and off until we\Neither Dialogue: 0,0:11:45.50,0:11:48.18,Default,,0000,0000,0000,,disconnect our Arduino or we turn off this\Nnode application. Dialogue: 0,0:11:48.18,0:11:50.27,Default,,0000,0000,0000,,And I'll be showing you how to do that to. Dialogue: 0,0:11:51.58,0:11:55.04,Default,,0000,0000,0000,,Theoretically, you could also include some\Nother functionality, in the Dialogue: 0,0:11:55.04,0:11:59.31,Default,,0000,0000,0000,,error to turn off the, Intel by clearing\NIntel if you'd Dialogue: 0,0:11:59.31,0:12:02.29,Default,,0000,0000,0000,,like to but in this tutorial to keep\Nthings simple, Dialogue: 0,0:12:02.29,0:12:04.11,Default,,0000,0000,0000,,we're just gonna give it to the basics I'm\Nshowing you. Dialogue: 0,0:12:04.11,0:12:08.10,Default,,0000,0000,0000,,This is how you can control the Arduino\Nfrom Node, and Dialogue: 0,0:12:08.10,0:12:10.93,Default,,0000,0000,0000,,then you can add as much functionality as\Nyou'd like to. Dialogue: 0,0:12:10.93,0:12:12.01,Default,,0000,0000,0000,,On top of this and have a bit of fun. Dialogue: 0,0:12:14.44,0:12:20.83,Default,,0000,0000,0000,,Now that we have those two files up there\Nand ready to run our Node application, we Dialogue: 0,0:12:20.83,0:12:29.15,Default,,0000,0000,0000,,do have to make sure those dependencies we\Nmentioned, are there and available to run. Dialogue: 0,0:12:31.11,0:12:34.69,Default,,0000,0000,0000,,So, what I've done is I've opened up a\Ntunnel, and I've gone to Dialogue: 0,0:12:34.69,0:12:39.56,Default,,0000,0000,0000,,the same folder that we put those two\Nfiles in to prove that to you. Dialogue: 0,0:12:39.56,0:12:40.53,Default,,0000,0000,0000,,I'll just show you there. Dialogue: 0,0:12:40.53,0:12:44.17,Default,,0000,0000,0000,,So, you've got the index JavaScript file,\Nand our package JSON file. Dialogue: 0,0:12:46.29,0:12:46.79,Default,,0000,0000,0000,,So. Dialogue: 0,0:12:48.23,0:12:53.85,Default,,0000,0000,0000,,How you would usually run a node\Napplication is just Node index.js. Dialogue: 0,0:12:53.85,0:12:57.29,Default,,0000,0000,0000,,And we're gonna attempt to run it. Dialogue: 0,0:12:57.29,0:13:01.61,Default,,0000,0000,0000,,And what we see here is that is says,\Ncannot find Module Johnny-Five. Dialogue: 0,0:13:01.61,0:13:02.99,Default,,0000,0000,0000,,Which is fair enough. Dialogue: 0,0:13:02.99,0:13:05.97,Default,,0000,0000,0000,,We've told it in the Index JavaScript\Nfile. Dialogue: 0,0:13:05.97,0:13:10.31,Default,,0000,0000,0000,,That there's gonna be a node module called\NJohnny-Five and it's gone and looked for Dialogue: 0,0:13:10.31,0:13:13.63,Default,,0000,0000,0000,,it and can't find and it is now very upset\Nat us for lying to it. Dialogue: 0,0:13:13.63,0:13:16.05,Default,,0000,0000,0000,,So, we need to get it installed. Dialogue: 0,0:13:17.54,0:13:21.75,Default,,0000,0000,0000,,To install it you can use an incredible\Npackage manager called MPM. Dialogue: 0,0:13:23.06,0:13:27.20,Default,,0000,0000,0000,,MPM just runs through your package.jason\Nfile, Dialogue: 0,0:13:27.20,0:13:29.44,Default,,0000,0000,0000,,and installs any dependencies that you've\Ngot listed. Dialogue: 0,0:13:29.44,0:13:32.15,Default,,0000,0000,0000,,If you don't have MPM on your machine just\Ndo a Dialogue: 0,0:13:32.15,0:13:35.55,Default,,0000,0000,0000,,quick Google search for MPM, and install\Nit on your computer. Dialogue: 0,0:13:36.75,0:13:41.18,Default,,0000,0000,0000,,It's quite a simple process, so I won't\Ncover it here. Dialogue: 0,0:13:42.90,0:13:47.46,Default,,0000,0000,0000,,So basically, once you've got MPM\Ninstalled, you type in MPM space install. Dialogue: 0,0:13:47.46,0:13:51.46,Default,,0000,0000,0000,,And, it will go through looking through\Nour package Jason file. Dialogue: 0,0:13:52.79,0:13:54.98,Default,,0000,0000,0000,,It also does a nice bunch of warning us,\Nsaying we Dialogue: 0,0:13:54.98,0:13:59.88,Default,,0000,0000,0000,,don't have a few of those that we could\Nhave had. Dialogue: 0,0:13:59.88,0:14:01.62,Default,,0000,0000,0000,,Description I think and a few other ones. Dialogue: 0,0:14:02.70,0:14:05.35,Default,,0000,0000,0000,,So, basically, it's gone through and\Ninstalled Dialogue: 0,0:14:05.35,0:14:08.40,Default,,0000,0000,0000,,our modules here so we've got all the Dialogue: 0,0:14:08.40,0:14:11.68,Default,,0000,0000,0000,,Johnny-Five Modules, and all this other\Nstuff Dialogue: 0,0:14:11.68,0:14:14.79,Default,,0000,0000,0000,,that it deems necessary to run our\Napplication. Dialogue: 0,0:14:16.07,0:14:16.78,Default,,0000,0000,0000,,So now, I'm going Dialogue: 0,0:14:18.92,0:14:22.58,Default,,0000,0000,0000,,to clear this, but before we run our\Nactual. Dialogue: 0,0:14:22.58,0:14:26.85,Default,,0000,0000,0000,,Application we're gonna need to set up our\NArduino, so Dialogue: 0,0:14:26.85,0:14:30.76,Default,,0000,0000,0000,,that it's able to receive communication\Nfrom our Arduino application. Dialogue: 0,0:14:31.98,0:14:36.70,Default,,0000,0000,0000,,To get this communication working between\Nour Arduino and the computer, Dialogue: 0,0:14:36.70,0:14:40.66,Default,,0000,0000,0000,,we just need to upload a bit of code to\Nour Arduino. Dialogue: 0,0:14:40.66,0:14:44.77,Default,,0000,0000,0000,,Arduino calls these bits of code sketches. Dialogue: 0,0:14:44.77,0:14:50.02,Default,,0000,0000,0000,,Which you upload and then install onto the\NArduino and then the Arduino knows Dialogue: 0,0:14:50.02,0:14:55.09,Default,,0000,0000,0000,,what it needs to do, In our case we don't\Nneed the Arduino to do too much. Dialogue: 0,0:14:55.09,0:15:00.48,Default,,0000,0000,0000,,Most of our functionality is in Node, all\Nwe need to do is install Dialogue: 0,0:15:00.48,0:15:04.03,Default,,0000,0000,0000,,a bit of code to ensure it understands how\Nto communicate with the computer. Dialogue: 0,0:15:05.96,0:15:10.02,Default,,0000,0000,0000,,First off, before we install it, if you\Nhaven't used the Arduino software Dialogue: 0,0:15:10.02,0:15:16.41,Default,,0000,0000,0000,,before, double check that your serial port\Nis pointing to the correct USB port. Dialogue: 0,0:15:16.41,0:15:17.83,Default,,0000,0000,0000,,You might need to do a bit of trial, and\Nerror with Dialogue: 0,0:15:17.83,0:15:21.18,Default,,0000,0000,0000,,this one if you're not sure which USB port\Nis the correct one. Dialogue: 0,0:15:21.18,0:15:24.87,Default,,0000,0000,0000,,But in my case, it was this TTY USB modem. Dialogue: 0,0:15:26.99,0:15:28.61,Default,,0000,0000,0000,,Do a bit of trial and error to check which\Nwill work Dialogue: 0,0:15:28.61,0:15:33.12,Default,,0000,0000,0000,,if you are having any issues with\Nuploading your code to your Arduino. Dialogue: 0,0:15:33.12,0:15:35.62,Default,,0000,0000,0000,,Definitely check that setting right there. Dialogue: 0,0:15:35.62,0:15:38.19,Default,,0000,0000,0000,,I've also got the board set up to Dialogue: 0,0:15:38.19,0:15:42.14,Default,,0000,0000,0000,,be Arduino set up to whichever board\N[INAUDIBLE]. Dialogue: 0,0:15:42.14,0:15:43.59,Default,,0000,0000,0000,,Then top load the sketch. Dialogue: 0,0:15:44.91,0:15:47.62,Default,,0000,0000,0000,,We're going to go to file, examples. Dialogue: 0,0:15:47.62,0:15:49.14,Default,,0000,0000,0000,,And then you'll have this on yours too Dialogue: 0,0:15:49.14,0:15:54.98,Default,,0000,0000,0000,,Fermata, we want the standard Fermata,\Nsketch here, and Dialogue: 0,0:15:54.98,0:15:58.00,Default,,0000,0000,0000,,this as it says here is a generic protocol Dialogue: 0,0:15:58.00,0:16:01.41,Default,,0000,0000,0000,,for communicating with micro controls,\Nfrom software on computer. Dialogue: 0,0:16:03.02,0:16:05.79,Default,,0000,0000,0000,,That is convenient, because that's exactly\Nwhat we want to do. Dialogue: 0,0:16:05.79,0:16:10.87,Default,,0000,0000,0000,,We want to communicate from our notes\Nsoftware Dialogue: 0,0:16:10.87,0:16:14.80,Default,,0000,0000,0000,,to our micro control, which is our\NArduino. Dialogue: 0,0:16:14.80,0:16:17.91,Default,,0000,0000,0000,,So, to upload this to our Arduino, make\Nsure you've Dialogue: 0,0:16:17.91,0:16:22.32,Default,,0000,0000,0000,,got it plugged into your computer still,\Nand click upload. Dialogue: 0,0:16:22.32,0:16:23.69,Default,,0000,0000,0000,,It'll compile the sketch. Dialogue: 0,0:16:24.78,0:16:27.21,Default,,0000,0000,0000,,It'll upload it onto the Arduino. Dialogue: 0,0:16:28.39,0:16:31.04,Default,,0000,0000,0000,,And then in a few seconds it should be\Ndone. Dialogue: 0,0:16:31.04,0:16:31.62,Default,,0000,0000,0000,,There we go. Dialogue: 0,0:16:31.62,0:16:33.65,Default,,0000,0000,0000,,So, it's done uploading, which mean's\Nyou've now got Dialogue: 0,0:16:33.65,0:16:39.27,Default,,0000,0000,0000,,the standard Fermata software or a\Nstandard Fermata sketch. Dialogue: 0,0:16:39.27,0:16:42.35,Default,,0000,0000,0000,,On your Arduino, which means we're ready\Nnow, to move on to the Dialogue: 0,0:16:42.35,0:16:46.56,Default,,0000,0000,0000,,next very exciting bit of running our Node\Ncode and communicating with that Arduino. Dialogue: 0,0:16:48.02,0:16:50.13,Default,,0000,0000,0000,,We've got our two files set up. Dialogue: 0,0:16:50.13,0:16:55.39,Default,,0000,0000,0000,,Our index JavaScript which has all the\Ncode for our Node application. Dialogue: 0,0:16:55.39,0:16:58.91,Default,,0000,0000,0000,,We've installed all our dependencies,\Nusing MPM. Dialogue: 0,0:16:58.91,0:17:01.59,Default,,0000,0000,0000,,We've also got our Arduino connected and Dialogue: 0,0:17:01.59,0:17:06.87,Default,,0000,0000,0000,,running the standard Fermata, sketch code;\Nwhich means Dialogue: 0,0:17:06.87,0:17:10.12,Default,,0000,0000,0000,,it's now ready to accept all commands that\Nwill come to it from our computer. Dialogue: 0,0:17:11.32,0:17:14.31,Default,,0000,0000,0000,,So, all that's left is to be in our\Nterminal Dialogue: 0,0:17:14.31,0:17:21.10,Default,,0000,0000,0000,,and type in Node index.js, and when we run\Nthis, Dialogue: 0,0:17:23.35,0:17:26.14,Default,,0000,0000,0000,,we've got our, waiting for device to\Nconnect, message along Dialogue: 0,0:17:26.14,0:17:31.40,Default,,0000,0000,0000,,with a few messages that come from the\NJohnny-Five Module. Dialogue: 0,0:17:32.60,0:17:36.27,Default,,0000,0000,0000,,It's found our serial port, which is the Dialogue: 0,0:17:37.65,0:17:42.89,Default,,0000,0000,0000,,USB port that we've got the Arduino\Nconnected to. Dialogue: 0,0:17:42.89,0:17:45.32,Default,,0000,0000,0000,,Your one might be very different to this. Dialogue: 0,0:17:45.32,0:17:46.15,Default,,0000,0000,0000,,Doesn't really matter. Dialogue: 0,0:17:46.15,0:17:47.86,Default,,0000,0000,0000,,The main important thing, is that our\Nconsole log Dialogue: 0,0:17:47.86,0:17:51.22,Default,,0000,0000,0000,,that we set up, which said, board ready,\Nhas appeared. Dialogue: 0,0:17:51.22,0:17:55.85,Default,,0000,0000,0000,,And if you turn to face your LED light,\Nyou'll see that it's now flashing. Dialogue: 0,0:17:57.57,0:17:58.06,Default,,0000,0000,0000,,Which is lovely. Dialogue: 0,0:17:58.06,0:17:59.35,Default,,0000,0000,0000,,It means that our code is working. Dialogue: 0,0:17:59.35,0:18:04.98,Default,,0000,0000,0000,,We're sending our commands to the 13th\Npin, telling Dialogue: 0,0:18:04.98,0:18:07.45,Default,,0000,0000,0000,,it to turn an LED light on and off. Dialogue: 0,0:18:07.45,0:18:10.58,Default,,0000,0000,0000,,And so it's turning on and off, and on and\Noff, on and off. Dialogue: 0,0:18:10.58,0:18:13.63,Default,,0000,0000,0000,,Just as we requested it to. Dialogue: 0,0:18:13.63,0:18:16.07,Default,,0000,0000,0000,,The only important question is how do you\Nget it to turn off? Dialogue: 0,0:18:16.07,0:18:18.65,Default,,0000,0000,0000,,How do you stop it from constantly\Nrunning? Dialogue: 0,0:18:18.65,0:18:19.65,Default,,0000,0000,0000,,This note application. Dialogue: 0,0:18:21.11,0:18:27.45,Default,,0000,0000,0000,,If we go back to the terminal here, what\Nyou've gotta do is just press Ctrl C and Dialogue: 0,0:18:27.45,0:18:34.04,Default,,0000,0000,0000,,then Ctrl C again and it'll close the\Nboard and it'll stop that light blinking. Dialogue: 0,0:18:35.05,0:18:37.55,Default,,0000,0000,0000,,If you timed it correctly, the light'll be\Noff. Dialogue: 0,0:18:37.55,0:18:40.69,Default,,0000,0000,0000,,If you time it slightly differently, the\Nlight will stay on. Dialogue: 0,0:18:40.69,0:18:42.75,Default,,0000,0000,0000,,And that's okay, really. Dialogue: 0,0:18:42.75,0:18:43.44,Default,,0000,0000,0000,,It's not a big deal. Dialogue: 0,0:18:43.44,0:18:47.13,Default,,0000,0000,0000,,If you want to completely turn it off, you\Ncan just unplug the Dialogue: 0,0:18:47.13,0:18:52.75,Default,,0000,0000,0000,,USB from the computer, and it will turn\Noff all power to your Arduino. Dialogue: 0,0:18:52.75,0:18:53.78,Default,,0000,0000,0000,,It won't harm it in any way. Dialogue: 0,0:18:53.78,0:18:55.80,Default,,0000,0000,0000,,It's just a quick way of getting it to. Dialogue: 0,0:18:56.92,0:18:59.87,Default,,0000,0000,0000,,Stop doing what it was doing that you\Nreally didn't want it to do. Dialogue: 0,0:18:59.87,0:19:05.70,Default,,0000,0000,0000,,And that, my friends, is how you turn a\NLED light on and off, and on and off Dialogue: 0,0:19:05.70,0:19:11.25,Default,,0000,0000,0000,,in an infinite loop using node Johnny-Five\Nand Arduino. Dialogue: 0,0:19:11.25,0:19:14.51,Default,,0000,0000,0000,,If you followed along, you should now have\Nan Dialogue: 0,0:19:14.51,0:19:17.36,Default,,0000,0000,0000,,LED light, bending to your node\Napplication as well. Dialogue: 0,0:19:17.36,0:19:17.86,Default,,0000,0000,0000,,Good work. Dialogue: 0,0:19:19.08,0:19:20.50,Default,,0000,0000,0000,,This is the basics. Dialogue: 0,0:19:20.50,0:19:22.09,Default,,0000,0000,0000,,There's a lot more to do from here. Dialogue: 0,0:19:22.09,0:19:24.94,Default,,0000,0000,0000,,If you've got any questions, or if there's\Nanything that Dialogue: 0,0:19:24.94,0:19:27.30,Default,,0000,0000,0000,,I've missed, feel free to get in touch\Nwith me. Dialogue: 0,0:19:27.30,0:19:29.53,Default,,0000,0000,0000,,My name once again is Patrick Catanzariti. Dialogue: 0,0:19:29.53,0:19:38.11,Default,,0000,0000,0000,,I am on Twitter at thatpatrickguy or I've\Ngot a website Patcat.me. Dialogue: 0,0:19:38.11,0:19:41.88,Default,,0000,0000,0000,,So, feel free to get in touch, if you make\Nanything really cool with Arduinos Dialogue: 0,0:19:41.88,0:19:43.26,Default,,0000,0000,0000,,following up from this tutorial,\Ndefinitely get Dialogue: 0,0:19:43.26,0:19:44.26,Default,,0000,0000,0000,,in touch as well, we'd love to see. Dialogue: 0,0:19:44.26,0:19:52.72,Default,,0000,0000,0000,,Thanks for taking the time, to watch, and\NI hope you learned something new. Dialogue: 0,0:19:52.72,0:19:55.05,Default,,0000,0000,0000,,See you. Dialogue: 0,0:19:55.05,0:20:01.27,Default,,0000,0000,0000,,