User Menu

Brain Board: Blink Buzz’s Eyes – Your First Brain Board Program (Preview)

This is a preview lesson. Please sign up for the course to access all lessons.

This will be our first Brain Board program and in this lesson we will learn how to control Buzz’s eyes. We will also identify the pinouts of the Brain Board. This lesson would work if you used Chip on the Brain Board as well.

Buzz & Chip

Gather your Hardware and USB Cable

What you will need for this lesson:

  • Buzz or Chip
  • Brain Board
  • USB Cable
  • Arduino IDE installed with support libraries for the Brain Board.

Code Challenge

Read the code to the right. What to you think it does? If you don’t know, it is ok.  Just try it.


int rEye = 1;

int lEye = 4;

void setup(){ 

pinMode(rEye, OUTPUT);

pinMode(lEye, OUTPUT); }

void loop(){ 

digitalWrite(rEye, HIGH);

digitalWrite(lEye, HIGH);

delay (1000);

digitalWrite(rEye, LOW);

digitalWrite(lEye, LOW);

delay (1000); }

Did you figure it out? Great! Lets step through that code again, this time with some comments that explain what each section does.  The “//” signifies a comment. A comment is ignored by the Brain Board. Comments are there for us humans, to make code more readable. Read through the code on the right again.

// Buzz has 4 pins, 3 we will use for this lesson
// 
// Ground (GND) 
// Right Eye LED (1) 
// Left Eye LED (4) 


// We need to define Buzz's eyes so we can use them in our code
int rEye = 1; //define right eye as pin 1 on the Brain Board (for Arduino UNO use Pin 10)
int lEye = 4; //define right eye as pin 4 on the Brain Board (for Arduino UNO use Pin 11)

// Next we need to initialize the pins for output
// setup() only runs once when you power on or reset an Arduino

void setup(){
pinMode(rEye, OUTPUT); //set right eye for output
pinMode(lEye, OUTPUT); //set left eye for output
}

//loop() runs forever - this is our main code
void loop(){

// turn both eyes on. HIGH means set voltage to HIGH
digitalWrite(rEye, HIGH);
digitalWrite(lEye, HIGH);

delay (1000); //wait for 1 second. Delay is set in miliseconds or 1/1000 of a second

// turn right eye off. LOW means set voltage to LOW.
digitalWrite(rEye, LOW);
digitalWrite(lEye, LOW);

delay (1000); //wait for 1 second. Delay is set in miliseconds or 1/1000 of a second
// we are at end of loop - we go back to line 21
}

Let’s write our first sketch

  • Launch the Arduino IDE.
  • Start a new sketch. On the Arduino menu go to FILE -> NEW
  • Copy the code from the example sketch above. Paste into your Arduino IDE sketch.
  • Save the sketch. File -> SAVE (name it something such as sketch_Buzz_Blink)
  • Under TOOLS – > Board, make sure you have selected the “Digispark (Default 16.5mhz)”

Arduino Verify

Verify the Sketch – click on the check mark icon. This will verify that your code does not have any syntax or procedural errors. However, it does not verify that your code will do what you want. That is up to you.

If the code is ok, you will not see an errors. If there are any errors, double check that you did not miss anything when you copied it from the above example.

 

sketch_Chip_Blink Arduino upload

Brain Board Upload

You are ready to upload the code from your computer to the Brain Board.

Disconnect the Brain Board from USB.

Click the Upload Icon arrow, which is next to the verify button.

When prompted, plug in the Brain Board to USB.

After the upload is successful, Buzz should be blinking.  Congrats!

Try these challenges.

What happens with if you change the delay to larger or smaller values?

delay (1000);

What happens with if you change put a delay in a different spot? Try different variations, different values.

digitalWrite(rEye, HIGH);
delay (1000);
digitalWrite(lEye, HIGH);
delay (1000);
digitalWrite(rEye, LOW);
delay (1000);
digitalWrite(lEye, LOW);
delay (1000);

 

Don’t forget to verify and upload your code after each change. Also, don’t forget to unplug the Brain Board before uploading your sketch.
Play around, you can not break anything. You can always re-copy and upload the original sketch.

Access all the code for The Brain Board and The Pi Pals

GitHub is a website where you can store, share, and manage code for projects. We use it store all the code for our lessons so that it is easy for you to download. If you have code you would like to contribute, please do so. You can access Soldering Sunday’s Github Repository here

Lesson tags: Arduino, Brain Board, Buzz, Chip
Back to: Brain Board