#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#include <pcf8591.h>
#define PINBASE 100
/*
cc -o test4 test4.c -lwiringPi
*/
int main (void)
{
int i;
int a2dChannel = 0; // analog channel
float a2dVol;
float Vref = 3.3;
if (pcf8591Setup(PINBASE, 0x48) < 0)
{
printf("pcf8591Setup failed:\n");
}
for(i=0;i<255;i=i+25) {
a2dVol=i * Vref
/ 255;
printf("i=%d
a2dVol=%f[V]\n",i,a2dVol);
analogWrite(PINBASE + a2dChannel,i);
sleep(2);
}
}
|