We are designing an Electronic Load (Lab Test equipment)and trying to create some sort of 4 button Menu feature as shown in the attachment picture from my post. For example when Buttons are pressed it will bring you into a settings menu to set a value for current or power factor, etc.
- Button 1 will be labeled Constant Current and once pressed it have you set a value for current using the potentiometer.
- Button 2 same idea but for power factor.
- Button 3 another option, maybe crest factor or something.
The once all the settings are set and saved you would hit - Button 4 "Load" to output the current and setting selected to say load down an power supply.
Below is a code we have developed so far that maybe can be tweaked, any advice or help would be greatly appreciated.
#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
#include <Wire.h>
//#include <Adafruit_ADS1015.h>
//#include <Adafruit_MCP4725.h>
// LCD innitiation
const int rs = 13, en = 12, d4 = 8, d5 = 9, d6 = 10, d7 = 11;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//ADC innitiation
//Adafruit_ADS1015 ads;
//DAC innitiation
//Adafruit_MCP4725 dac;
//Buttons define
int BT1=6;
int BT2=5;
int BT3=4;
int BT4=3;
int LED1=2;
int LED2=17;
int LED3=18;
int LED4=19;
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
//-----------------------------LCD setup
lcd.begin(16, 2);
//-----------------------------ADC setup
// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC!
// ADS1015 ADS1115
// ------- -------
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
// ads.begin();
//---------------------------DAC setup
// For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
// For MCP4725A0 the address is 0x60 or 0x61
// For MCP4725A2 the address is 0x64 or 0x65
// dac.begin(0x62);
// -------------------------------Buttons and led declaration
pinMode(3,INPUT_PULLUP) ; //Button 1
pinMode(4,INPUT_PULLUP) ; //Button 2
pinMode(5,INPUT_PULLUP) ; //Button 3
pinMode(6,INPUT_PULLUP) ; //Button 4
pinMode(7,OUTPUT) ; //RELCONT pin to controll main relay
pinMode(2,OUTPUT) ; // LED 1
pinMode(A3,OUTPUT) ; // LED 2
pinMode(A4,OUTPUT) ; // LED 3
pinMode(A5, OUTPUT); // LED 4
pinMode(A0, INPUT); // POT1 read control potentiometer
}
void loop() {
POT_test();
BT_LED_test();
}
void LCD_test(){
lcd.setCursor(0, 0);
lcd.print("LCD TEST LINE #1");
lcd.setCursor(0, 1);
lcd.print("LCD TEST LINE #2");
}
void BT_LED_test(){
if (digitalRead(BT1)==1){
digitalWrite(LED1,LOW);
lcd.setCursor(0,0);
lcd.print("BT1_H");
}
else{
digitalWrite(LED1,HIGH);
lcd.setCursor(0,0);
lcd.print("BT1_L");
}
Serial.print(digitalRead(BT1));
Serial.print("\n");
//-----------------------------------
if (digitalRead(BT2)==1){
digitalWrite(LED2,LOW);
lcd.setCursor(6,0);
lcd.print("BT2_H");
}
else{
digitalWrite(LED2,HIGH);
lcd.setCursor(6,0);
lcd.print("BT2_L");
}
Serial.print(digitalRead(BT2));
Serial.print("\n");
//-----------------------------------
if (digitalRead(BT3)==1){
digitalWrite(LED3,LOW);
lcd.setCursor(11,0);
lcd.print("BT3_H");
}
else{
digitalWrite(LED3,HIGH);
lcd.setCursor(11,0);
lcd.print("BT3_L");
}
Serial.print(digitalRead(BT3));
Serial.print("\n");
//-------------------
if (digitalRead(BT4)==1){
digitalWrite(LED4,LOW);
lcd.setCursor(0,1);
lcd.print("BT4_H");
}
else{
digitalWrite(LED4,HIGH);
lcd.setCursor(0,1);
lcd.print("BT4_L");
}
Serial.print(digitalRead(BT4));
Serial.print("\n");
}
void POT_test(){
int aread=analogRead(A0);
lcd.setCursor(9,1);
lcd.print("POT");
lcd.setCursor(12,1);
lcd.print(aread);
}
/* void ADC_test()
{
int16_t adc0, adc1, adc2, adc3;
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
Serial.print("AIN0: "); Serial.println(adc0);
Serial.print("AIN1: "); Serial.println(adc1);
Serial.print("AIN2: "); Serial.println(adc2);
Serial.print("AIN3: "); Serial.println(adc3);
Serial.println(" ");
}
void DAC_test() {
uint32_t counter;
// Run through the full 12-bit scale for a triangle wave
for (counter = 0; counter < 4095; counter++)
{
dac.setVoltage(counter, false);
}
for (counter = 4095; counter > 0; counter--)
{
dac.setVoltage(counter, false);
}
}*/