SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
阿爾杜伊諾
     Arduino: Lv. 1




Mutienliao.TW    , 2013-03-18
Arduino
Introduction
Human Computer Interactive / Interface ??
physical computing system
What is Arduino?
Open Source
Arduino Hardware   Arduino Software   Physical Computing Platform & Group
•                    14          Digital Pins 0-13                •   Reset      - S1
•   Digital Pins 0-1/Serial In/Out - TX/RX                        •
    -              Serial port                         Pin 0,1.   •           Jumper       USB        DC   (Duemilanove   )
•              6        Analog Input Pins 0-5                     •   USB
•            Analog Output * (Digital Pins 3,5,6,9,10,11)         •            Vin, 5V, 3.3V (Diecimila     )
各式各樣的Arduino........族繁不及備載
Digital Out   Digital In   Analog In   Analog Out   Communication
Digital Out
Analog Out
Digital In
Analog In
Communication
Digital In    Digital Out   Communication




Emotion   Experience
                              Analog In      Analog Out
| Prepare to test Arduino board




-      Arduino

-       LED Blink
    File > Examples > Basic > Blink
| Set up your board
•                      : Tools > Board




                 [ Mac OS X ]                                       [ Windows ]




•    Arduino         serial port:             Tools > Serila Port




                 [ Mac OS X ]                                        [ Windows ]
           Mac          /dev/tty.usbserial-     *
| Upload the program
| Upload the program




                                                                          Vertify
  •       File > Examples > Basic > Blink

  •

  •            ....
                                                                      Update to board*




                                                                                    TX/RX LED




                                                                                                       2~3
                                                                                         Pin13   pin
                                                                                    (                   )



* Arduino NG                           Reset   Update   Arudino   Reset
                                  Reset        Update
# | Troubleshooting




•                          Serial port

•

• Serial Port                             Serila port

•               Jump                              Duemilanove/UNO

•                                 Reset                         Reset   Update

•                Arudino                         USB

•
breadborad
Digital Out




              Digital Out
#1 | Blink
HIGH                            1

           LOW                            0


• Only 1 or 0 / High or LOW / ON or OFF
#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)
LED


              pin ?


(      )            pin?
    pinMode(who, ?)

      (        )
    digitalWrite(who,?)
#2 | Loop
#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);
    }
}
#Bonus | Light Talk
#Bonus                          http://mutienliao.tw/arduino/Light_Talk.pde

  int pins[] = { 2, 3, 4, 5, 6, 7 }; !!         // LED
  int lights = 6;                  ! !          // LED
  int pattens = 10;                ! !          //
  byte graphy[10][6] = { {0,1,1,1,0,0},
                         {1,1,1,1,0,0},
                         {1,1,1,1,1,0},
                         {0,1,1,1,1,0},
                         {0,0,1,1,1,1},
                         {0,0,1,1,1,1},
                         {0,1,1,1,1,0},                                                        [a]
                         {1,1,1,1,1,0},
                         {1,1,1,1,0,0},
                         {0,1,1,1,0,0} };       !
                                                //

  void setup()
  {
    for (int i = 0; i < lights; i++)    !       //                      0    light-1
      pinMode(pins[i], OUTPUT);      !!         //
  }

  void loop()
  {
    for(int k = 0; k < lights; k++) { !         //
      digitalWrite(pins[k], LOW);
    }                                                                                          [b]
    delay(40); !             !       !          //       40

      for (int i = 0; i < pattens; i++) { !     //              ...                    Fig.1
        for(int j = 0; j < lights; j++) {!      //            LED...
          if(patten[i][j]==1) {
            digitalWrite(pins[j], HIGH);    !   //                     LED
          }else {
            digitalWrite(pins[j], LOW);     !   //                     LED
          }
        }
        delay(1);                  !    !       //       1
      }

      for(int k = 0; k < lights; k++) {   !     //
        digitalWrite(pins[k], LOW);
      }
      delay(40);!              !        !       //       40
  }
byte graphy[10][6] = { {0,1,1,1,0,0},
                       {1,1,1,1,0,0},
                       {1,1,1,1,1,0},
                       {0,1,1,1,1,0},
                       {0,0,1,1,1,1},
                       {0,0,1,1,1,1},
                       {0,1,1,1,1,0},
                       {1,1,1,1,1,0},
                       {1,1,1,1,0,0},
                       {0,1,1,1,0,0} };   !
