//Mystepresponce Embafrsh Solomon //Fab Academy 2021 // Program to use transmit-receive across space between two conductors which are attached to digital pin and another to analog pin. // // // This program has a function MystepResponce() which returns a long integer value. long value; //variable for the result of the tx_rx measurement. int analog_pin = A3; int tx_pin = A2; void setup() { pinMode(tx_pin,OUTPUT); Serial.begin(115200); } long MystepResponce(){ int read_high; int read_low; int diff; long int sum; int SampleTaken = 100; //Number of samples to take. As much sample as possible to reduce scatter. sum = 0; for (int i = 0; i < SampleTaken; i++){ digitalWrite(tx_pin,HIGH); //Step up voltage on conductor 1. read_high = analogRead(analog_pin); //Measure response on conductor 2. delayMicroseconds(100); //wait untill steady state. digitalWrite(tx_pin,LOW); //Step down voltage on conductor 1. read_low = analogRead(analog_pin); //Measure response on conductor 2. diff = read_high - read_low; //the difference on high and low readings of condutor 2. sum += diff; //Sums up N_samples of these measurements. } return sum; } void loop() { value = MystepResponce(); value = map(value, 8000, 11000, 0, 1024); Serial.println(value); delay(100); }