-

Introduction to Arduino Programming 4: Blinky’s revenge

Introduction to Arduino Programming

A series of based on New York University’s Introduction to Computer Programming class from the Courant Institute of Mathematical Sciences.

This is intended as a “gentle” introduction to computer programming and Arduino. The only prerequisite is that you’ve completed our Arduino Basics guide!

Blinky’s revenge.

As in the other tutorial, while we level up our skills we’ll talk less and code more!

This program will let us light up our bargraph Bit and make it blink.

 

The code!




Don’t Delay!

So since we’re pros at input and output. Now let’s start stretching our coding chops!

In order to make our bargraph blink, we will need turn it off and on. In order to do that we need to call a function named delay() and pass in a number (in this case an integer) that will stop our program for however many milliseconds we like between changing state of the light from on to off. We’ve set it at 1000 feel free to change that number and play around with it!

The delay() function will pause our program and the Arduino Bit for however many milliseconds we want!

1) We set our analogWrite() function to 0, turning our bargraph off.

2) Let’s add some delay!


3) Then we turn on our bargraph by setting the number to 1023.


4) Let’s add some (more) delay!


One key thing to note is that our bargraph variable is an integer that is assigned to just 5 NOT d5.

 

Troubleshooting

Let’s flash our Arduino! (no, not that kind of flashing)

Once you’ve typed up the sample code, hit the upload button found in the tool bar. It looks like this: ❤

❤

This will flash the memory in our Arduino so it can run our program!

TL;DR

More Tips & Tricks

Tips & Tricks
Friday’s Tips & Tricks: Latch

Use the latch to turn any momentary input, like a button or a trigger module, into an ON/OFF switch, like a toggle!

Tips & Tricks
DC motor (tethered)

Note: These tips and tricks correspond with the DC motor (tethered). If you have the previous version of the DC motor Bits [o5], c...

Tips & Tricks
Synth Tips & Tricks: Record your Music

When you make sweet beats with the Synth Kit, you might want to record them and share with your friends. This is a basic overview ...