// sigAnalyser01
// working state machine , one probe with three pins 100R, 1000R, 100000R, one probe ADC read
// First proof of concept prototype, looks promising ...
//----------------------------------------------------------------------------------------
int ledPin = 13;
//Probe1 (main probe) pin asignments
int probe1PinA = A0;//100R and probe1 analog read
int probe1PinB = 8;//1000R
int probe1PinC = 9;//100000R
//Probe2 (secondary or chassis) pin asignments:
int probe2PinA = A1; //100R and probe2 Analog Read
int probe2PinB = 10; //1000R
int probe2PinC = 11; //100000R
int aRead;
int bRead;
int probe1Result[10];
int probe2Result[10];
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
unsigned long intervalMillis = 0;
// enum not used in this program...
enum pModes {
noLoad, // noLoad (=0, no initalizer so underlying default value is 0)
PinHigh, // (=1, auto incriment of previous)
PinLow, // we want the led to be on for interval (=2, auto incriment of previous)
};
// now make a variable we can use--- not used in this program
enum pModes pinState; // create a variable called pinstate of type pModes.
// use a 2D array as a state machine
// 100R 1000R 100000R 100R 1000R 100000R
// Probe1PinA, Probe1PinB, Probe1PinC, Probe2PinA, Probe2PinB, Probe2PinC
int TestModePins[10][6] = {
// 0=noLoad, 1=HIGH, 2=LOW. Zero indexed
{ 0, 0, 2, 0, 0, 1 }, //noLoad noLoad LOW noLoad noLoad HIGH
{ 0, 0, 2, 0, 1, 0 }, //noLoad noLoad LOW noLoad HIGH noLoad
{ 0, 2, 0, 0, 1, 0 }, //noLoad LOW noLoad noLoad HIGH noLoad
{ 0, 2, 0, 1, 0, 0 }, //noLoad LOW noLoad HIGH noLoad noLoad
{ 2, 0, 0, 1, 0, 0 }, //LOW noLoad noLoad HIGH noLoad noLoad
{ 0, 0, 1, 0, 0, 2 }, //noLoad noLoad HIGH noLoad noLoad LOW
{ 0, 0, 1, 0, 2, 0 }, //noLoad noLoad HIGH noLoad LOW noLoad
{ 0, 1, 0, 0, 2, 0 }, //noLoad HIGH noLoad noLoad LOW noLoad
{ 0, 1, 0, 2, 0, 0 }, //noLoad HIGH noLoad LOW noLoad noLoad
{ 1, 0, 0, 2, 0, 0 } //HIGH noLoad noLoad LOW noLoad noLoad
};
//=======================================================================================
void setup() {
pinMode(ledPin, OUTPUT); // LED pin as output
digitalWrite(ledPin, LOW); // make sure LED is OFF
pinMode(probe1PinA, OUTPUT);
pinMode(probe1PinB, OUTPUT);
pinMode(probe1PinC, OUTPUT);
pinMode(probe2PinA, OUTPUT);
pinMode(probe2PinB, OUTPUT);
pinMode(probe2PinC, OUTPUT);
Serial.begin(115200);
Serial.println("Start");
}
//########################################################################################
void loop() {
pinMode(probe1PinA, INPUT); // noLoad
pinMode(probe1PinB, INPUT); // noLoad
pinMode(probe1PinC, INPUT); // noLoad
//pinMode(probe2PinA, INPUT); // noLoad
//pinMode(probe2PinB, INPUT); // noLoad
//pinMode(probe2PinC, INPUT); // noLoad
Serial.println("-");
for (int i = 0; i < 10; i++) {
Serial.print(probe1Result[i]);
Serial.print(", ");
}
Serial.println();
for (int i = 0; i < 10; i++) {
Serial.print(probe2Result[i]);
Serial.print(", ");
}
Serial.println();
intervalMillis = millis() - previousMillis;
//Serial.print(intervalMillis);
delay(100);
for (int i = 0; i < 10; i++) { // loop 10 times zero indexed
previousMillis = millis();
for (int p = 0; p < 7; p++) { // just do the probe1 pins A B C fo now
//testModePins[i][p];//i is the current test mode, p 0,1,2 is probe1 pinstate
// p 0,1,2 are just for probe1's three pins A B C
//delay(1000);
if (p == 0) { //do probe1PinA
switch (TestModePins[i][p]) {
case 0:
pinMode(probe1PinA, INPUT); // noLoad
//Serial.print("p0 noload");
break;
case 1:
pinMode(probe1PinA, OUTPUT);
digitalWrite(probe1PinA, HIGH); // HIGH-Vcc
//Serial.print("p0 high ");
break;
case 2:
pinMode(probe1PinA, OUTPUT);
digitalWrite(probe1PinA, LOW); // LOW(Gnd)
//Serial.print("p0 low ");
break;
}
}
if (p == 1) { //do probe1PinB
switch (TestModePins[i][p]) {
case 0:
pinMode(probe1PinB, INPUT); // noLoad
//Serial.print("p1 noload");
break;
case 1:
pinMode(probe1PinB, OUTPUT);
digitalWrite(probe1PinB, HIGH); // HIGH-Vcc
//Serial.print("p1 high ");
break;
case 2:
pinMode(probe1PinB, OUTPUT);
digitalWrite(probe1PinB, LOW); // LOW(Gnd)
//Serial.print("p1 low ");
break;
}
}
if (p == 2) { //do probe1PinC
switch (TestModePins[i][p]) {
case 0:
pinMode(probe1PinC, INPUT); // noLoad
//Serial.print("p2 noload");
break;
case 1:
pinMode(probe1PinC, OUTPUT);
digitalWrite(probe1PinC, HIGH); // HIGH-Vcc
//Serial.print("p2 high ");
break;
case 2:
pinMode(probe1PinC, OUTPUT);
digitalWrite(probe1PinC, LOW); // LOW(Gnd)
//Serial.print("p2 low ");
break;
}
}
if (p == 3) { //do probe1PinA
switch (TestModePins[i][p]) {
case 0:
pinMode(probe2PinA, INPUT); // noLoad
//Serial.print("p0 noload");
break;
case 1:
pinMode(probe2PinA, OUTPUT);
digitalWrite(probe2PinA, HIGH); // HIGH-Vcc
//Serial.print("p0 high ");
break;
case 2:
pinMode(probe2PinA, OUTPUT);
digitalWrite(probe2PinA, LOW); // LOW(Gnd)
//Serial.print("p0 low ");
break;
}
}
if (p == 4) { //do probe1PinB
switch (TestModePins[i][p]) {
case 0:
pinMode(probe2PinB, INPUT); // noLoad
//Serial.print("p1 noload");
break;
case 1:
pinMode(probe2PinB, OUTPUT);
digitalWrite(probe2PinB, HIGH); // HIGH-Vcc
//Serial.print("p1 high ");
break;
case 2:
pinMode(probe2PinB, OUTPUT);
digitalWrite(probe2PinB, LOW); // LOW(Gnd)
//Serial.print("p1 low ");
break;
}
}
if (p == 5) { //do probe2PinC
switch (TestModePins[i][p]) {
case 0:
pinMode(probe2PinC, INPUT); // noLoad
//Serial.print("p2 noload");
break;
case 1:
pinMode(probe2PinC, OUTPUT);
digitalWrite(probe2PinC, HIGH); // HIGH-Vcc
//Serial.print("p2 high ");
break;
case 2:
pinMode(probe2PinC, OUTPUT);
digitalWrite(probe2PinC, LOW); // LOW(Gnd)
//Serial.print("p2 low ");
break;
}
}
}
delay(10);
aRead = analogRead(A0);
bRead = analogRead(A1);
probe1Result[i] = aRead;
probe2Result[i] = aRead;
}
//delay(2000); // Wait for 5 seconds before repeating the loop
}
//#######################################################################################
//if (pinState == noLoad) {
// pin to INPUT mode
// digitalWrite(ledPin, LOW);