Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Digital Input/Output Chin-Shiuh Shieh ( 謝欽旭 ) Department of Electronic Engineering National Kaohsiung University of Applied Sciences, Taiwan
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan2 Digital Input/Output
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan3 Digital Input/Output (cont) pinMode(pin,mode); digitalWrite(pin,value); digitalRead(pin);
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan4 Example – LED
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan5 Example – LED (cont) void setup() { int pin; for(pin=14;pin<=21;pin++) { pinMode(pin,OUTPUT); digitalWrite(pin,HIGH); } void loop() { int pin; for(pin=14;pin<=21;pin++) { digitalWrite(pin,LOW); delay(100); digitalWrite(pin,HIGH); }
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan6 Example DIP Switch
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan7 Example DIP Switch (cont) void setup() { int pin; for(pin=14;pin<=21;pin++) { pinMode(pin,OUTPUT); pinMode(pin*2+3,INPUT); } void loop() { int pin; for(pin=14;pin<=21;pin++) { digitalWrite(pin,digitalRead(pin*2+3)); }
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan8 Example - Button
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan9 Example – Button (cont) int button = 2;int LED = 13; void setup() { pinMode(button,INPUT); pinMode(LED,OUTPUT);digitalWrite(LED,LOW); } void loop() { if(digitalRead(button)==LOW) { for(int i=0;i<3;i++) { digitalWrite(LED,HIGH);delay(500); digitalWrite(LED,LOW);delay(500); }