Arduino pins and leds


I need to find the sum of values
RGBLed+GreenLed+RedLed.
When I go with 48 it shows as incorrect,
and value of
RedLed+GreenLed+Button=30 is correct.

Welcome to the forum

What do you mean by these and Button ?

Please post the sketch that you are running

Where is your code/sketch ?

Never power a motor with the Arduino 5v pin.

For the circuit in the picture, a part of the Arduino program is given that does the following: first it waits for a key to be pressed, then it measures the duration T of the pressed key and, based on that, drives one of the output devices:

if T<100ms, turn off all outputs;
if 100ms < T < 230ms, turn on the red LED;
if 230ms < T < 350ms, turn on the green LED;
if 350ms < T < 450ms, turn on the white color on the RGB LED module;
if 450ms < T < 520ms, it starts the servo motor.

while(!digitalRead(KEY)); // wait for a key to be pressed
unsigned long start=millis(); // record the moment when the key is pressed
while(digitalRead(KEY)); // wait for the key to be released
T=millis()-start; // calculate the elapsed time
if(T<100) { PORTB=0; PORTD=0; } // turn everything off
else if(T<230) digitalWrite(RED_LED, HIGH);
else if(T<350) digitalWrite(GREEN_LED, HIGH);
else if(T<450) PORTB |= RGB; // turn white on RGB
else if( T<520) myServo.write(position): // move the axis of the servo motor

Determine the values for: RGB, RED_LED and GREEN_LED, then find their sum.
RGB + RED_LED + GREEN_LED = ?

Help: RGB stands for Red-Green-Blue. By mixing these 3 basic colors, all other colors are obtained. White color is obtained when all 3 primary colors are lit.

(I think sketch is not important for task,just pins from picture)

Please read the Forum Posting Guidelines.

That makes no sense at all because there is no definition of what they mean

According to the code snippet you posted RED_LED and GREEN_LED are pin numbers. Adding them does not make sense. RGB appears to be a bit pattern corresponding to GPIO pins.

What you say DOES NOT MAKE SENSE!

You need to be clearer about what you are trying to do.

What are 38 and 30 ?

Are you referring to PORTB and PORTD somehow?

Sum of pins
Red-13
Green-5
Button-12

Every time I reset the task it gives me 3 different things to sum up.
If it's RED+GREEN+BUTTON and I try answer 30 it's showing as correct .So I think what you need to do is just add sum of pins,but it's not working if RGB is involved(RGB+GREEN+RED 9+10+11+5+13=48 is incorrect)

You are still not making any sense.

I presume this is some kind of assignment?

Post exactly what the assignment is asking.
Post ALL your code (in code tags </>).

What task would that be ?

Yeah,this is assignment,I got confused as well.This is the whole task

Well now everybody is confused... maybe if we could see the actual assignment we could understand what is being asked.

I've copied every single word here

You should go back to your teacher and clarify what is being asked - this is a stupid assignment if you have shown us everything.

Where are 30 and 48 mentioned?

What do you mean by correct and incorrect?

They are not, it's sum of pins

Where are you doing this? Is this some online test ?


It's on my language but I translated most important parts.