Arduino Serial Calculator

I have to make a calculator using serial on my arduino for a project, we’re not allowed to use libraries at all. I’ve coded the whole thing and it should work but for some reason it wont wait for input at the scanf and just starts the loop again, help me fix it please.

static FILE uart00 = {0};
char function;
float Value1;
float Value2;
float Value3;
float Stored = 0;
float Answer = 0;
void setup(void) {
  USART0_init(); //initialise Serial parameters
}
void loop() {
  printf("Enter an Operator:\n");
  printf("+: Adds two values\n");
  printf("A: Calculates the average of three values\n");
  printf("!: Shows the Factorial of the given value\n");
  printf("S: Squares the given value\n");
  printf("M: Adds to the previously stored value (default is 0)\n");
  printf("R: Shows the stored value\n");
  printf("C: Clears the stored values\n");
  scanf(" %c", &function);

  switch (function) {
    case '+':
      Add();
      break;
    case 'A':
    case 'a':
      Mean();
      break;
    case '!':
      Factorial();
      break;
    case 'S':
    case 's':
      Sq();
      break;
    case 'M':
    case 'm':
      MemAdd();
      break;
    case 'R':
    case 'r':
      ReadMem();
      break;
    case 'C':
    case 'c':
      ClearMem;
      break;
    default:
      printf("The operation you have entered is invalid\n\r");
  }
}
void Add ()
{
  printf("----------------|Addition|----------------\n\r");
  printf("Enter the first value:\n");
  scanf(" %f, Value1");
  printf("Enter the second value:\n\r");
  scanf("  %f, Value2");
  Answer = Value1 + Value2;
  printf("%f, Value1");
  printf("+");
  printf("%f, Value2");
  printf("=");
  printf("%f, Answer\n\r");
}
void Mean()
{
  printf("----------------|Average|----------------\n\r");
  printf("Enter the first value:\n\r");
  scanf(" %f, Value1");
  printf("Enter the second value:\n\r");
  scanf(" %f, Value2");
  printf("Enter the third value:\n\r");
  scanf(" %f, Value3");
  Answer = (Value1 + Value2 + Value3) / 3;
  printf("The Mean value of \n\r");
  printf(" %f, Value1,");
  printf(" %f, Value2 ");
  printf("and");
  printf(" %f, Value3");
  printf("is:");
  printf(" %f, Answer\n\r");
}
void Factorial()
{
  printf("----------------|Factorial|----------------\n\r");
  printf("Enter the value to find the factorial of:\n\r");
  scanf(" %f, Value1");
  if (Value1 == 0)
  {
    printf("0!= 1");
  }
  else
  {
    Value2 = Value1;
    Value3 = Value2;
    while (Value2 >= 2)
    {
      Value2--;
      Answer = Value1 * Value2;
      Value1--;
    }
    printf("%f, Value3");
    printf("! = ");
    printf("%f, Answer\n\r");
  }
}
void Sq()
{
  printf("----------------|Square|----------------\n\r");
  printf("Enter the value to be squared\n\r");
  scanf(" %f, Value1");
  Value2 = Value1;
  Answer = Value1 * Value2;
  printf("%f, Value1");
  printf("^2 = ");
  printf("%f, Answer\n\r");
}
void MemAdd()
{
  printf("----------------|Add to stored value|----------------\n\r");
  printf("Enter the value to be added to the stored value\n\r");
  scanf(" %f, Value1");
  Value2 = Value1 + Stored;
  Stored = Value2;
  printf("%f, Value1");
  printf(" has been added to the stored value\n\r");
  printf("the stored value is now = ");
  printf("%f, Stored\n\r");
}
void ReadMem()
{
  printf("----------------|Stored Value|----------------\n\r");
  printf("the stored value is = ");
  printf("%f, Stored\n\r");
}
void ClearMem()
{
  printf("----------------|Clear Stored Value|----------------\n\r");
  Stored = 0;
  printf("The stored value has been cleared\n\r");
  printf("the stored value is now = ");
  printf("%f, Stored\n\r");
}
void USART0_init(void) {
  UCSR0A = B00000000; //single transmission speed, multiprocessor disabled
  UCSR0B = B00011000; //enable Rx & Tx
  UCSR0C = B00000110; //asynchronous, no parity, 1 stop, 8 bits
  UBRR0 = 103;        //load the value for 9600 bps baud rate into whole UBRR register
  fdev_setup_stream (&uart00, TX, RX, _FDEV_SETUP_RW); //Associate RX and TX functions with stdin/stdout
  stdin = stdout = &uart00 ; //the uart is defined as the standard inputa/output device
}

