title: DAC0808 doesn't want tranfer to analog
body: <p>my lecture gave us DAC lab. He asks to make a sawtooth waveform in 8 bit from Arduino and then connect it DAC0808 to produce an analog signal with an amplifier. So we made an a circuit. Checked it. It works. Then started to do the calculations and expected results. We have done that. And the last we make a program in the wiring language. I wanted to make a step further and made a program which accepts different inputs from serial and changes the types of waveforms. But when we tried to check the working circuit for somereason it didn't want to work. I checked the program on 8 LEDS and they all workign perfect. But we put i  ht ecircuit and check on osciliscope it shows 9.7 volts when it should have 0 or 5 volts. The bits still went to DAC inputs but DAC didn't translate them to analog output. <a href="https://i.stack.imgur.com/jDC1y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jDC1y.png" alt="enter image description here"></a></p>
  
  <p>The lecturer sure the problem is in my complex problem rather then in my circuit or maybe with my processor, but I noticed very strange voltage output. When I touch the HIGH input voltage on DAC by multimeter it gives that value out. He still thinks it's problem with the code because his simple version works. :c</p>
  
  <ul>
  <li>So if it is I want to know where?</li>
  <li>Or why i doesn't?</li>
  </ul>
  
  <p>The code:</p>
  
  <pre><code>    //Global Variables
  enum wave {SAWTOOTH = 49, TRIANGLE, SQUARE, SINE, TANGENT};
  int incomingByte;
  int lastState = 0;
  int calcResult;
  int binaryOutput;
  int triangleCheck;
  int squareCheck;
  int squareCount;
  int sineOutput;
  int tangentOutput;
  int pin[8];
  
  //Prototypes
  int bitConversion(int);
  
  //Setup
  void setup() {
    Serial.begin(250000);
    for (int i = 2; i &lt; 10; i++)
    {
      pinMode(i, OUTPUT);
      pin[i - 2] = i;
    }
  }
  
  void loop() {
    if (Serial.available())
      incomingByte = (int)Serial.read();
  
    Serial.print("Incoming Byte: ");
    Serial.write(incomingByte);
    Serial.println();
    Serial.print("Last State: ");
    Serial.write(lastState);
    Serial.println();
  
    if (incomingByte != lastState)
    {
      lastState = incomingByte;
      calcResult = 0;
      triangleCheck = 0; 
      squareCheck = 0;
      squareCount = 0;
      sineOutput = 0;
      tangentOutput = 0;
      Serial.println("State changed!");
    }
  
    Serial.print("STATE:                 ");
    switch (lastState)
    {
      case (SAWTOOTH):
        Serial.println("SAWTOOTH WAVE");
        Serial.println("------------------------------------------");
        if (calcResult == 255)
          calcResult = 0;
        calcResult++;
        break;
  
      case (TRIANGLE):
        Serial.println("TRIANGLE WAVE");
        Serial.println("------------------------------------------");
        if (calcResult == 255 || !calcResult)
        {
          Serial.println("Triangle changed!");
          Serial.println();
          triangleCheck++;
        }
        if ((triangleCheck % 2))
        {
          Serial.print("ODD   ");
          calcResult++;
        }
        else
        {
          Serial.print("EVEN  ");
          calcResult--;
        }   
        break;
  
      case (SQUARE):
        Serial.println("SQUARE WAVE");
        Serial.println("------------------------------------------");
        if (squareCount == 255 || squareCount == 0)
        {
          Serial.println("Square changed!");
          Serial.println();
          squareCheck++;
        }
        if ((squareCheck % 2))
        {
          Serial.print("ODD   ");
          calcResult = 0;
          squareCount++;
        }
        else
        {
          Serial.print("EVEN  ");
          calcResult = 255;
          squareCount--;
        }
        break;
  
      case (SINE):
        Serial.println("SINE WAVE");
        Serial.println("------------------------------------------");
        calcResult = 128+128*sin(2*PI*100*(sineOutput/10000.0));
        sineOutput++;
        break;
  
      case(TANGENT):
        Serial.println("TANGENT WAVE");
        Serial.println("------------------------------------------");
        calcResult = 128+64*tan(2*PI*100*(tangentOutput/10000.0));
        tangentOutput++;
        break;
  
      default:
        Serial.println("DEFAULT");
        Serial.println("------------------------------------------");
        calcResult = 0;
        break;
    }
  
    binaryOutput=calcResult;
    Serial.print("Binary Output: ");
    Serial.println(binaryOutput, DEC); 
  
    if (binaryOutput)
    {
      for (int i = 7; i &gt;= 0; i--)
      {
        if (binaryOutput &gt;= bitConversion(i))
        {
          digitalWrite(pin[i], HIGH);
          binaryOutput -= bitConversion(i);
          Serial.print(1);
          Serial.print(" ");
        }
        else
        {
          digitalWrite(pin[i], LOW);
          Serial.print(0);
          Serial.print(" ");
        }
      }
    }
  
    else
    {
      for (int i = 7; i &gt;= 0; i--)
      {
        pinMode(pin[i], LOW);
        Serial.print(0);
        Serial.print(" ");
      }
    }
    Serial.println("\n\n");
    delay(50);
  }
  
  int bitConversion(int n)
  {
    int result = 1;
    for (int i = 0; i&lt;n; i++)
      result *= 2;
    return result;
  
  }
  </code></pre>