LED ON ARDUINO

Play with LED bulb is fun, especially for kids or everybody who beginning learn arduino. Setup LED is basic before go to higher level

LED arduino

SKET 1

const int numLED = 16;
const int pinLED[numLED] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
void setup() {
for(int i=0; i<16; i++){
pinMode(pinLED[i], OUTPUT);
}
}
void loop() {
for(int i=0; i<16; i++){
digitalWrite(pinLED[i], LOW);
}
delay(100);
for(int i=0; i<16; i++){
digitalWrite(pinLED[i], HIGH);
delay(100);
}
}

SKET 2

// Inisialisasi Pin LED
const int pinLED1 =2;
const int pinLED2 =3;
const int pinLED3 =4;
const int pinLED4 =5;
const int pinLED5 =6;
const int pinLED6 =7;
const int pinLED7 =8;
const int pinLED8 =9;
const int pinLED9 =10;
const int pinLED10=11;
const int pinLED11=12;
const int pinLED12=13;
const int pinLED13=14; // pin A0
const int pinLED14=15; // pin A1
const int pinLED15=16; // pin A2
const int pinLED16=17; // pin A3

void setup() {
// pin LED sebagai output
pinMode(pinLED1, OUTPUT);
pinMode(pinLED2, OUTPUT);
pinMode(pinLED3, OUTPUT);
pinMode(pinLED4, OUTPUT);
pinMode(pinLED5, OUTPUT);
pinMode(pinLED6, OUTPUT);
pinMode(pinLED7, OUTPUT);
pinMode(pinLED8, OUTPUT);
pinMode(pinLED9, OUTPUT);
pinMode(pinLED10, OUTPUT);
pinMode(pinLED11, OUTPUT);
pinMode(pinLED12, OUTPUT);
pinMode(pinLED13, OUTPUT);
pinMode(pinLED14, OUTPUT);
pinMode(pinLED15, OUTPUT);
pinMode(pinLED16, OUTPUT);
}
void loop() {
for(int i=0; i<17; i++){
if(i==1){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, LOW);
digitalWrite(pinLED3, LOW);
digitalWrite(pinLED4, LOW);
digitalWrite(pinLED5, LOW);
digitalWrite(pinLED6, LOW);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==2){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, LOW);
digitalWrite(pinLED4, LOW);
digitalWrite(pinLED5, LOW);
digitalWrite(pinLED6, LOW);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==3){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, LOW);
digitalWrite(pinLED5, LOW);
digitalWrite(pinLED6, LOW);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==4){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, LOW);
digitalWrite(pinLED6, LOW);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==5){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, LOW);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==6){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==7){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==8){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==9){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==10){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, HIGH);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==11){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, HIGH);
digitalWrite(pinLED11, HIGH);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==12){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, HIGH);
digitalWrite(pinLED11, HIGH);
digitalWrite(pinLED12, HIGH);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==13){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, HIGH);
digitalWrite(pinLED11, HIGH);
digitalWrite(pinLED12, HIGH);
digitalWrite(pinLED13, HIGH);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==14){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, HIGH);
digitalWrite(pinLED11, HIGH);
digitalWrite(pinLED12, HIGH);
digitalWrite(pinLED13, HIGH);
digitalWrite(pinLED14, HIGH);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}else if(i==15){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, HIGH);
digitalWrite(pinLED11, HIGH);
digitalWrite(pinLED12, HIGH);
digitalWrite(pinLED13, HIGH);
digitalWrite(pinLED14, HIGH);
digitalWrite(pinLED15, HIGH);
digitalWrite(pinLED16, LOW);
}else if(i==16){
digitalWrite(pinLED1, HIGH);
digitalWrite(pinLED2, HIGH);
digitalWrite(pinLED3, HIGH);
digitalWrite(pinLED4, HIGH);
digitalWrite(pinLED5, HIGH);
digitalWrite(pinLED6, HIGH);
digitalWrite(pinLED7, HIGH);
digitalWrite(pinLED8, HIGH);
digitalWrite(pinLED9, HIGH);
digitalWrite(pinLED10, HIGH);
digitalWrite(pinLED11, HIGH);
digitalWrite(pinLED12, HIGH);
digitalWrite(pinLED13, HIGH);
digitalWrite(pinLED14, HIGH);
digitalWrite(pinLED15, HIGH);
digitalWrite(pinLED16, HIGH);
}
else{
digitalWrite(pinLED1, LOW);
digitalWrite(pinLED2, LOW);
digitalWrite(pinLED3, LOW);
digitalWrite(pinLED4, LOW);
digitalWrite(pinLED5, LOW);
digitalWrite(pinLED6, LOW);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
}
delay(100);
}
}