static int RX(FILE * stream) {
  //do nothing until data is received and is ready to be read from UDR0; wait for USART RX Complete flag
  while ((UCSR0A & (1 << RXC0)) == 0) {};
  //when flag is set read data from USART UDR0 register and return it
  return (UDR0);
}

static int TX(char TXData , FILE * stream) {
  //do nothing until UDR0 is ready for more data to be written to it; wait for USART UDRE flag
  while ((UCSR0A & (1 << UDRE0)) == 0) {};
  //when flag is set send data by placing the byte into UDR0
  UDR0 = TXData;
  return 0 ;
}

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The “Code: [Select]” feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.
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. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Unless the sketch is too large, it’s better if you post your code, rather than attach it. When it’s attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the “Temp” folder and manually remove it. It’s much easier to just view the code in your post.

Isn't this buffer kind of small?

static FILE uart00 = {0};

Honestly I have no idea what that means, i've done a bit of c in the past but arduino is brand new to me and im not sure what im doing, thats why I think my code should work but I don't know why its not waiting for input on the scanf's

Isn’t this buffer kind of small?

No. The FILE object is only one element (it’s really a pointer).

aarg: Isn't this buffer kind of small?

static FILE uart00 = {0};

That's not a buffer. For mere mortals, that should be equivalent to

static FILE uart00 = NULL;

I think you are using scanf() and printf() incorrectly. You DON'T put the variable names inside the format string. Note that the Arduino does not implement the %f format in printf().

When I compile this for Arduino UNO I get a LOT of warnings. You should turn up you warning level to "All" and check each warning to see if it is causing your problem.

/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:1:24: warning: missing initializer for member '__file::unget' [-Wmissing-field-initializers]
 static FILE uart00 = {0};
                        ^
warning: missing initializer for member '__file::flags' [-Wmissing-field-initializers]
warning: missing initializer for member '__file::size' [-Wmissing-field-initializers]
warning: missing initializer for member '__file::len' [-Wmissing-field-initializers]
warning: missing initializer for member '__file::put' [-Wmissing-field-initializers]
warning: missing initializer for member '__file::get' [-Wmissing-field-initializers]
warning: missing initializer for member '__file::udata' [-Wmissing-field-initializers]

/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void loop()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:47:15: warning: statement is a reference, not call, to function 'ClearMem' [-Waddress]
       ClearMem;
               ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:47:15: warning: statement has no effect [-Wunused-value]

/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void Add()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:57:22: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf(" %f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:59:23: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf("  %f, Value2");
                       ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:61:22: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:63:22: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Value2");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:65:26: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Answer\n\r");
                          ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void Mean()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:71:22: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf(" %f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:73:22: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf(" %f, Value2");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:75:22: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf(" %f, Value3");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:78:24: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf(" %f, Value1,");
                        ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:79:24: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf(" %f, Value2 ");
                        ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:81:23: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf(" %f, Value3");
                       ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:83:27: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf(" %f, Answer\n\r");
                           ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void Factorial()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:89:22: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf(" %f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:104:24: warning: format '%f' expects a matching 'double' argument [-Wformat=]
     printf("%f, Value3");
                        ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:106:28: warning: format '%f' expects a matching 'double' argument [-Wformat=]
     printf("%f, Answer\n\r");
                            ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void Sq()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:113:22: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf(" %f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:116:22: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:118:26: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Answer\n\r");
                          ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void MemAdd()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:124:22: warning: format '%f' expects a matching 'float*' argument [-Wformat=]
   scanf(" %f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:127:22: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Value1");
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:130:26: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Stored\n\r");
                          ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void ReadMem()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:136:26: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Stored\n\r");
                          ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: In function 'void ClearMem()':
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:144:26: warning: format '%f' expects a matching 'double' argument [-Wformat=]
   printf("%f, Stored\n\r");
                          ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino: At global scope:
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:155:22: warning: unused parameter 'stream' [-Wunused-parameter]
 static int RX(FILE * stream) {
                      ^
/Users/john/Documents/Arduino/sketch_jul30a/sketch_jul30a.ino:162:36: warning: unused parameter 'stream' [-Wunused-parameter]
 static int TX(char TXData , FILE * stream) {
                                    ^
Sketch uses 7020 bytes (21%) of program storage space. Maximum is 32256 bytes.
Global variables use 1088 bytes (53%) of dynamic memory, leaving 960 bytes for local variables. Maximum is 2048 bytes.