17. 1 | Get an Arduino & USB cable
Sunday, May 4, 14
18. | Prepare to test Arduino board
- Arduino
- LED Blink
File > Examples > Basic > Blink
Sunday, May 4, 14
19. | Set up your board
• : Tools > Board
[ Mac OS X ]
[ Mac OS X ]
• Arduino serial port: Tools > Serila Port
Mac /dev/tty.usbserial- *
[ Windows ]
[ Windows ]
Sunday, May 4, 14
20. | Upload the program
Vertify
Update to board*
* Arduino NG Reset Update Arudino Reset
Reset Update
TX/RX LED
2~3
Pin13 pin
( )
• File > Examples > Basic > Blink
•
• ....
Sunday, May 4, 14
21. # | Troubleshooting
• Serial port
•
• Serial Port Serila port
• Jump Duemilanove/UNO
• Reset Reset Update
• Arudino USB
•
Sunday, May 4, 14
30. • Only 1 or 0 / High or LOW / ON or OFF
HIGH
LOW
1
0
Sunday, May 4, 14
31. 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)
#1 File > Examples > Basic > Blink
Sunday, May 4, 14
32. LED
pin ?
( ) pin?
pinMode(who, ?)
( )
digitalWrite(who,?)
Sunday, May 4, 14
36. #6 | Button #6 File > Examples > Digital > Button
Sunday, May 4, 14
37. 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);
}
}
#6 File > Examples > Digital > Button
Sunday, May 4, 14
44. int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
}
void loop() {
// set the brightness of pin 9:
analogWrite(9, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
#4 File > Examples > Basic > Fade
Sunday, May 4, 14
54. int ledPin = 13; // LED connected to digital pin 13
int analogPin = 0; // photocell connected to analog pin 0
int val = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
val = analogRead(analogPin); // read the value from the sensor
if(val<80) {
digitalWrite(ledPin, HIGH); // sets the LED on
}
else {
digitalWrite(ledPin, LOW); // sets the LED off
}
delay(50);
}
#10 http://code.mutienliao.tw/arduino/analog_control.pde
Sunday, May 4, 14
55. int ledPin = 13; // LED connected to digital pin 13
int analogPin = 0; // photocell connected to analog pin 0
int val = 0;
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}
void loop()
{
val = analogRead(analogPin); // read the value from the sensor
Serial.println(val);
if(val<80) {
digitalWrite(ledPin, HIGH); // sets the LED on
}
else {
digitalWrite(ledPin, LOW); // sets the LED off
}
delay(50);
}
#10 analogRead
#10 http://code.mutienliao.tw/arduino/analog_control.pde
Sunday, May 4, 14
56. Arduino Software Serial Monitor Arduino
546756456575456745674567447
baud rate
Sunday, May 4, 14
58. const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("t output = ");
Serial.println(outputValue);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
#11 File > Examples > Analog > AnalogInOutSerial
Sunday, May 4, 14