개발자 코스프레 002 - Switch Switch int button = 7;int led = 12; void setup() { pinMode(button, INPUT); pinMode(led, OUTPUT);} void loop() { if(digitalRead(button) == HIGH) { digitalWrite(led, HIGH); } else { digitalWrite(led, LOW); }} Arduino 2015.10.26
개발자 코스프레 001 - 7 LEDs 7 LEDs int leds[] = {0, 1, 2, 3, 4, 5, 6, 7};int len = sizeof(leds) / 2; void setup() { int idx; for(idx = 0; idx < len; idx++) { pinMode(leds[idx], OUTPUT); }} void loop() { int idx; for(idx = 0; idx < len; idx++) { if(idx == 0) { digitalWrite(leds[len - 1], LOW); digitalWrite(leds[idx], HIGH); } else { digitalWrite(leds[idx - 1], LOW); digitalWrite(leds[idx], HIGH); } delay(100); }} Arduino 2015.10.26