Lesson 2 - Blink BASIC
Lesson 2 - Blink BASIC
Default code
} //end brace
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;
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
}