SKET 3

const int pinLED1 =2;
const int pinLED2 =3;
const int pinLED3 =4;
const int pinLED4 =5;
const int pinLED5 =6;
const int pinLED6 =7;
const int pinLED7 =8;
const int pinLED8 =9;
const int pinLED9 =10;
const int pinLED10=11;
const int pinLED11=12;
const int pinLED12=13;
const int pinLED13=14;
const int pinLED14=15;
const int pinLED15=16;
const int pinLED16=17;
void setup() {
// pin LED sebagai output
pinMode(pinLED1, OUTPUT);
pinMode(pinLED2, OUTPUT);
pinMode(pinLED3, OUTPUT);
pinMode(pinLED4, OUTPUT);
pinMode(pinLED5, OUTPUT);
pinMode(pinLED6, OUTPUT);
pinMode(pinLED7, OUTPUT);
pinMode(pinLED8, OUTPUT);
pinMode(pinLED9, OUTPUT);
pinMode(pinLED10, OUTPUT);
pinMode(pinLED11, OUTPUT);
pinMode(pinLED12, OUTPUT);
pinMode(pinLED13, OUTPUT);
pinMode(pinLED14, OUTPUT);
pinMode(pinLED15, OUTPUT);
pinMode(pinLED16, OUTPUT);
}
void loop() {
digitalWrite(pinLED1, LOW);
digitalWrite(pinLED2, LOW);
digitalWrite(pinLED3, LOW);
digitalWrite(pinLED4, LOW);
digitalWrite(pinLED5, LOW);
digitalWrite(pinLED6, LOW);
digitalWrite(pinLED7, LOW);
digitalWrite(pinLED8, LOW);
digitalWrite(pinLED9, LOW);
digitalWrite(pinLED10, LOW);
digitalWrite(pinLED11, LOW);
digitalWrite(pinLED12, LOW);
digitalWrite(pinLED13, LOW);
digitalWrite(pinLED14, LOW);
digitalWrite(pinLED15, LOW);
digitalWrite(pinLED16, LOW);
delay(100);
digitalWrite(pinLED1, HIGH);
delay(100);
digitalWrite(pinLED2, HIGH);
delay(100);
digitalWrite(pinLED3, HIGH);
delay(100);
digitalWrite(pinLED4, HIGH);
delay(100);
digitalWrite(pinLED5, HIGH);
delay(100);
digitalWrite(pinLED6, HIGH);
delay(100);
digitalWrite(pinLED7, HIGH);
delay(100);
digitalWrite(pinLED8, HIGH);
delay(100);
digitalWrite(pinLED9, HIGH);
delay(100);
digitalWrite(pinLED10, HIGH);
delay(100);
digitalWrite(pinLED11, HIGH);
delay(100);
digitalWrite(pinLED12, HIGH);
delay(100);
digitalWrite(pinLED13, HIGH);
delay(100);
digitalWrite(pinLED14, HIGH);
delay(100);
digitalWrite(pinLED15, HIGH);
delay(100);
digitalWrite(pinLED16, HIGH);
delay(100);
}

SKET 4

const int numLED = 16;
const int pinLED[numLED] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
void setup() {
for(int i=0; i<16; i++){
pinMode(pinLED[i], OUTPUT);
}
}
void loop() {
for(int i=0; i<15; i++){
digitalWrite(pinLED[i], HIGH);
delay(100);
digitalWrite(pinLED[i], LOW);
}
for(int i=15; i>0; i–){
digitalWrite(pinLED[i], HIGH);
delay(100);
digitalWrite(pinLED[i], LOW);
}
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s