Need help merging code

Hello so i’ve been trying to replicate a project i found which uses an AD5950 thermocouple amplifier, but i hapen to have a MAX 6675. I found a code that i successfully used to read temperatures with the max 6675 and i need some help merging it to the code from the project i found, any help would be appreciated. The first code is for the MAX 6675 and i want to merge it to the second code.

// Sample Arduino MAX6675 Arduino Sketch

#include “max6675.h”

int ktcSO = 8;
int ktcCS = 9;
int ktcCLK = 10;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

void setup() {
// give the MAX a little time to settle

void loop() {
// basic readout test

Serial.print("Deg C = “);
Serial.print(”\t Deg F = ");


// Define which analog input pin we have connected to the temperature sensor

// if you tie the Arduino’s vRef to the 3.3 volt supply, change this to 3.3

void setup() {

void loop() {
// prints the currrent temperature with 1 place after the decimal point
printFloat(getTemperature(), 1);
// print a carriage return
// rest 100 milliseconds

float CtoF(float c) {
// optionally convert from Celsius to Farenheit if you are into that sorta thing
return c * 9.0 / 5.0 + 32.0;

float analogInToDegreesC(int inputValue) {
// divide by 1023, the maximum possible input value, that scales the input between 0 - 1
// then multiply by the reference voltage, which scales 0-1 to 0-vREF (default is 5V)
// lastly, multiply by 100 to scale it to 10s of millivolts or degrees
return inputValue / 1023.0 * ANALOG_VOTLAGE_REFERENCE * 100.0;
float getTemperature() {
// read the analog input, convert to degrees C, and covert to F
return CtoF(analogInToDegreesC(analogRead(TEMP_SENSOR_PIN)));

// ---- This last function, printFloat isn’t necessary to understand unless you want to
// ---- feel free to ignore it for now, and treat it as a built-in utility,
// ---- it prints out floating point point values

// printFloat prints out the float ‘value’ rounded to ‘places’ places after the decimal point
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;

// make sure we round properly. this could use pow from <math.h>, but doesn’t seem worth the import
// if this rounding step isn’t here, the value 54.321 prints as 54.3209

// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d/= 10.0;
// this small addition, combined with truncation will round our values properly
tempfloat += d;

// first get value tens to be the large power of ten less than value
// tenscount isn’t necessary but it would be useful if you wanted to know after this how many chars the number will take

if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;

// write out the negative if needed
if (value < 0)

if (tenscount == 0)
Serial.print(0, DEC);

for (i=0; i< tenscount; i++) {
digit = (int) (tempfloat/tens);
Serial.print(digit, DEC);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;

// if no places after decimal, stop now and return
if (places <= 0)

// otherwise, write the point and continue on

// now write out each decimal place by shifting digits one by one into the ones place and writing the truncated value
for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
// once written, subtract off that digit
tempfloat = tempfloat - (float) digit;

This Simple Merge Demo may help.

Before trying to merge the programs go through the two of them carefully to make sure they are not both trying to use the same resource - for examples an I/O pin. If you find conflicts change something in one of the separate programs and make sure it still works with the change.


looks like i dont really want to merge them i just want to change this part from the code


So that is takes input from the pins the MAX is conected to

#include "max6675.h"

int ktcSO = 8;
int ktcCS = 9;
int ktcCLK = 10;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

So how i will actually do that ?

The ONLY thing the second code does is print the temperature. It doesn't do anything with it.

The first code prints the temperature in C and F. Just delete one of those and change the 500ms delay to 100ms and it will produce the same output as the first.

Note that the Serial.print() function has an optional second argument which is the number of decimal places to print. That whole printFloat() function is redundant and unnecessary.

To give a bit more background, this is the code i am working on, all i want is to use a different amplifier, than the one used in this.