 Thank you. All right, like you said, I'll be talking about hardware APIs. And I said hardware, because it sounds cool. But primarily, we'll be talking about an Arduino, because I have an Arduino right here. But I want to win that Raspberry Pi out there. Anyways, before I get started, I want to say one thing. Jamison tweeted this a year ago. Just go ahead and read that. And I made my slides. And then I'm not a designer, and I made my slides. And then I happened to see him tweet this something about it earlier, and I clicked on it. And it was exactly what my slides were. So sorry about the default blue Helvetica. Just a little bit about me. My background is more web development. And actually, my first language was JavaScript. And I'm not a designer like the last guy said, so I don't know. But I started developing websites and freelancing. And then I have now started shifting. And I'm a hobbyist for hardware and stuff. And actually, a couple of months ago, I attended RobotsConf 2014. And it truly inspired me. VoodooTikiGod, aka Chris Williams. He does JSConf, RobotsConf. He spoke and asked each one of us what we're going to take away from RobotsConf. I got pretty excited because he's a pretty influential speaker. And just the way he was talking, it made me like subscribe to Make Magazine. I bought some hardware, but I wasn't even really sure what I was getting myself into. But I knew I wanted to make something with hardware, because hardware's awesome. Jameson actually talked about awesome things you can do with hardware last year around West. So that also helped inspire me. So I bought some things. And then what I wanted to make, my project seemed a little crazy, but it was a White Tiles app. Or like the White Tiles game, but with hardware. So basically, the way I thought it was was I'd have a grid of LEDs and then four buttons. And basically, if you don't know what the White Tiles phone app is, it has these black things that come down. And then you tap them in consecutive order. And so I wanted to make that with hardware, like a life size hardware game that you could play. And then, what was that? Don't say something. Oh, anyways. I actually did make this. And Jameson can test. And he saw it. And I showed him. And so I did write it. And I actually wrote it in Arduino. Or it's like a variation of C++ or C. I'm not really sure. But I found it was, at least for me, like this is a story of me, how I came from web development to hardware. Writing in Arduino was like super hard. And I was like, I didn't understand. There's a lot of concepts that I understand. I haven't taken any computer science courses. So I'm still like super fresh. And I looked at Johnny 5. And Johnny 5 was awesome because it lets you do easy stuff with just looking at this syntax. It looks like jQuery asks, like, board.onReady. And then you'd give it a button. And then you'd say, new5.button. And then that would be on pin8. And then you could say, button.on, down. And then you'd press down or button.onHold. So I was like, wow, that's pretty easy. I was like, I want to see what Arduino would be like. And then, so I was looking at Arduino. And basically, they have a setup loop. And in the setup, you'd set a pin mode. So this is just for doing a button. Just like the Johnny 5 version I just showed you. And it takes a pin, and then the mode. And then the mode would be something like an input, output, input, pull up, et cetera. And then you could, the way I'm doing it here is by reading the state of the push-button value. So setting it outside. And then if the button is pressed, the buttons, they'll be high. And then if it's not pressed, then it'll be low. And then this may seem like similar to Johnny 5's, but it actually can get kind of complex. Like say, for instance, I push a button and then go. It'll const out multiple times. And by multiple times, I mean it could get called five to 10 times. And I was so confused why I was pushing a button. And then my game would, I'd push the right button, but then the game would break. I was so confused, but it was because apparently you have to do something which called debouncing. And the reason why you have to debounce is, for you don't know what debounce is, it's like, if you've ever used low dash or underscore, they have a debounce function. And the reason why I was happening is because the values were read faster than your hands would move, so there may be a lot of reads before you even push the button and change the state. So there's a couple ways that I know of that you could fix this. And one way is the way I'm doing it right here is keeping the button state outside and then checking to see if the button stays changed. Or you can debounce, which is also cool. But I still wanted to know what Johnny Fai was doing to make things so much easier and accessible. So I decided to peek under the covers. I don't know why I whistled. I was just kind of, I just decided to. Anyways, I opened up LED.js. And I saw, I immediately recognized the concept of pins because you have pins in Arduino and you have, you know, Johnny Fai uses them also. And then they had a board, and then they also had some, like a variable called IO. So they'd always do like IO dot something. And, you know, I knew IO stood for input and output. But I was like, what are they doing with this? And so I kept chasing back what IO was. And I finally came to a conclusion that the library they're using is called Formata. Like a Formata library is actually called that. Like, there's a Formata and then there's like this Formata library, not to get confused with that. And so they're using a Formata library. And basically what Formata is, not the Formata library, but what Formata is, it's a protocol to communicate with microcontrollers from software on a computer. That's like the definition. And so microcontroller would be like an Arduino, Raspberry Pi, et cetera. And then for you that don't know what a protocol is, it's an agreed upon way. And then so we can control the Arduino by using Formata, something that, you know, I like to just show a little, you can sprinkle on a little bit of fairy dust, which is called Formata, which will be able to control, you know, using the, or control the Arduino using Node. So I'll talk a little bit more about Formata a little bit later. And also I found this thing called, inside the Formata library, Node serial port. And this will allow you to make a connection to a serial port for reading and writing data, communicate over the USB, et cetera. And this Node serial port, the library was actually, well, I think it's called library, is actually Chris Williams, the guy I was talking about earlier. He made that, so it's awesome. You can do some cool stuff with that. So this is my whole picture. This is what I came to see. I looked at Johnny Five, looked inside Johnny Five, just simple led.js example. And then I found the Formata library, which will then go, they use Node serial ports, communicate the data, you know, through your computer to the Arduino or whatever. And then it goes onto the Arduino and then it's processed by the onboard like firmware that you, you know, you can boot up ahead of time. And then to use Node for the Arduino, we'll upload a standard Formata, which is a way to communicate through it, like I said. So we have the whole picture. Well, this is how me going through my steps of learning about this. And I have the whole picture I could see to top down, but I wanted to make a Johnny Five style abstraction so that I could say, you know, I wanted to be able to do what Johnny Five was doing, but a much simpler version. So I'll show you that demo and hope everything works. I'm going to, can anyone see my cursor? Cool. So I have the Arduino right here. It's not really important that you see it, but just pointing it out. Okay, so I'll open my Mountain West folder. And I've already installed, just in case, you know, because I don't have internet, I already installed the, oh, let me make that bigger. Why don't you guys see anything? Is that better? Bigger? Okay. All right, so I already installed the Formata library. So now we're going to need a couple of things that to make for what we're going to do. So I'll first make an index.js and a josh.js, you know, because of my name. And I'll use Sublime. You guys can hate on me later, because I'm not using them or whatever. Oh. Okay, so now we'll open up our josh.js and we'll create a function called led. And inside here, we'll have the, we'll give it a pin and then the board that the Formata library will give us when in our index.js. I'll say this.pins equal to pin. This.board is equal to board. Oops, I'll put that back there. And then we'll have in the Formata library that you can turn on, give the pin my luck I was showing you earlier that Johnny Fai was doing, but we'll just use it for model library in here. And then we'll say pin mode. I think it's capital M, maybe not, I'm not sure. I think it's like that. And then we can say give it this, the pin that we're giving it in the led function. Then we'll say this.board.modes.output. And they'll also do led. Oh, thank you. Thanks Murphy. And we'll say instead of dot on, let's say give life. Cause let's give the led life. Thanks Murphy for laughing again. So console logger on. And then we'll say, we'll just find out what pin we're on, this pin. And then we'll say this.board.digitalwrite, which digital write is a function that the Formata library gives that you can write an output to the digital pin. So either high or low, so high will be on and then low will just be off. So we'll give it that. And we'll have to give it the stop pin and then this.board.high. And then in our index.js we'll have, oops, we gotta export it, led, led. And then our index.js will say var Formata equals the require the Formata library that I've already installed. And then we can say var Josh is equal to require Josh. Josh. And then we can give it the board instance, like I was saying, so new Formata. This Formata library has the board. This is familiar to anyone who you know, Johnny five or Formata, they're both, you can give it either board instances, but I'm just using Formata. And then we give it the path of the USB. So if when you, ahead of time, you can check to see what serial port you'll be using. So I know I'm using this one right here. And I'm using Arduino and O, et cetera. Also, I'm going to want to upload standard Formata to the Arduino so we can communicate to it, as I was saying earlier. So I'll upload that right now. Flash, because it works. So I know the ports USB is to do our dot USB modem 1411 inside here. Yeah, and then inside this, we can just save our led equals new Josh dot led. And then we can give it the pin, which I'm on pin 13, just cause it's easy. And then we get the board instance from right here. So we can communicate in here. And then we can just say led dot give life. And then in theory, if we run node index.js, give life. Yes. There we go. We're in business. All right. Now we're talking. Okay, back to some slides. That's just gonna stay on. Can any of you see the light? Nice. All right, good. All right, next slide. Level two, cause I'm a gamer, so level two. Now we're talking about the board. And for me as a web developer, this was like extremely complex. When I opened up the Formata library, I was like, you gotta be kidding me. I saw like bit shifting, bit masking. I was like, oh my gosh, I just got overwhelmed and took me a couple of days to cool off. I was a little scared, but I decided to try and make a simple example. These are all some simple examples. Anyways, I'll be using those serial port. And just before I use that, I just wanna cover a couple definitions. One being baud rate. I'm pretty sure that's how you pronounce it. And so basically when we're gonna open in a serial port, we need to specify a couple of things. The path of the serial port, which you already saw, and then we can give it some options. I need some water, excuse me. Oh, much better. All right. The option object allows us to pass some stuff. One of the things is the baud rate. And baud rate specifies how fast the data is sent over the serial line. So usually it'll be bits per second or BPS. And baud rates can be basically like any value. The only requirement though is that both devices operate the same rate. So this is on say 9600 and this one's on 9600. The Arduino and what we're communicating with, so no. And then the most common baud rate is 9600 BPS, which is why I said that. And then also a higher baud rate goes, the faster the data is sent, received. But there are some limits to how fast you can send data, of course, in transferred. And then there's also a ton of other valid attributes for the options object. That, by the way, the options object is the notes report. That's what I was talking about. I hope I explained that. You can, I'll show you that. But anyways, there's like data bits, stop bits, like parity, buffer size. There's tons. But we'll only be using baud rate just so we can communicate with it. And we'll have another demo. Sweet. Love demos. Well, we all love demos, don't we? Oh my gosh. Okay, there it is. Sometimes a little hard to find my cursor. Sweet. So now we'll go back to demo two. And I've already installed notes to report. You know, like always. And then like I did in the last demo, I did it in all of them. And we'll need an index.js. And then we'll also need, I have some notes just in case you forget. Oh yeah. And then we'll have a formata.js. Cause we're making the formata board. Okay. Open this in sublime. What are you just gonna hit? Let's see how big that is. Is that fine? Okay. So I'll open up the formata.js. And inside here, we're gonna need to get the serial ports that are required in. And then we're gonna call the serial port. Not capitals. And then we're gonna get to port. That's just localizing the object constructor. So now we'll say joshes board again. And then we'll say port. We'll get the port. And then we'll have callback. And then inside here, we'll say our board is equal to this. And then I'm just gonna call the callback just so we can get the console log in the other one. But normally we do something different. So now we can say this, so board. We'll just do sp for serial port. And then we'll start, we'll create a new serial port. And then we'll give it the port from up here. And then we'll do a callback. So, or oops, not callback. And then in here, we give it the bot rate, which is what I was talking about earlier. And then the most common one is the 9600, which I'll be doing on the Arduino as well. So now we can say console log inside here. And you can say, you got it, coach, starting up. And we can say this is not on open. So when serial port opens, by the way, I'm using again the serial port library. So when we open it, open the function console log port. It is open. And I'll start with that for now, but it'll get better. And then we'll give it the formata instead of having the formata library requiring ours. And then we'll create a new board. I'll say fromata.joshesboard. And then we'll do the path of the USB, or the path of USB, yeah, so the Arduino, which was tty.i, can never remember. That USB modem 1411. Shoot, I just forgot, that's embarrassing. Oh, okay, thanks. Don't hate me. Okay, and then inside here, we'll, again, hold back. And then all we'll say is connected for now. So we have the model.js file, and then we have the index.js file. But now we also need to have an Arduino sketch because so now we're opening a serial port, but I want to be able to communicate, so in here we'll create a new, so right here. And all of them have void set up and void loop. And then we'll just say serial.begin, listening to 9600, the moderate speed that it's going to. Like I explained earlier. And we'll have the loop. And we'll say serial.write1, delay, and here we'll also write a zero. And what we should be getting, what the heck? I put being, thanks, thank you. What's wrong with this one? Can you guys, oh my gosh, thank you very much. Crowd saves my day, or saves me. All right, so I upload this, and now I should be writing, wow, why is it, you need to speak up if it's so small. I don't even know how to, you can't do command plus in this ID, I hate this ID to be honest, yeah, it's worse. Okay, anyways, now we should if when we open up our index, what, module.exports, wow, okay, Josh is bored. I knew something was going to happen, sorry about that. So basically we've connected, it's starting, and now it's open. And that sketch I created, I actually didn't need to create it yet, but I got a little ahead of myself. So now we can listen on that data that the sketch right here is sending, so it's writing one and then zero, and in here we can say the no-to-report library has a dot on data, that is pretty easy, and we'll say console.org-data, and we should be getting some buffers. So one, zero, one, zero, sweet. So the Arduino is writing the data, two here, and we're reading it, awesome. Okay, now I just started my own class, that was awesome. Okay, now let's get back to the presentation again. Level three, okay, so now we're talking about no-to-report, and about 80% of no-to-report is in C++ if you actually see the GitHub repo, and I won't be showing how to make no-to-report, I mean, I haven't been showing how to make each library, because of course they do tons of stuff, like they'll be using, yeah, they just do tons of stuff, tons of checking to make sure everything will work right, but I'm just showing examples. Anyways, so like I said in our last example, we're reading data from the Arduino, but this time let's write data to the Arduino, and then we'll read data from the, the Arduino will read the data that we send to it, and I showed you that we were sending buffers, and we were like, what the heck's a buffer? Well, the right, no-to-report has a write method, and basically the write method will be sending buffers, and then we can give it a callback, and basically the buffer parameter accepts this, or it'll accept a buffer object, or a type that is accepted by a buffer constructor, an example being an array of bytes, or a string, and the buffer is just like, if you use Node at all, then you'll, they have just normal buffers, so I'm not doing anything crazy, and then in our Arduino sketch, we'll turn on, we'll turn the LED on if a one is read, and then if, we'll turn the LED off if a zero is read, and then in our blinky.js, we'll just send all the bytes. Send the bytes, now there's zero one. Found this cool cat picture for demo. No reason, just because, mirror the displays, awesome. So now we're going to demo three, and again, we'll be using Node-to-report, because Node-to-report is awesome. Okay, we'll go back, and we'll create a blinky.js, and then in here, we'll open it up, and again, we're gonna wanna get the serial port, so we'll get serial port is equal to require serial port, and then we can say dot serial port. And now let's create the serial port, so serial is equal to new serial, just like we did in the last one, not the new here, yet. Let's say devcty.usbmodem1411. That's right, okay. And then go in here, and we can give it the baud rate again, 9,600. And then we'll just create a value. This could be zero, but I'm gonna make it a hex, because hexes are awesome, and it makes me look smart and stuff, so you can just send a hex to the Arduino, and it'll still just be a zero, like I could just do a zero, but hex is cool. But you will use hexes for stuff, for communicating with the Arduino, but right now there's not really a reason why I have to, but I'm going to. So then we'll create a function, blink. Basically we'll just say values equal to, then we'll say values, just so I can switch it else. Values equal to, and then we'll say serial dots, so serial's from up here, and then we'll say dot right, give it a new buffer, so node, you know, you can give it a buffer. And like I said earlier, we'll give it an array, and then we'll give it the value. Then we'll say console.log, and then we could say serial.on, serial.on, open, function, and say console.log, serial port is open, and then in here we'll also say set interval, give it the blink, and we'll just say every second. So now we have our blink.js, and we'll be writing, so instead of reading the data, we're going to be writing to the Arduino, then the Arduino will read the data, and then turn on the LED, depending if it's a zero or one, so now we'll have to create that in a new sketch, and I don't want to type that, so I'm just going to take this out. But again we'll begin it the, how do I even make this bigger? Can you all see that? Is that fine? What? Ah, great. What? That's search, yeah. Look at this. Woo, magic! Nice, I know what I'm doing. Okay, oh my gosh, that was good. Okay, we'll create a const outside, and then this will just be our output pin, or output pin, oh my gosh. And this is 13. The one I was on, so. And then our setup, again we'll just say pin mode, and then we'll give it the output pin. I couldn't, I could have just put 13, but just, yeah. And then we'll give it the output. This is what I was talking about earlier, you can give it an input, output, input pull up, et cetera. And then in our loop we'll say incoming bytes is equal to serial.read, instead of write, we're reading now, and then we'll say if incoming byte is equal to one, then we'll digital write, which I told you about earlier, that you can give it a pin, and either high or low to turn on the LED. So we'll give it the pin, and then we'll just say hi. Oh my gosh, now I gotta go down. Doot, doot, doot, doot. Oh, I could have just moved that up, oops, I'm smart. And then in our if we'll say else, incoming byte is equal to, then here we can just say digital write, output pin. So now we are, let me zoom out a little. In our setup, we get the pin, set the pin mode, and then we begin listening on 9600, and if any bytes are coming that are a one, then turn on the LED, and if it's a zero, then we'll turn off the LED, so it'll just make it blink. So we'll upload that to the Arduino, and then we'll do blinky.js, starting to report it's open, and it blinks, woo! Thank you, thank you. All right, that was awesome. I'll just leave it blinking for now, cause it's cool. Sweet. Okay, let's stop mirroring for now, and we'll go back to the slides. Gonna see the awesome cat again. Okay, now I just wanna talk there a little bit about this. So Adafruit, you can buy hardware and stuff from them, and they have tons of libraries out there that just don't have no JS counterparts, or they don't have anything that you can write JavaScript to, so for instance, like I was saying earlier, my white tiles app, or not app, well the game that I made with hardware, I was using NeoPixel, they have a library NeoPixel, and I wanted to use JavaScript, but I didn't know of any counterpart to NeoPixel that I can control the lights with with JavaScript, so I wasn't sure, and there's just a ton of libraries out there that they have that need no JS counterparts, and so I'm gonna start trying and making new libraries that will be no JS counterparts to them, so we can write JavaScript to communicate with the Arduino and use other libraries, and there is one downside though I wanna say using JavaScript is you have to run Node, and instead of having an Arduino sketch, if you just give the Arduino power, then it'll automatically run, but if you run Node, or I mean if you don't run Node, then of course it won't run, so there's just some downsides, but JavaScript's awesome, so we all wanna write JavaScript, and that's my talk. Thanks. Do I have extra time? I'm sure I do. I didn't wanna take questions, because I'm sure you guys are gonna ask me tons of crazy questions, but I'll take some. Do you have any questions to make me look dumb? Oh no, Murphy, be nice. It made me excited interacting with the real world and making a game that I can play with, like buttons and show other people, like I could just transport it anywhere and then just give it power was awesome feeling, like and then playing a game, so I definitely got excited, and I still wanna make more, and that's what I was saying, I wanna make libraries their counterpart to the Arduino ones, so that I can control using Node to control NeoPixels lights that they have, or control all this stuff that they have, so I got excited for sure, but I don't know if everyone else would. Oh, Ryan? Oh man, yeah, prom is coming up. I don't know what I'm gonna make. Oh yeah, I'll let you know. So, like I said earlier, I bought an Arduino a long time ago, and then I totally broke it, so I need to flash it again, because I don't even know what I was doing. I was just like, you know, there's that dog gift that I don't know what I'm doing, that's basically what I mean with my Raspberry Pi, but I know that the Arduino has tons of libraries, and JavaScript has, you know, they have Johnny Five and stuff, but Raspberry Pi, I'm not really sure how it compares to the Arduino, so I'm sorry, I can't really answer that, but it's awesome. What does that for five mean again? It's like C plus plus C, yeah, it's like a variation, so probably, I'm not really sure. That's why I said I haven't made an actual, like I haven't made transferred Arduino code to JavaScript, yeah, but that's what I wanna do after this conference, so I'm sorry I can't answer you, but yeah.