70 likes | 227 Views
Cascade switching of an LED. EAS 199B Winter 2011. Digital I/O pin to switch LED. Transistor switch for LED. Transistor to Relay switch for LED. Compare switching circuits. Code to turn on pins. int npin = 3; // number of pins
E N D
Cascade switching of an LED EAS 199B Winter 2011
Code to turn on pins int npin = 3; // number of pins int LED_pin[] = {4,5,6}; // array of pins for digital output void setup() { for ( int i=0; i<npin; i++ ) { // arrays are zero offset pinMode( LED_pin[i], OUTPUT ); } } void loop() { int i; for ( i=0; i<npin; i++ ) { digitalWrite( LED_pin[i], HIGH); } delay(1000); for (i=0; i<npin; i++ ) { digitalWrite( LED_pin[i], LOW); } delay(1000); }
Code without loops int LED_pin1=4, LED_pin2=5, LED_pin3=6; void setup() { pinMode( LED_pin1, OUTPUT ); pinMode( LED_pin2, OUTPUT ); pinMode( LED_pin3, OUTPUT ); } void loop() { digitalWrite( LED_pin1, HIGH); digitalWrite( LED_pin2, HIGH); digitalWrite( LED_pin3, HIGH); delay(1000); digitalWrite( LED_pin1, LOW); digitalWrite( LED_pin2, LOW); digitalWrite( LED_pin3, LOW); delay(1000); }