#3 | Blink Without Delay
#3                  File > Examples > Digital > BlinkWithoutDelay




const int ledPin =      13;         //    pin 13   LED

int ledState = LOW;                 //             LED
long previousMillis = 0;            //

long interval = 1000;               //                           1000ms = 1sec

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  unsigned long currentMillis = millis();                   //

    if(currentMillis - previousMillis > interval) {         //

        previousMillis = currentMillis;                     //

        //    LED
        if (ledState == LOW)
           ledState = HIGH;
        else
           ledState = LOW;

        //    LED
        digitalWrite(ledPin, ledState);
    }
}
Delay()    :




millis()   :
輸入才是互動的精華
Digital In




         Digital Input
#6 | Button
#6 | Button
#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);
    }
}
#7 | StateChangDetection   #7   File > Examples > Digital > StateChangDetection
#8 | Debounce   #7   File > Examples > Digital > Debounce
#|




     1

     2

     3

     4

Mais conteúdo relacionado

Mais procurados

Arduino Full Tutorial
Arduino Full TutorialArduino Full Tutorial
Arduino Full Tutorial
Akshay Sharma
 

Mais procurados (20)

2015-10-21 - Arduino workshop
2015-10-21 - Arduino workshop2015-10-21 - Arduino workshop
2015-10-21 - Arduino workshop
 
Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 2 - Interactive Media CS4062 Semester 2 2009
 
Arduino Lecture 4 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 4 - Interactive Media CS4062 Semester 2 2009Arduino Lecture 4 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 4 - Interactive Media CS4062 Semester 2 2009
 
Arduino
ArduinoArduino
Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Arduino electronics cookbook
Arduino electronics cookbookArduino electronics cookbook
Arduino electronics cookbook
 
Ardublock tutorial
Ardublock tutorialArdublock tutorial
Ardublock tutorial
 
Arduino spooky projects_class1
Arduino spooky projects_class1Arduino spooky projects_class1
Arduino spooky projects_class1
 
NSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and ArduinoNSTA 2013 Denver - ArduBlock and Arduino
NSTA 2013 Denver - ArduBlock and Arduino
 
Arduino Platform with C programming.
Arduino Platform with C programming.Arduino Platform with C programming.
Arduino Platform with C programming.
 
Lesson sample introduction to arduino
Lesson sample   introduction to arduinoLesson sample   introduction to arduino
Lesson sample introduction to arduino
 
Arduino Full Tutorial
Arduino Full TutorialArduino Full Tutorial
Arduino Full Tutorial
 
Ardui no
Ardui no Ardui no
Ardui no
 
Intro to Arduino
Intro to ArduinoIntro to Arduino
Intro to Arduino
 
Making things sense-Day 2 (May 2011)
Making things sense-Day 2 (May 2011)Making things sense-Day 2 (May 2011)
Making things sense-Day 2 (May 2011)
 
Multi Sensory Communication 1/2
Multi Sensory Communication 1/2Multi Sensory Communication 1/2
Multi Sensory Communication 1/2
 
Introduction to Arduino Programming
Introduction to Arduino ProgrammingIntroduction to Arduino Programming
Introduction to Arduino Programming
 
Intro to Arduino.ppt
Intro to Arduino.pptIntro to Arduino.ppt
Intro to Arduino.ppt
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Aurdino presentation
Aurdino presentationAurdino presentation
Aurdino presentation
 

Destaque (6)

Hacking into IoT using JavaScript
Hacking into IoT using JavaScriptHacking into IoT using JavaScript
Hacking into IoT using JavaScript
 
Ertzaintza - Police: security information points of interest for visitors to ...
Ertzaintza - Police: security information points of interest for visitors to ...Ertzaintza - Police: security information points of interest for visitors to ...
Ertzaintza - Police: security information points of interest for visitors to ...
 
OpenStack Dashboard - Diablo
OpenStack Dashboard - DiabloOpenStack Dashboard - Diablo
OpenStack Dashboard - Diablo
 
Foss, the Cloud Engine
Foss, the Cloud EngineFoss, the Cloud Engine
Foss, the Cloud Engine
 
