Hi,
i have just started a new project where i need a dig potentiometer. I got my hands on AD5242 and somebody gave me their codes on controling it. The thing is that the code doesn't compile and i am quite new to the arduino and don't really understand the code itself.
Code itself:
#include "AD524X.h"
#include "Wire.h"
AD524X AD01(0x2C);
AD524X AD02(0x2D);
AD524X AD03(0x2E);
AD524X AD04(0x2F);
void setup()
{
Serial.begin(115200);
Serial.println("Zacatek mereni: ");
Wire.begin();
TWBR = 72; // 100KHz
}
void loop()
{
int val;
int delayTime = 500;
int resistance = 0;
delay(delayTime);
AD01.write(0, 0);
AD01.write(1, 0);
AD02.write(0, 0);
AD02.write(1, 255);
AD03.write(0, 0);
AD03.write(1, 0);
AD04.write(0, 0);
AD04.write(1, 0);
delay(2000);
for (val = 0; val <= 255; val++, resistance++)
{
AD01.write(0, val);
delay(delayTime);
Serial.println(resistance);
}
for (val = 0; val <= 255; val++, resistance++)
{
AD01.write(1, val);
delay(delayTime);
Serial.println(resistance);
}
for (val = 0; val <= 255; val++, resistance++)
{
AD02.write(0, val);
delay(delayTime);
Serial.println(resistance);
}
for (val = 255; val >= 0; val--, resistance++)
{
AD02.write(1, val);
delay(delayTime);
Serial.println(resistance);
}
for (val = 0; val <= 255; val++, resistance++)
{
AD03.write(0, val);
delay(delayTime);
Serial.println(resistance);
}
for (val = 0; val <= 255; val++, resistance++)
{
AD03.write(1, val);
delay(delayTime);
Serial.println(resistance);
}
for (val = 0; val <= 255; val++, resistance++)
{
AD04.write(0, val);
delay(delayTime);
Serial.println(resistance);
}
for (val = 0; val <= 255; val++, resistance++)
{
AD04.write(1, val);
delay(delayTime);
Serial.println(resistance);
}
delay(1000);
}
AD524X.h
//
// FILE: AD524X.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.03
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
// DATE: 2013-10-12
// URL:
//
// Released to the public domain
//
#ifndef AD524X_h
#define AD524X_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Wire.h>
#define AD524X_VERSION "0.1.03"
#define AS524X_OK 0
#define AS524X_ERROR 100
class AD524X
{
public:
// address
explicit AD524X(const uint8_t);
uint8_t zeroAll();
// rdac
uint8_t read(const uint8_t);
// for debugging
uint8_t readBackRegister(); // returns the last value written in register.
// rdac value
uint8_t write(const uint8_t, const uint8_t);
// rdac value O1 O2
uint8_t write(const uint8_t, const uint8_t, const uint8_t, const uint8_t);
uint8_t setO1(const uint8_t); // HIGH / LOW
uint8_t setO2(const uint8_t); // HIGH / LOW
uint8_t getO1();
uint8_t getO2();
// rdac
uint8_t midScaleReset(const uint8_t);
//
// uint8_t shutDown();
private:
uint8_t send(const uint8_t, const uint8_t); // cmd value
uint8_t _address;
uint8_t _lastValue[2];
uint8_t _O1;
uint8_t _O2;
};
#endif
The error says:
C:\Users\Ivan\AppData\Local\Temp\cchHU81d.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_Ovladani_dig_potenciometru.ino.cpp.o.1886':
cchHU81d.ltrans0.o:(.text.startup+0x76): undefined reference to `AD524X::AD524X(unsigned char)'
cchHU81d.ltrans0.o:(.text.startup+0x80): undefined reference to `AD524X::AD524X(unsigned char)'
cchHU81d.ltrans0.o:(.text.startup+0x8a): undefined reference to `AD524X::AD524X(unsigned char)'
cchHU81d.ltrans0.o:(.text.startup+0x94): undefined reference to `AD524X::AD524X(unsigned char)'
C:\Users\Ivan\AppData\Local\Temp\cchHU81d.ltrans0.ltrans.o: In function `main':
cchHU81d.ltrans0.o:(.text.startup+0x1fa): undefined reference to `AD524X::write(unsigned char, unsigned char)'
cchHU81d.ltrans0.o:(.text.startup+0x206): undefined reference to `AD524X::write(unsigned char, unsigned char)'
cchHU81d.ltrans0.o:(.text.startup+0x212): undefined reference to `AD524X::write(unsigned char, unsigned char)'
cchHU81d.ltrans0.o:(.text.startup+0x21e): undefined reference to `AD524X::write(unsigned char, unsigned char)'
cchHU81d.ltrans0.o:(.text.startup+0x22a): undefined reference to `AD524X::write(unsigned char, unsigned char)'
C:\Users\Ivan\AppData\Local\Temp\cchHU81d.ltrans0.ltrans.o:cchHU81d.ltrans0.o:(.text.startup+0x236): more undefined references to `AD524X::write(unsigned char, unsigned char)' follow
collect2.exe: error: ld returned 1 exit status
exit status 1
I dont really understant where might be the problem and would like to ask you for help. Thank you.