// https://wokwi.com/projects/472790836186018817
// for
// https://forum.arduino.cc/t/i-need-some-assistance-with-changing-a-library-initialize-commandd/1455956
// two '595s used as a thermocouple selector
void write16(unsigned int); // bits out to two '595s
# include <SPI.h>
# include <Wire.h>
# include <Adafruit_MAX31855.h>
#define DO 3
#define CS 4
#define CLK 5
// One themocouple
Adafruit_MAX31855 thermocouple(CLK, CS, DO);
void setup() {
Serial.begin(9600);
delay(500);
if (!thermocouple.begin()) { // all thermocouples, just one object
Serial.println("\nERROR.");
while (1) delay(10);
}
setup595();
Serial.println("\nDONE.");
}
void loop() {
static int tcIndex;
write16(~(1 << tcIndex));
double c = thermocouple.readCelsius();
Serial.print("Thermocouple ");
Serial.print(tcIndex);
Serial.print(" Temp = ");
Serial.println(c);
delay(20);
if (++tcIndex >= 16) {
Serial.println("");
tcIndex = 0;
delay(1000);
}
}
//////// the fold
# define DATA 8 // for DS of 74HC595
# define LATCH 9 // for STCP of 74HC595
# define CLOCK 10 // for SHCP of 74HC595
void setup595() {
pinMode(DATA, OUTPUT);
pinMode(CLOCK, OUTPUT);
pinMode(LATCH, OUTPUT);
write16(0);
}
void write16(unsigned int theBits) {
digitalWrite(LATCH, LOW);
for (uint8_t i = 0; i < 16; i++, theBits <<= 1) {
digitalWrite(CLOCK, LOW);
digitalWrite(DATA, (theBits & 0x8000) ? HIGH : LOW);
digitalWrite(CLOCK, HIGH);
}
digitalWrite(LATCH, HIGH);
}
3
2
1
0
15
14
13
12