Super noob here..

i need to make a program that will allow me to light a led using a commands

example :
led 1 to arduino pin 13
led 2 to arduino pin 12
led 3 to arduino pin 11
led 4 to arduino pin 10
.. program will ask the user to input a command like
13 = light led 1
12 = light led 2
11 = light led 3
10 = light led 4

up

Hi,

Sorry, no-one is replying because we can't understand what you are trying to do. Your explanation of the project makes no sense to us. Your photographs do not help us understand at all. The link to the instructables project does not help either. Several times you use the phrase "four moves". What is that?

Try again to explain what your project is.

Paul

sorry about that .. what im trying to say is four moves like four command , i need a code that will allow me input a number and will perform a command :

1 = play
2 = next
3 = previous
4 = stop

...i have tried the code blink for four integer but i dont know how to code it when i need to input a number to choose what integer/led will blink. ("ex entered num 5 = 5 in microcontroller will give power to on the led")

Read this http://forum.arduino.cc/index.php?topic=261445.0 it will help you get a better idea how to get started.

Thankssir… i changed the post and i have hope it’s more easier to understand

That can be done. Read on how to receive serial. And how to set a port. We're here to help, not to write code for you (unless you pay us).

Also, how do you want to connect it to something? Because now you're talking about LEDs but you don't mean LEDs :wink:

recieve serial and set a port. ok ok i think im getting the terms xD ill try to study those.. for now i need to sleep its 230 am here thanks for replies.

i need to make a program that will allow me to light a led using a commands

Very simple serial command code.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if (readString == "on")     
    {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");
    }
    if (readString == "off")
    {
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");
    }
    readString="";
  } 
}

Something like this should get you started. A lot of folk here are not too friendly to newbies for some weird reason. It's not like they were born experts and never had to ask about anything.

/*
1 = play
2 = next
3 = previous
4 = stop
*/
int ledPin = 13;
int readInt;

void setup() 
{ Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
}

void loop() 
{  while (Serial.available()) 
   { delay(3);  
     int i = Serial.read();
   }
  switch(readInt)
  {
    case 1:
    { // Play
      // Write the code here to Play whatever it is
      digitalWrite(ledPin, HIGH);
      break;
    }
    case 2:
    { // Next
      // Write the code here for Next whatever it is
      digitalWrite(ledPin, HIGH);
      break;
    }
    case 3:
    { // Previous
      // Write the code here for Previous whatever it is
      digitalWrite(ledPin, HIGH);
      break;
    }
    case 4:
    { // Stop
      // Write the code here to Stop whatever it is
      digitalWrite(ledPin, LOW);
      break;
    }
  }
}

@WaitSome
“readInt” never changes.

void loop()
{  while (Serial.available())
   { delay(3); 
     int i = Serial.read();
   }

Inefficent methode to get rid of serial input. :wink:

(sarcasm)
But useless routines should at least hinder the program flow.

'oh, there is input available, so lets go to sleep, throwing away the input can wait'. :confused:

(/sarcasm)

“i” goes out of scope when you leave the while loop.

Do you mean:
readInt = Serial.read();

Maybe in each “case” you want,
readInt = 0;
so you do not re-execute the same code each time loop starts.

.

Sorry, I only tested that it complied as I have a project connected and running on a Mega that I cannot interrupt for another day at least. So, could not test it. I was winging the coding. :slight_smile:

Here ya go, tested to work. I used a Nano and another PC.
Oh, and in the .print(F(“Play”)) the “F( )” part is Macro you should get in the habit of using in Print statement for Strings as it saves SRAM memory. Every little bit helps you will quickly come to find. :slight_smile:

/*
1 = play
2 = next
3 = previous
4 = stop
*/
int ledPin = 13;
int readInt;

void setup() 
{ Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
}

void loop() 
{ if (Serial.available() > 0) 
  { readInt = Serial.read();
  }
  if (readInt > 0)
  { 
    switch(readInt-48) // Need to deduct 48 as the returned value is the ASCII character number
    {
      case 1:
      { // Play
        // Write the code here to Play whatever it is
        Serial.print(F("Play"));
        digitalWrite(ledPin, HIGH);
        break;
      }
      case 2:
      { // Next
        // Write the code here for Next whatever it is
        Serial.print(F("Next"));
        digitalWrite(ledPin, HIGH);
        break;
      }
      case 3:
      { // Previous
        // Write the code here for Previous whatever it is
        Serial.print(F("Previous"));
        digitalWrite(ledPin, HIGH);
        break;
      }
      case 4:
      { // Stop
        // Write the code here to Stop whatever it is
        Serial.print(F("Stop"));
        digitalWrite(ledPin, LOW);
        break;
      }
    }
    Serial.println();
  }
  readInt = 0;
}

wouldn't it be more readable to write

    switch(readChar-'0')
    {
      case 1:

or

    switch(readChar)
    {
      case '1':

so its easy its just like a C++ omg.. im just not used in self study thanks so much and ill try the codes to edit on how i want it to work thanks so much

is this going to work?

1 = play
2 = next
3 = previous
4 = stop
*/
int ledPin1 = 13;
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int readInt;

void setup()
{ Serial.begin(9600);
 pinMode(ledPin, OUTPUT);
}

void loop()
{ if (Serial.available() > 0)
 { readInt = Serial.read();
 }
 if (readInt > 0)
 {
   switch(readInt-48) // Need to deduct 48 as the returned value is the ASCII character number
   {
     case 1:
     { // Play
       // Write the code here to Play whatever it is
       Serial.print(F("Play"));
       digitalWrite(ledPin1, HIGH);
       break;
     }
     case 2:
     { // Next
       // Write the code here for Next whatever it is
       Serial.print(F("Next"));
       digitalWrite(ledPin2, HIGH);
       break;
     }
     case 3:
     { // Previous
       // Write the code here for Previous whatever it is
       Serial.print(F("Previous"));
       digitalWrite(ledPin3, HIGH);
       break;
     }
     case 4:
     { // Stop
       // Write the code here to Stop whatever it is
       Serial.print(F("Stop"));
       digitalWrite(ledPin4, LOW);
       break;
     }
   }
   Serial.println();
 }
 readInt = 0;
}

i tried to compile it but
compiler says

sketch_sep27a.ino:2:21: fatal error: Arduino.h: No such file or directory
compilation terminated.
Error compiling.

Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags which make the code looklike thiswhen posting source code files.

If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button.

sorry sir.. done