How to Program the LEDs on the Inventor Board

This lesson will go over the LEDs found on PINS(11~18)

First, begin the code by assigning Global Variable Names for the pins that you will be using. Create some space in your sketch by placing your cursor before the void setup method and pressing the enter key.

This process will assign each pin a specific variable name.

int name = pin_number;
int LEDPIN11 = 11;

Repeat this process for pins 11 through 18, your code should resemble the following

int LEDPIN11 = 11;
int LEDPIN12 = 12;
int LEDPIN13 = 13;
int LEDPIN14 = 14;
int LEDPIN15 = 15;
int LEDPIN16 = 16;
int LEDPIN17 = 17;
int LEDPIN18 = 18;

After assigning  names for each of the pins, place your cursor inside of the void setup method, after the comment. This section will go over how to use the pinMode()function.

pinMode( )

pinMode( name of the declared pin, pin assigned as either an INPUT or OUTPUT );

When a pin is declared as an INPUT, this means that the component takes in/reads information and are generally associated with components such as sensors.

When a pin is declared as an OUTPUT, this means that the component performs an action.

Now use pinMode() to assign the first LED, LEDPIN11, as an OUTPUT.

pinMode(LEDPIN11,OUTPUT);

Lights do not take in or read information, therefore it is assigned as an OUTPUT. Continue using pinMode() to assign the other pins from 12-18. The sketch should look like the following

pinMode(LEDPIN11,OUTPUT);
pinMode(LEDPIN12,OUTPUT);
pinMode(LEDPIN13,OUTPUT);
pinMode(LEDPIN14,OUTPUT);
pinMode(LEDPIN15,OUTPUT);
pinMode(LEDPIN16,OUTPUT);
pinMode(LEDPIN17,OUTPUT);
pinMode(LEDPIN18,OUTPUT);

Next, place the cursor within the method void loop(). Code created in this method will continually run once the last part of the code is executed. One should only place code here if the action is expected to be repeated.

The next section will use the function digitalWrite() and delay()

digitalWrite( );

digitalWrite( name of the declared pin, pin state either HIGH or LOW );

When an LED’s state is declared as HIGH, the LED will turn on.

//Sets the LED's state to HIGH and will turn the LED on
digitalWrite(LEDPIN11,HIGH);

When the LED’s state is LOW, the LED will turn off.

//Sets the LED's state to LOW and will turn the LED off
digitalWrite(LEDPIN11,LOW);
delay( )

delay( time in milliseconds );

delay()is a function that will define how long an action should be performed. There are 1000 milliseconds in 1 second. This means that if the action should run for 3 seconds, the time entered in the delay() should be 3000.

delay(3000);

Final Code

//declares global variables used in the code
int LEDPIN11 = 11;
int LEDPIN12 = 12;
int LEDPIN13 = 13;
int LEDPIN14 = 14;
int LEDPIN15 = 15;
int LEDPIN16 = 16;
int LEDPIN17 = 17;
int LEDPIN18 = 18;


void setup() {
//pin assignments            
pinMode(LEDPIN11, OUTPUT);
pinMode(LEDPIN12, OUTPUT);
pinMode(LEDPIN13, OUTPUT);
pinMode(LEDPIN14, OUTPUT);
pinMode(LEDPIN15, OUTPUT);
pinMode(LEDPIN16, OUTPUT);
pinMode(LEDPIN17, OUTPUT);
pinMode(LEDPIN18, OUTPUT);

}

void loop() {
//Sets the LED state to HIGH
digitalWrite(LEDPIN11,HIGH);
digitalWrite(LEDPIN12,HIGH);
digitalWrite(LEDPIN13,HIGH);
digitalWrite(LEDPIN14,HIGH);
digitalWrite(LEDPIN15,HIGH);
digitalWrite(LEDPIN16,HIGH);
digitalWrite(LEDPIN17,HIGH);
digitalWrite(LEDPIN18,HIGH);
delay(1000);

//Sets the LED state to LOW
digitalWrite(LEDPIN11,LOW);
digitalWrite(LEDPIN12,LOW);
digitalWrite(LEDPIN13,LOW);
digitalWrite(LEDPIN14,LOW);
digitalWrite(LEDPIN15,LOW);
digitalWrite(LEDPIN16,LOW);
digitalWrite(LEDPIN17,LOW);
digitalWrite(LEDPIN18,LOW);
delay(1000);

}

Next, try turning the LEDs on and off at various times to create your own light show!