title: Displaying negative numbers in Arduino
body: <p>My friend and I are wiring/coding a digital thermometer on an Arduino board, and I'm writing the code. We've got the thermometer working great, and the basic temp data going to the 4-digit 7-segment LED screen we're using for output. I'm trying to write the code to display negative (sub-zero) temperatures, and am having trouble getting proper output. Instead of outputting a negative sign, it outputs an 8. </p>
  
  <p>Here's the loop() method:</p>
  
  <pre><code>void loop(void) {
   int temp = getTemp();
   boolean neg = false;
   if (temp &lt; 0) {
     // Since the temperature is negative, multiplying it by -2 and adding it
     // to itself gives us the absolute value of the number
     temp += (temp * (-2));
     // We set the neg boolean to true, indicating that we're dealing with a negative number
     neg = true;
   }
   displayNumber(temp, neg);
  }
  </code></pre>
  
  <p>Here's the (truncated) displayNumber() method:</p>
  
  <pre><code>void displayNumber(int toDisplay, boolean negative) {
  
  int num = toDisplay;
  
  // The digits are 1-4, left to right
  for(int digit = 4; digit &gt; 0 ; digit--) {
  //Turn on a digit for a short amount of time
  switch(digit) {
  case 1:
    // The leftmost digit only needs to be on for temps 100.0 or above, 
    // or to display the negative sign for temps -10.0 or below
    if (num &gt;= 1000 || (num &gt;= 100 &amp;&amp; negative == true)) {
      digitalWrite(digit1, HIGH);
      }
    if (num &gt;= 100 &amp;&amp; negative == true) {
      lightNumber(11);
    }
    break;
  case 2:
    // Only needs to be on for temps 10.0 degrees or above, or 
    // for single-digit subzero temps.
    if (num &gt;= 100 || negative == true) {
      digitalWrite(digit2, HIGH);
    }
    if (num &lt; 100 &amp;&amp; negative == true) {
      lightNumber(11);
    }
    break;
  case 3:
    digitalWrite(digit3, HIGH);
    break;
  case 4:
    digitalWrite(digit4, HIGH);
    break;
  }
  
  //Turn on the right segments for this digit
  lightNumber(toDisplay % 10);
  toDisplay /= 10;
  
  //Turn off all segments
  lightNumber(10); 
  
  //Turn off all digits
  digitalWrite(digit1, LOW);
  digitalWrite(digit2, LOW);
  digitalWrite(digit3, LOW);
  digitalWrite(digit4, LOW);    
  }
  }
  </code></pre>
  
  <p>...And the code for the lightNumber() method turns the segments on or off properly for the numbers 0-9, with 10 being all segments off, and 11 being only the center segment on, for a negative sign. It uses a switch statement with the integer parameter as the switch.
  The problem is, when I send displayNumber() a negative value, instead of a negative sign in front of the number, I get an eight displayed where the negative sign should be. 
  Any ideas why?</p>