際際滷

際際滷Share a Scribd company logo
ARDUINO 
蠍一襦蠏碁覦
contents 
1. 企 (ARDUINO) 
2. 襦 
3. 企 ARDUINO 
 
4. れ豺襦 DC 覈
1. 企(ARDUINO) 
 Arduino( 企 )  ろ 蠍磯 殊貉 
貉危  
 語 
Arduino Uno 
+ 
Arduino IDE
1. 企(ARDUINO) -  
 Arduino 
Uno 
襷危襦 貉碁, ATmega328 
  5V 
  7 ~ 20V 
讌  / 豢 14 螳 
襦蠏  6 螳 
 / 豢 襯 40mA 
3.3V 豢 襯 50mA 
SRAM 2KB 
EEPROM 1KB 
企  16MHz
1. 企(ARDUINO) -  
 Arduino 
Uno 
讌 /豢  
襦蠏   
USB  
  
襦蠏 豢  ~
1. 企(ARDUINO) - 語 
 Arduino IDE  れ企 
http://arduino.cc/en/Main/Software 
貉危 襦 
覯 
豕豐 覯 ろ 
覓危 覦覲 
襦 setup() loop()
2. 襦  觚 覲企 & LED 
+, 5V 
-, GND 
+ - 
觚 覲企 
LED
3. Arduino  
Arduino 
 
豢 
讌  
襦蠏  
讌 豢 
襦蠏 豢 
襴狩旧
3. Arduino  
 pinMode(pin, mode)      覈 れ 
pin :  覯 
mode : INPUT, OUTPUT, INPUT_PULLUP 
 delay(ms)  讌 螳 襷危襦襦語  
覃豢ms : 覦襴語雑 
讌 豢 
 digitalWrite(pin, value)  れ  讌 螳 豢 
pin :  覯 
value : HIGH, LOW
3. Arduino  
讌  
 digitalRead(pin)  れ  讌 螳 曙 
pin :  覯 
襦蠏  
 analogRead(pin)  れ  0 ~ 1023 螳 曙 
pin :  覯 
襦蠏 豢 
 analogWrite(pin, val)  豢ロ 螳 豢 
pin :  覯 
val : 豢リ 0 ~ 255
3. Arduino  
襴狩旧 
 Serial.begin(speed) 
speed : 襴 旧 れ 
 Serial.available()  襴 旧 覯殊 
曙   覦危  
 Serial.read()  覯殊 一危磯ゼ 曙  
 Serial.print(val)  一危磯ゼ 覓語企
3. Arduino  
蠍壱 
 Millis()   襦蠏碁  螳覿 覦襴 
襦 豺伎危  螳 覦 
 MsTimer2::set(unsigned long ms, void(*f)())  
誤磯渚 れ 
ms : 誤磯渚 螳 , 覦襴 豐 
void(*f)() : 誤磯渚 覿蠍 覈 
 MsTimer2::start()  誤磯渚  
 MsTimer2::stop()  誤磯渚 讌 
 MsTimer2  碁殊企襴  
http://arduino.cc/en/Reference/Libraries れ企  
C:Program FilesArduinoarduino-1.0.5-r2libraries  启 覲旧
4. れ豺襦 DC 覈 危蠍 - 襦
4. れ豺襦 DC 覈 危蠍 -  
#define CW HIGH 
#define CCW LOW 
#define SPEED 100 // 0 ~ 255伎 螳 
int swBuf; 
void setup(){ pinMode(9, OUTPUT); 
pinMode(8, OUTPUT); 
pinMode(7, OUTPUT); 
pinMode(2, INPUT_PULLUP); 
} 
void loop(){ 
setMotor(SPEED, CW); 
} 
void setMotor(int motorSpeed, boolean motorDir){ 
if(digitalRead(2) == LOW && swBuf == 0){ 
swBuf = 1; 
}else if(digitalRead(2) == HIGH && swBuf == 1){ 
swBuf = 0; 
analogWrite(9, motorSpeed); 
digitalWrite(8, motorDir); 
digitalWrite(7, !motorDir); 
} 
}

More Related Content

Arduino Basic Programming

  • 2. contents 1. 企 (ARDUINO) 2. 襦 3. 企 ARDUINO 4. れ豺襦 DC 覈
  • 3. 1. 企(ARDUINO) Arduino( 企 ) ろ 蠍磯 殊貉 貉危 語 Arduino Uno + Arduino IDE
  • 4. 1. 企(ARDUINO) - Arduino Uno 襷危襦 貉碁, ATmega328 5V 7 ~ 20V 讌 / 豢 14 螳 襦蠏 6 螳 / 豢 襯 40mA 3.3V 豢 襯 50mA SRAM 2KB EEPROM 1KB 企 16MHz
  • 5. 1. 企(ARDUINO) - Arduino Uno 讌 /豢 襦蠏 USB 襦蠏 豢 ~
  • 6. 1. 企(ARDUINO) - 語 Arduino IDE れ企 http://arduino.cc/en/Main/Software 貉危 襦 覯 豕豐 覯 ろ 覓危 覦覲 襦 setup() loop()
  • 7. 2. 襦 觚 覲企 & LED +, 5V -, GND + - 觚 覲企 LED
  • 8. 3. Arduino Arduino 豢 讌 襦蠏 讌 豢 襦蠏 豢 襴狩旧
  • 9. 3. Arduino pinMode(pin, mode) 覈 れ pin : 覯 mode : INPUT, OUTPUT, INPUT_PULLUP delay(ms) 讌 螳 襷危襦襦語 覃豢ms : 覦襴語雑 讌 豢 digitalWrite(pin, value) れ 讌 螳 豢 pin : 覯 value : HIGH, LOW
  • 10. 3. Arduino 讌 digitalRead(pin) れ 讌 螳 曙 pin : 覯 襦蠏 analogRead(pin) れ 0 ~ 1023 螳 曙 pin : 覯 襦蠏 豢 analogWrite(pin, val) 豢ロ 螳 豢 pin : 覯 val : 豢リ 0 ~ 255
  • 11. 3. Arduino 襴狩旧 Serial.begin(speed) speed : 襴 旧 れ Serial.available() 襴 旧 覯殊 曙 覦危 Serial.read() 覯殊 一危磯ゼ 曙 Serial.print(val) 一危磯ゼ 覓語企
  • 12. 3. Arduino 蠍壱 Millis() 襦蠏碁 螳覿 覦襴 襦 豺伎危 螳 覦 MsTimer2::set(unsigned long ms, void(*f)()) 誤磯渚 れ ms : 誤磯渚 螳 , 覦襴 豐 void(*f)() : 誤磯渚 覿蠍 覈 MsTimer2::start() 誤磯渚 MsTimer2::stop() 誤磯渚 讌 MsTimer2 碁殊企襴 http://arduino.cc/en/Reference/Libraries れ企 C:Program FilesArduinoarduino-1.0.5-r2libraries 启 覲旧
  • 13. 4. れ豺襦 DC 覈 危蠍 - 襦
  • 14. 4. れ豺襦 DC 覈 危蠍 - #define CW HIGH #define CCW LOW #define SPEED 100 // 0 ~ 255伎 螳 int swBuf; void setup(){ pinMode(9, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(2, INPUT_PULLUP); } void loop(){ setMotor(SPEED, CW); } void setMotor(int motorSpeed, boolean motorDir){ if(digitalRead(2) == LOW && swBuf == 0){ swBuf = 1; }else if(digitalRead(2) == HIGH && swBuf == 1){ swBuf = 0; analogWrite(9, motorSpeed); digitalWrite(8, motorDir); digitalWrite(7, !motorDir); } }