Introduction to Alfresco
Introduction to AlfrescoIntroduction to Alfresco
Introduction to Alfresco
 
物聯網概論 - Arduino
物聯網概論 - Arduino物聯網概論 - Arduino
物聯網概論 - Arduino
 

Semelhante a Arduino: Intro and Digital I/O

Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduino
Sravanthi Sinha
 

Semelhante a Arduino: Intro and Digital I/O (20)

Programming arduino makeymakey
Programming arduino makeymakeyProgramming arduino makeymakey
Programming arduino makeymakey
 
arduinoSimon.ppt
arduinoSimon.pptarduinoSimon.ppt
arduinoSimon.ppt
 
arduinoSimon.ppt
arduinoSimon.pptarduinoSimon.ppt
arduinoSimon.ppt
 
arduinoSimon.ppt
arduinoSimon.pptarduinoSimon.ppt
arduinoSimon.ppt
 
Introduction to Arduino Microcontroller
Introduction to Arduino MicrocontrollerIntroduction to Arduino Microcontroller
Introduction to Arduino Microcontroller
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
 
arduino.ppt
arduino.pptarduino.ppt
arduino.ppt
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
 
Introduction to Arduino and Circuits
Introduction to Arduino and CircuitsIntroduction to Arduino and Circuits
Introduction to Arduino and Circuits
 
Arduino workshop
Arduino workshopArduino workshop
Arduino workshop
 
P-Space Arduino/Genuino day 2016
P-Space Arduino/Genuino day 2016P-Space Arduino/Genuino day 2016
P-Space Arduino/Genuino day 2016
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
 
Powerful Electronics with Arduino
Powerful Electronics with ArduinoPowerful Electronics with Arduino
Powerful Electronics with Arduino
 
Magnetic door lock using arduino
Magnetic door lock using arduinoMagnetic door lock using arduino
Magnetic door lock using arduino
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
 
Simply arduino
Simply arduinoSimply arduino
Simply arduino
 
67WS Event FIO Primer
67WS Event FIO Primer67WS Event FIO Primer
67WS Event FIO Primer
 
Arduino and Robotics
Arduino and RoboticsArduino and Robotics
Arduino and Robotics
 
Arduino Boot Camp Pitch Slides
Arduino Boot Camp Pitch SlidesArduino Boot Camp Pitch Slides
Arduino Boot Camp Pitch Slides
 

Mais de June-Hao Hou (12)

Processing Basics 1
Processing Basics 1Processing Basics 1
Processing Basics 1
 
Arduino: Analog I/O
Arduino: Analog I/OArduino: Analog I/O
Arduino: Analog I/O
 
跨領域設計
跨領域設計跨領域設計
跨領域設計
 
ETH+NCTU workshop 0419 Kyle
ETH+NCTU workshop 0419 KyleETH+NCTU workshop 0419 Kyle
ETH+NCTU workshop 0419 Kyle
 
ETH+NCTU workshop 0412 ETH
ETH+NCTU workshop 0412 ETHETH+NCTU workshop 0412 ETH
ETH+NCTU workshop 0412 ETH
 
ETH+NCTU workshop 0412 Kyle group
ETH+NCTU workshop 0412 Kyle groupETH+NCTU workshop 0412 Kyle group
ETH+NCTU workshop 0412 Kyle group
 
ETH+NCTU workshop 0412 MS
ETH+NCTU workshop 0412 MSETH+NCTU workshop 0412 MS
ETH+NCTU workshop 0412 MS
 
Taiwanese Tea culture
Taiwanese Tea cultureTaiwanese Tea culture
Taiwanese Tea culture
 
ETH_NCTU_Workshop_0405_Kyle
ETH_NCTU_Workshop_0405_KyleETH_NCTU_Workshop_0405_Kyle
ETH_NCTU_Workshop_0405_Kyle
 
ETH_NCTU_Workshop_0405_MS
ETH_NCTU_Workshop_0405_MSETH_NCTU_Workshop_0405_MS
ETH_NCTU_Workshop_0405_MS
 
ETH_NCTU_Workshop_0329
ETH_NCTU_Workshop_0329ETH_NCTU_Workshop_0329
ETH_NCTU_Workshop_0329
 
