0% found this document useful (0 votes)
9 views8 pages

Lesson 2 - Blink BASIC

Blink on arduino

Uploaded by

kesjay20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Lesson 2 - Blink BASIC

Blink on arduino

Uploaded by

kesjay20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Arduino

Default code

// Pin 13 has an LED connected on most Arduino boards.


// give it a name:
int led = 13; //declare a variable to hold values – output to LED

// the setup routine runs once when you press reset:


void setup() { //start brace
pinMode(led, OUTPUT); // initialize the digital pin as an output.

} //end brace

// the loop routine runs over and over again forever:


void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Verify - to check your code.

Upload – Uploads or sends your code to the Arduino CPU and RUNs
BLINKS ON (HIGH) AND OFF (LOW)

Since we know this works this can serve as a quick test to see your code uploaded actually working on
the Arduino board. Normally we would connect an external LED to test the Digital Out of pin 13 to
extend this exercise but the UHS Mega boards kits do not have pin 13 connected to the ethernet cables.
Note you can rewrite you code as below without the use of variables (ok for now but it is not good
programming style or practice for more complex programs)

//Notice no variables
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
// Change to Pin 9 as UHS Arduino system start Digital I/O from PIN # 9.
// give it a name:
int led = 9;

// the setup routine runs once when you press reset:


void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Now lets add a 2nd LED and attach to pin 7

void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}
Notice again you should have pin 7 and 9 (replaces 13) on your board.

void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
pinMode(13,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
}

What happened….?
void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
pinMode(13,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
}

void setup() {
// put your setup code here, to run once:
pinMode(7, OUTPUT);
pinMode(13,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(7, LOW); // turn the LED off by making the voltage LOW
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
}

You might also like