Thanks for your reply, I have checked the breaks in the protoboard power lines as they have caught me out before! I now fit all my boards with links!
As requested here is my code and attached schematic.
#include <EEPROM.h>
const int buttonPin = 7;
int buttonState;
int lastButtonState = LOW;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
const int analogInPin = A0;
const int analogOutPin = 9;
int sensorValue = 0;
int outputValue = 0;
byte readEEPROM(int address) {
byte data = EEPROM.read(address);
return data;
}
void printContents() {
for (int base = 0; base <= 255; base += 16) {
byte data[16];
for (int offset = 0; offset <= 15; offset += 1) {
data[offset] = readEEPROM(base + offset);
}
char buf[80];
sprintf(buf, "%03x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
base, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7],
data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]);
Serial.println(buf);
}
}
void setup() {
Serial.begin(115200);
pinMode(buttonPin, INPUT);
pinMode(analogOutPin, OUTPUT);
Serial.println("Reading EEPROM");
printContents();
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
// read address
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 16); // highest EEPROM address
analogWrite(analogOutPin, outputValue);
Serial.print("Sensor: ");
Serial.print(sensorValue);
Serial.print("\t");
float voltage = sensorValue * (5.0 / 1023.0);
Serial.print("Voltage: ");
Serial.print(voltage);
Serial.print("\t");
Serial.print("Address: ");
Serial.print(outputValue);
Serial.print("\t");
byte newData = readEEPROM(outputValue);
Serial.print("Data: ");
Serial.println(newData, HEX);
}
}
}
lastButtonState = reading;
}
DAC outputs
Sensor: 747 Voltage: 3.65 Address: 11 Data: 1F
Sensor: 745 Voltage: 3.64 Address: 11 Data: 1F
Sensor: 746 Voltage: 3.65 Address: 11 Data: 1F
Sensor: 746 Voltage: 3.65 Address: 11 Data: 1F
Sensor: 746 Voltage: 3.65 Address: 11 Data: 1F
Sensor: 746 Voltage: 3.65 Address: 11 Data: 1F
Sensor: 746 Voltage: 3.65 Address: 11 Data: 1F
Sensor: 745 Voltage: 3.64 Address: 11 Data: 1F
Sensor: 746 Voltage: 3.65 Address: 11 Data: 1F
Sensor: 746 Voltage: 3.65 Address: 11 Data: 1F
When using a potentiometer on A0
The Serial outputs:
Sensor: 0 Voltage: 0.00 Address: 0 Data: 7E
Sensor: 84 Voltage: 0.41 Address: 1 Data: 30
Sensor: 153 Voltage: 0.75 Address: 2 Data: 6D
Sensor: 221 Voltage: 1.08 Address: 3 Data: 79
Sensor: 293 Voltage: 1.43 Address: 4 Data: 33
Sensor: 360 Voltage: 1.76 Address: 5 Data: 5B
Sensor: 440 Voltage: 2.15 Address: 6 Data: 5F
Sensor: 494 Voltage: 2.41 Address: 7 Data: 70
Sensor: 560 Voltage: 2.74 Address: 8 Data: 7F
Sensor: 606 Voltage: 2.96 Address: 9 Data: 7B
Sensor: 657 Voltage: 3.21 Address: 10 Data: 77
Sensor: 706 Voltage: 3.45 Address: 11 Data: 1F
Sensor: 783 Voltage: 3.83 Address: 12 Data: 4E
Sensor: 848 Voltage: 4.14 Address: 13 Data: 3D
Sensor: 933 Voltage: 4.56 Address: 14 Data: 4F
Sensor: 1001 Voltage: 4.89 Address: 15 Data: 47
Which is perfect!
vinceherman:
Use of code tags on the first post - Karma++
Thanks, back at ya!