15. Digital In Digital Out Communication
Emotion Experience
Analog In Analog Out
16. | Prepare to test Arduino board
- Arduino
- LED Blink
File > Examples > Basic > Blink
17. | Set up your board
• : Tools > Board
[ Mac OS X ] [ Windows ]
• Arduino serial port: Tools > Serila Port
[ Mac OS X ] [ Windows ]
Mac /dev/tty.usbserial- *
24. HIGH 1
LOW 0
• Only 1 or 0 / High or LOW / ON or OFF
25. #1 File > Examples > Basic > Blink
int ledPin = 13; // LED connected to digital pin 3
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
pinMode(pin, Mode) digitalWrite(pin, value) delay(ms)
28. #2 File > Examples > Control > ForLoopIteration
int timer = 100; // The higher the number, the slower the timing.
void setup()
{
int i;
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin <= 7; thisPin++ ) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin <=7 ; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = 7; thisPin >= 2; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
39. #6 File > Examples > Digital > Button
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}