Check out a free preview of the full Nodebots / Hardware course:
The "Getting an LED to Blink" Lesson is part of the full, Nodebots / Hardware course featured in this preview video. Here's what you'd learn in this lesson:

Steve walks through the Tessel 2 JavaScript library, demonstrating how to get a built-in LED to blink.

Get Unlimited Access Now

Transcript from the "Getting an LED to Blink" Lesson

>> Steve Kinney: All right, so at this point, we have everything set up, so let's actually open up the repo, the Steve Kinney Nodebots Workshop. And I have a few files kind of ready to go. The first one we'll play with is Tessel intro. And it's actually taken from the Tessel Project itself.

[00:00:21] And it shows what it looks like to work with the Tessel directly without Johnny-Five. And we'll look at Johnny-Five and all the really cool things it offers us later. But this is a very simple example that we can see just using straight Tessel code. So we wanna deploy it to our device.

[00:00:36] There's two options, we can actually send the code to our device that means that anytime it has power, it will run that code. Or we can just run it as we're developing which will basically, as long as we keep the terminal process open on our computer, it'll run a device.

[00:00:52] And when we hit Ctrl + C, it will stop running on the device which, is what we're gonna use for most people. When your masterpiece is done and you're ready to install it somewhere and do a thing, that would be when you actually deploy the code to your device.

[00:01:05] So I'm gonna go over to my terminal again. Just clear it real quick. I'm just gonna type in t2. And so you can kind of see some of the different commands that are available. And so run will actually run it from our computer onto the device. So it will deploy onto the device but we'll still be connected.

[00:01:22] We'll see all of the different results in our terminal. And as soon as we kill the process, it will stop running on the device, as well. But, if we can actually push it to the device, as well. And there are a bunch of other fun stuff like erasing the Tessel, listing all the Tessels.

[00:01:40] We've played with some of these previously. Cool, so what we're gonna do is we're gonna run that initial file. So I'm just gonna do a t2 run and then my directory is just 00. So t2 run 00-tessel-intro. I'll let that go and we'll just actually see what happens here.

[00:01:59] So it's gonna look for my tessel. Hopefully it finds the right one. Cool, mine is connected to RobotComputer because I exported that variable. If you're watching this later or working at home, probably it's already defaulting to the correct one. But for those of us in the room, we need to make sure that we're not deploying to other people's Tessels.

[00:02:17] Likely won't work because of the provisioning with the public and the private keys. Your code won't start running on somebody else's device, it will just not work. Cool, and so it's writing to the RAM on RobotComputer. It's gonna run that code. Cool, so at this point, we can see the two LEDs blinking on the device, which means we have successfully run our first few lines of JavaScript on a Tessel.

[00:02:40] Good job, everyone. And with that, I can now kill the process, and we should see the LEDs. They're going to stop blinking depending on what tenth of second you hit CTRL + C they will either remain on or they will now be off. So if you see them stay on that's just simply a 50/50 chance.

[00:02:59] The one thing I would like you to do is, we go to the code.
>> Steve Kinney: We can take one of these.
>> Steve Kinney: And there's a bunch of methods that we could use. Toggle will basically change the state from on to off. There's two other methods. One of them is dot on which will turn the LED on.

[00:03:28] The other one is dot off, which will turn the LED off. What I would like you to do is pick one, either two or three, whichever one makes you happiest, and go ahead and start it in the on position and take the other one. They should default to off, but.

>> Steve Kinney: And put it to the off position. So now they'll start. One of them will be on and one of them will be off. And then we're going to run and deploy this code again. So you won't see it on this device yet on the screen. There it goes.

[00:04:03] It was still deploying the code from my computer. But now you can see I'm alternating between the two LEDs on the device. So we started one in the on position and one in the off position, and now as we toggle them, they are kinda alternating back and forth.