114Views7Replies

Author Options:

Hi, I was trying to control 10 Leds with the arduino Through the serial monitor, does anybody know how ? Answered

Discussions

0
None
Genius 470

4 years ago

I was wondering if i could modify this code so i could control the led's with the serial monitor, but i don't know how, Could somebody help?

int pin2 = 2;

int pin3 = 3;

int pin4 = 4;

int pin5 = 5;

int pin6 = 6;

int pin7 = 7;

int pin8 = 8;

int pin9 = 9;

int pin10 = 10;

int pin11 = 11;

int timer = 60;

void setup(){

pinMode(pin2, OUTPUT);

pinMode(pin3, OUTPUT);

pinMode(pin4, OUTPUT);

pinMode(pin5, OUTPUT);

pinMode(pin6, OUTPUT);

pinMode(pin7, OUTPUT);

pinMode(pin8, OUTPUT);

pinMode(pin9, OUTPUT);

pinMode(pin10, OUTPUT);

pinMode(pin11, OUTPUT);

}

void loop() {

digitalWrite(pin2, HIGH);

delay(timer);

digitalWrite(pin2, LOW);

delay(timer);

digitalWrite(pin3, HIGH);

delay(timer);

digitalWrite(pin3, LOW);

delay(timer);

digitalWrite(pin4, HIGH);

delay(timer);

digitalWrite(pin4, LOW);

delay(timer);

digitalWrite(pin5, HIGH);

delay(timer);

digitalWrite(pin5, LOW);

delay(timer);

digitalWrite(pin6, HIGH);

delay(timer);

digitalWrite(pin6, LOW);

delay(timer);

digitalWrite(pin7, HIGH);

delay(timer);

digitalWrite(pin7, LOW);

delay(timer);

digitalWrite(pin8, HIGH);

delay(timer);

digitalWrite(pin8, LOW);

delay(timer);

digitalWrite(pin9, HIGH);

delay(timer);

digitalWrite(pin9, LOW);

delay(timer);

digitalWrite(pin10, HIGH);

delay(timer);

digitalWrite(pin10, LOW);

delay(timer);

digitalWrite(pin11, HIGH);

delay(timer);

digitalWrite(pin11, LOW);

delay(timer);

digitalWrite(pin10, HIGH);

delay(timer);

digitalWrite(pin10, LOW);

delay(timer);

digitalWrite(pin9, HIGH);

delay(timer);

digitalWrite(pin9, LOW);

delay(timer);

digitalWrite(pin8, HIGH);

delay(timer);

digitalWrite(pin8, LOW);

delay(timer);

digitalWrite(pin7, HIGH);

delay(timer);

digitalWrite(pin7, LOW);

delay(timer);

digitalWrite(pin6, HIGH);

delay(timer);

digitalWrite(pin6, LOW);

delay(timer);

digitalWrite(pin5, HIGH);

delay(timer);

digitalWrite(pin5, LOW);

delay(timer);

digitalWrite(pin4, HIGH);

delay(timer);

digitalWrite(pin4, LOW);

delay(timer);

digitalWrite(pin3, HIGH);

delay(timer);

digitalWrite(pin3, LOW);

delay(timer);

}

0
None
steveastroukGenius 470

Answer 4 years ago

No, you need to start with what I posted, after you've learned how to listen to the serial port.

0
None
steveastrouk

4 years ago

Yes, Here's one method, it will allow you to put any combination of 10 LEDs on or off at once

Fasten all the LEDs to the Arduino pins.
Read a number from the serial port

if ( (number&1)==1) led1=1 else led1=0;

if ((number&2)==2) led2=1 else led2 =0;

if ((number&4)==4) led3=1 else led3 =0;

if ((number&8)==8) led4=1 else led4 =0;

if ((number&16)==16) led5=1 else led5 =0;

if ((number&32)==32) led6=1 else led6 =0;

if ((number&64)==64) led7=1 else led7 =0;

if ((number&128)==128) led8=1 else led8 =0;

if ((number&256)==256) led9=1 else led9 =0;

if ((number&512)==512) led10=1 else led10 =0;

There are other ways, but this is the easiest method for a beginner.

0
None
Genius 470steveastrouk

Answer 4 years ago

Thank you for you answer, But could you explain a little bit more, because i'm only 13 and i just started using arduino and the coding.

0
None
steveastroukGenius 470

Answer 4 years ago

Do this in stages then. Take a look at the serial programming samples in the Arduino code and try them out. Make them turn on and off one LED first. Then come back and look how, if you enter a number from 0..1024, my code works.

0
None
mpilchfamily

4 years ago

Need lots more information here. What code are you using? What LEDs are you using? How do you have everything wired?

0
None
Genius 470mpilchfamily

Answer 4 years ago

I'm using a led bargraph wired through pins of 2 through 11 of a arduino uno.