Arduino: Intro and Digital I/O

1,254 views

Published on

Arduino -- Introduction & Basic Digital Input/Output, by Mao Wu

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,254
On SlideShare
0
From Embeds
0
Number of Embeds
237
Actions
Shares
0
Downloads
39
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Arduino: Intro and Digital I/O

  1. 1. 阿爾杜伊諾 Arduino: Lv. 1Mutienliao.TW , 2013-03-18
  2. 2. ArduinoIntroduction
  3. 3. Human Computer Interactive / Interface ??
  4. 4. physical computing system
  5. 5. What is Arduino?
  6. 6. Open SourceArduino Hardware Arduino Software Physical Computing Platform & Group
  7. 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 )
  8. 8. 各式各樣的Arduino........族繁不及備載
  9. 9. Digital Out Digital In Analog In Analog Out Communication
  10. 10. Digital Out
  11. 11. Analog Out
  12. 12. Digital In
  13. 13. Analog In
  14. 14. Communication
  15. 15. Digital In Digital Out CommunicationEmotion Experience Analog In Analog Out
  16. 16. | Prepare to test Arduino board- Arduino- LED Blink File > Examples > Basic > Blink
  17. 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. 18. | Upload the program
  19. 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. 20. # | Troubleshooting• Serial port•• Serial Port Serila port• Jump Duemilanove/UNO• Reset Reset Update• Arudino USB•
  21. 21. breadborad
  22. 22. Digital Out Digital Out
  23. 23. #1 | Blink
  24. 24. HIGH 1 LOW 0• Only 1 or 0 / High or LOW / ON or OFF
  25. 25. #1 File > Examples > Basic > Blinkint ledPin = 13; // LED connected to digital pin 3void 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. 26. LED pin ?( ) pin? pinMode(who, ?) ( ) digitalWrite(who,?)
  27. 27. #2 | Loop
  28. 28. #2 File > Examples > Control > ForLoopIterationint 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); }}
  29. 29. #Bonus | Light Talk
  30. 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. 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. 32. #3 | Blink Without Delay
  33. 33. #3 File > Examples > Digital > BlinkWithoutDelayconst int ledPin = 13; // pin 13 LEDint ledState = LOW; // LEDlong previousMillis = 0; //long interval = 1000; // 1000ms = 1secvoid 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. 34. Delay() :millis() :
  35. 35. 輸入才是互動的精華
  36. 36. Digital In Digital Input
  37. 37. #6 | Button
  38. 38. #6 | Button
  39. 39. #6 File > Examples > Digital > Buttonconst int buttonPin = 2; // the number of the pushbutton pinconst int ledPin = 13; // the number of the LED pinint buttonState = 0; // variable for reading the pushbutton statusvoid 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. 40. #7 | StateChangDetection #7 File > Examples > Digital > StateChangDetection
  41. 41. #8 | Debounce #7 File > Examples > Digital > Debounce
  42. 42. #| 1 2 3 4

×