Pages: [1]   Go Down
Author Topic: a problem with receving a 3 digit serial number.  (Read 333 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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:
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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Sydney, Australia
Offline Offline
Full Member
***
Karma: 3
Posts: 230
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Is life really that serious...??!

Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: [1]   Go Up
Jump to: