I am tring to make a simple C++ loop program to read analog values from MCP3004 via SPI. I am using wiringPi libs to make code super clear. Functions works fine, I get proper numbers but not in a loop. I get only 3 first reads and after that only 0. I looked in wiringPi references, libs and I found nothing that would help me. I tried to change delay times but still getting only 3 first proper values. Maybe somebody had that kind of problem and know the answer? Would really appreciate any help.
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <mcp3004.h>
int main()
{
int wart;
wiringPiSetupGpio();
mcp3004Setup (100,0);
while(true)
{
for(int i=0;i<4;i++)
{
wart=analogRead(100);
printf("Value: %d\n", wart);
delay(1000);
}
delay(5000);
}
}
this code gives me for eg.: Value:1004, Value:1003, Value:500, and than only Value:0