231a-ad lab4
Code Examples from Lab 4
Blink
/*
* Blink
*
* The basic Arduino example. Turns on an LED on for 1/10 of a second,
* then off for 9/10 of a second, and so on... We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*
* http://www.arduino.cc/en/Tutorial/Blink
*/
int ledPin = 13; // LED connected to digital pin 13
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(100); // waits for 1/10 of a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(900); // waits for 9/10 of a second
}
HelloWorld!
/*
* Hello World!
*
* This is the Hello World! for Arduino.
* It shows how to send data to the computer
*/
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop() // run over and over again
{
Serial.println("Hello world!"); // prints hello with ending line break
}
RickRoll
/*
* Rick Roll!
*
* Teaching the Arduino internet pranks.
* This will print out the lyrics to that song that
* may or may not be always getting stuck in your
* head thanks to current trolling fads.
*/
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop() // run over and over again
{
Serial.println("Never gonna give you up!"); // prints lyrics with ending line break
delay(1500); // do nothing!
Serial.println("Never gonna let you down!"); // prints lyrics with ending line break
delay(1500); // do nothing!
Serial.println("Never gonna turn arouuuuund and..."); // prints lyrics with ending line break
delay(2000); // do nothing!
Serial.println("DESERT YOU!"); // prints lyrics with ending line break
delay(2000); // do nothing!
}