#include <LiquidCrystal_I2C.h>
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1023; // sensor maximum
char
szStr[30],
szF[6];
// Variables will change:
LiquidCrystal_I2C lcd (0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int inputValue = 0; // Map Sensor input A5 variable 0-5v
int outputPin = 11; // set output pin D11 for Frequency Output 80 to 160Hz
void setup() {
lcd.begin(32, 4); // start the library
lcd.setCursor(0,0);
lcd.print("Tip Volts"); // print message
lcd.setCursor(0,1);
lcd.print("Divider V"); // print message
lcd.setCursor(0,2);
lcd.print("kHz"); // print message
lcd.setCursor(0,3);
lcd.print("Raw"); // print message
}
// the loop routine runs over and over again forever:
void loop()
{
int arcVolts = mapfloat(analogRead(A0),0, 1023, 0, 5.0); // read the input on analog pin A0:
float rawArcVolts = arcVolts * 50;
long range = (mapfloat(analogRead(A0), 0, 1023, 0, 900) * 1000) / 64; // Convert to Frequency 0-900 khz:
tone(11, range);
delay(5);
noTone(11);
lcd.setCursor(10,0); //
lcd.print(dtostrf(abs(mapfloat(analogRead(A0),0, 1023, 0, 5.0)), 2, 4, szF )); // display Input MAP Voltage since power-up
lcd.setCursor(10,1); //
lcd.print(dtostrf(abs(arcVolts * 50), 2, 4, szF )); // display Input MAP Voltage since power-up
lcd.setCursor(4,2); //
lcd.print(dtostrf(abs(range / 1000), 2, 4, szF )); // display Input MAP Voltage since power-up
lcd.setCursor(4,3); //
lcd.print(dtostrf(abs(rawArcVolts), 2, 4, szF )); // display Input MAP Voltage since power-up
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}