Go Down

Topic: a problem with receving a 3 digit serial number. (Read 414 times) previous topic - next topic

thatdude624

ok, so the OS im making is 4KB in size (the answer to my last question was aproxamately 5000 lines of code,BTW.)
and although i can recieve numbers from 0-9, i have this problem with my dialog box.
the code for the box:
Code: [Select]
  int entry()
  {
   Serial.println("|I|please enter |");
   Serial.println("|I|a 3 digit no:|");
   Serial.print("|w|    ");
   int felds[3];
   for(int times=1;times==3;times)//3 loop, no change
   {
         if (Serial.available())//is there new data?
    {
    char ch2 = Serial.read();//picup data
    if(ch2 >= '0' && ch2 <= '9') // is this an ascii digit between 0 and 9?
    {
       felds[times]=(ch2 - '0');//convert to number
       Serial.print(felds[times]);//print entered number
       times++;//add 1 to current number
  }}
   }//loop out
     Serial.println("         |");//end the line
     int output=((felds[0])+(felds[1]*10)+(felds[2]*100));//compile final number
     return output;
  }


I know its something stupid, I know it. I just can't find it!
this compiler doesn't seem to give as much errors or warnings like Java does. sometimes i'm like, how can that even run?


output:
Code: [Select]
please type in:5 seconds in order to acess the OS.
+----------------------------+
|_____L-OS_(by laurens!)_____|
|the OS you wish you invented|
+-+-------------+------------+
|M|  Main menu  |
|1|remote codes |
|2|  settings   |
|3| RUN(5 sec.) |
+-+-------------|
|I| Selected: 2 +------------+
+-+-------------|
|M|Settings menu|
|0|to main menu |
|1|wall distance|
+-+-------------|
|I| Selected: 1 +------------+
+-+-------------|
|I|please enter |
|I|a 3 digit no:|
|w|             |
0

note the end bit. that empty space is where the number being entered is supposed to be(while you are typing) it appears it puts a space instead of the actual letter.
that last number is so i can see what the number entered was. it is 0,as you can obviously see.

thatdude624

NVM, i fixed it. something wrong with the for look, so i used a while.
but what's wrong with it?

pocketscience

Your for loop is screwed up... lookup how for loops work... the middle piece defines the exit condition - in your case it will exit right away... ie times doesn't equal 3, so the loop bails.


G.
Is life really that serious...??!

thatdude624

ooo. i thought that that was when it does exit! mus have read it wrong. so it shud have been times!=3. i know it was something stupid!

Go Up