#include <Wire.h>
#define tas
#define clrWARN 3 // button to clear WARN pin
#define readTAS 2 // button to read TAS6422 registers over i2c
#define led1 8 // LED1
#define led2 9 // LED2
// variables will change:
int clrWARNs = 0; // State variable for reading the button used to clear latched WARN pin
int readTASs = 0; // State variable for reading the button used to command i2c read
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(clrWARN, INPUT);
pinMode(readTAS, INPUT);
Wire.begin();
Serial.begin(9600);
Serial.println("TAS6422 Diagnostics");
}
void loop() {
clrWARNs = digitalRead(clrWARN);
readTASs = digitalRead(readTAS);
if (clrWARNs == HIGH) {
digitalWrite(led1, HIGH);
Wire.beginTransmission(byte(0xD4));
Wire.write(byte(0x21));
Wire.write(byte(1000000));
delay(500);
}
else {
digitalWrite(led1, LOW);
}
if (readTASs == HIGH) {
digitalWrite(led2, HIGH);
Wire.requestFrom(1, 8); // Ask slave#1 for 8 bytes
while (Wire.available()) {
char c = Wire.read();
Serial.println(c);
delay(500);
}
}
else {
digitalWrite(led2, LOW);
}
}