PT8211 dac output

Hello,

Newbie question warning! sorry guys…

I’m trying to modify this pt8211 code to simply output an analogRead value. I’ve managed to make the original code to run without any problems.

I tried to erase the loop and simply leave writeDACChannel(analogRead(A1));
Iithout any success. can anyone point me the right direction?

#include <limits.h>

#ifndef PIN_BCK
#define PIN_BCK   22
#endif

#ifndef PIN_WS
#define PIN_WS    23
#endif

#ifndef PIN_DIN
#define PIN_DIN   24
#endif

#define NOP __asm__ __volatile__ ("nop\n\t")

void writeDACChannel(short waveData)
{
  unsigned char pos = 16;

  // Send data into PT8211 in least significant bit justified (LSBJ) format.
  while(pos > 0)
  {
    pos--;
    digitalWrite(PIN_BCK, LOW);
    // Write next bit in stream into DIN.
    digitalWrite(PIN_DIN, (waveData & (1 << pos)) ? HIGH : LOW);
    NOP;
    // Toggle BCK.
    digitalWrite(PIN_BCK, HIGH);
    NOP;
  }
}

void writeDAC(short waveData)
{
  digitalWrite(PIN_WS, LOW);
  digitalWrite(PIN_BCK, LOW);
  // Write data into right channel of DAC.
  writeDACChannel(waveData);
  digitalWrite(PIN_WS, HIGH);
  // Write data into left channel of DAC.
  writeDACChannel(waveData);
}

void setup() 
{
  pinMode(PIN_BCK, OUTPUT);
  pinMode(PIN_WS, OUTPUT);
  pinMode(PIN_DIN, OUTPUT);
}

void loop() 
{
  short pos = 0;
  while(pos < 360)
  {
    pos += 5;
    if(pos > 360)
    {
      pos = 0;
      continue;
    }

    writeDAC(sin(radians(pos)) * SHRT_MAX);
  }
}

the code was found in this github:

Thanks guys!