Design Collaboration: Harvard-NCTU Experiences
Design Collaboration: Harvard-NCTU ExperiencesDesign Collaboration: Harvard-NCTU Experiences
Design Collaboration: Harvard-NCTU Experiences
 

Último

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

Arduino: Intro and Digital I/O

  • 1. 阿爾杜伊諾 Arduino: Lv. 1 Mutienliao.TW , 2013-03-18
  • 3. Human Computer Interactive / Interface ??
  • 6. Open Source Arduino Hardware Arduino Software Physical Computing Platform & Group
  • 7. 14 Digital Pins 0-13 • Reset - S1 • Digital Pins 0-1/Serial In/Out - TX/RX • - Serial port Pin 0,1. • Jumper USB DC (Duemilanove ) • 6 Analog Input Pins 0-5 • USB • Analog Output * (Digital Pins 3,5,6,9,10,11) • Vin, 5V, 3.3V (Diecimila )
  • 9. Digital Out Digital In Analog In Analog Out Communication
  • 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- *
  • 18. | Upload the program
  • 19. | Upload the program Vertify • File > Examples > Basic > Blink • • .... Update to board* TX/RX LED 2~3 Pin13 pin ( ) * Arduino NG Reset Update Arudino Reset Reset Update
  • 20. # | Troubleshooting • Serial port • • Serial Port Serila port • Jump Duemilanove/UNO • Reset Reset Update • Arudino USB •
  • 22. Digital Out Digital Out
  • 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)
  • 26. LED pin ? ( ) pin? pinMode(who, ?) ( ) digitalWrite(who,?)
  • 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); } }
  • 30. #Bonus http://mutienliao.tw/arduino/Light_Talk.pde int pins[] = { 2, 3, 4, 5, 6, 7 }; !! // LED int lights = 6; ! ! // LED int pattens = 10; ! ! // byte graphy[10][6] = { {0,1,1,1,0,0}, {1,1,1,1,0,0}, {1,1,1,1,1,0}, {0,1,1,1,1,0}, {0,0,1,1,1,1}, {0,0,1,1,1,1}, {0,1,1,1,1,0}, [a] {1,1,1,1,1,0}, {1,1,1,1,0,0}, {0,1,1,1,0,0} }; ! // void setup() { for (int i = 0; i < lights; i++) ! // 0 light-1 pinMode(pins[i], OUTPUT); !! // } void loop() { for(int k = 0; k < lights; k++) { ! // digitalWrite(pins[k], LOW); } [b] delay(40); ! ! ! // 40 for (int i = 0; i < pattens; i++) { ! // ... Fig.1 for(int j = 0; j < lights; j++) {! // LED... if(patten[i][j]==1) { digitalWrite(pins[j], HIGH); ! // LED }else { digitalWrite(pins[j], LOW); ! // LED } } delay(1); ! ! // 1 } for(int k = 0; k < lights; k++) { ! // digitalWrite(pins[k], LOW); } delay(40);! ! ! // 40 }
  • 31. byte graphy[10][6] = { {0,1,1,1,0,0}, {1,1,1,1,0,0}, {1,1,1,1,1,0}, {0,1,1,1,1,0}, {0,0,1,1,1,1}, {0,0,1,1,1,1}, {0,1,1,1,1,0}, {1,1,1,1,1,0}, {1,1,1,1,0,0}, {0,1,1,1,0,0} }; !
  • 32. #3 | Blink Without Delay
  • 33. #3 File > Examples > Digital > BlinkWithoutDelay const int ledPin = 13; // pin 13 LED int ledState = LOW; // LED long previousMillis = 0; // long interval = 1000; // 1000ms = 1sec void setup() { pinMode(ledPin, OUTPUT); } void loop() { unsigned long currentMillis = millis(); // if(currentMillis - previousMillis > interval) { // previousMillis = currentMillis; // // LED if (ledState == LOW) ledState = HIGH; else ledState = LOW; // LED digitalWrite(ledPin, ledState); } }
  • 34. Delay() : millis() :
  • 36. Digital In Digital Input
  • 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); } }
  • 40.
  • 41. #7 | StateChangDetection #7 File > Examples > Digital > StateChangDetection
  • 42. #8 | Debounce #7 File > Examples > Digital > Debounce
  • 43. #| 1 2 3 4