I agree.
Just finished designing schematic and parts should be with me in the next few days. I wanted to get started on the code as its my weakest skill or lack there of. In my experience, I can complete a build in a blink of an eye but the code is what holds me back.
Yes i have changed it about, thanks it compiles ok now, but if you would be so kind and give it a second look it will be much appreciated.
.
//Bench PSU Arduino LCD
/*-----( Import needed libraries )-----*/
#include <Wire.h>
#include <LiquidCrystal.h>
#define PWRBTN 2
#define PWROK_PIN 4
#define PWRTRANS 6
//sensor info
const int three = 6; // Analog input pins that the sensor is attached to
const int five = 7;
const int fivex = 8;
const int twelve = 9;
const int Vrone = 10;
const int Vrtwo = 11;
double threeI = 0; // intialize variable currnent
double fiveI = 0;
double fivebI = 0;
double twelveI = 0;
double VroneI= 0;
double VrtwoI = 0;
double threeVo = 0;
double fiveVo = 0; // initialize variable for sensor output voltage
double fivebVo = 0;
double twelveVo = 0;
double VroneVo = 0;
double VrtwoVo = 0;
/*-----( Declare objects )-----*/
// Variables will change:
int PWRSTATE = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //16,4
LiquidCrystal lcd2(12, 10, 5, 4, 3, 2);//16,2
float threeV, fiveV,fiveb, twelveV, VroneV, VrtwoV;
float threevolts, fivevolts,fivebs, twelvevolts, Vronevolts, Vrtwovolts;
void LCDSetup(){
lcd.begin(16, 4);
lcd2.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0); //take this out if monitor buggy
lcd.print("Bench PSU");// this code be fine
lcd.setCursor(0,1);
lcd.print("Monitor V1.0");
lcd.setCursor(0,2);
lcd.print("ICE");
lcd.setCursor(4,3);
lcd.print("ROBOTICS");
lcd2.begin(16, 2); // replace with the date_time function
lcd2.setCursor(0,0);
lcd2.print("Hope 4 the best");
lcd2.setCursor(0, 1);
lcd2.print("prep 4 the worst");
delay(3000);
lcd.clear(); // wipes old message
lcd.setCursor(0,0);
lcd.print("Building");
lcd.setCursor(6,1);
lcd.print("The Future");
lcd.setCursor(0,1);
lcd.print("since 2014");
delay(2500);
//Inset the time function somewhere in here
lcd.clear();
lcd2.clear();
}
void readVoltages(){
threeV = (analogRead(A0)* 5)/1024.0; // attched to voltage deviders
fiveV = (analogRead(A1)* 5)/1024.0;
fiveb = (analogRead(A2)* 5)/1024.0;
twelveV = (analogRead(A3)* 5)/1024.0;
VroneV = (analogRead(A4)* 5)/1024.0;
VrtwoV = (analogRead(A5)* 5)/1024.0;
}
void calculatePrintVoltages(){
threevolts = threeV;
lcd.setCursor(0,0);
lcd.print(threevolts);
lcd.setCursor(5,0);
lcd.print("V");
fivevolts = (fiveV)/ (1770.0/(182.0+1770.0));
lcd.setCursor(0,1);
lcd.print(fivevolts);
lcd.setCursor(5,1);
lcd.print("V");
fivebs = (fiveb)/ (1770.0/(182.0+1770.0)); // usb rail
lcd.setCursor(0,2);
lcd.print(fivebs);
lcd.setCursor(5,2);
lcd.print("V");
twelvevolts = (twelveV ) / (1770.0/(4650.0+1770.0));
lcd.setCursor(0,3);
lcd.print(twelvevolts);
lcd.setCursor(5,3);
lcd.print("V");
Vronevolts = (VroneV ) / (1770.0/(11890.0+1770.0));
lcd2.setCursor(0,0);
lcd2.print(Vronevolts);
lcd2.setCursor(5,0);
lcd2.print("V");
Vrtwovolts = (VrtwoV ) / (1770.0/(11920.0+1770.0));
lcd2.setCursor(0,1);
lcd2.print(Vrtwovolts);
lcd.setCursor(5,1);
lcd.print("V");
}
// uncomment the below code, it wont work with this
void checkPowerOK(){
if (digitalRead(PWROK_PIN) == HIGH) {
lcd.setCursor(8,2);
lcd.print("ON ");
lcd2.setCursor(4,0);
lcd2.print("Hello");
}
else if (digitalRead(PWROK_PIN) == LOW) {
lcd.setCursor(8,2);
lcd.print("OFF");
lcd2.setCursor(3, 0);
lcd2.print("Good bye");
}
}
void togglePower(){
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 500)
{
// set the power:
digitalWrite(PWRTRANS, PWRSTATE);
}
PWRSTATE = !PWRSTATE;
last_interrupt_time = interrupt_time;
}
void setup() /****** SETUP: RUNS ONCE ******/
{
LCDSetup();
pinMode(PWRBTN, INPUT);
pinMode(PWRTRANS, OUTPUT);
attachInterrupt(0, togglePower, RISING);
digitalWrite(PWRTRANS, PWRSTATE);
}
//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/{
checkPowerOK();
readVoltages();
calculatePrintVoltages();
delay(250);
//read the analog in value
threeVo = analogRead(three)*5.0/1023.0;
// calibration to get actual current value
threeI = (threeVo -2.5 )/0.185;
//print to lcd
lcd.setCursor(7,0);
lcd.print(threeI);
lcd.setCursor(14,0);
lcd.print("A");
delay(4);
fiveVo = analogRead(five)*5.0/1023.0;
// calibration to get actual current value
fiveI = (fiveVo -2.5 )/0.185;
lcd.setCursor(7,1);
lcd.print(fiveI);
lcd.setCursor(14,1);
lcd.print("A");
delay(4);
fivebVo = analogRead(fivex)*5.0/1023.0;
// calibration to get actual current value
fivebI = (fivebVo -2.5 )/0.185;
lcd.setCursor(7,2);
lcd.print(fivebI);
lcd.setCursor(14,2);
lcd.print("A");
delay(4);
twelveVo = analogRead(twelve)*5.0/1023.0;
// calibration to get actual current value
twelveI = (twelveVo -2.5 )/0.185;
lcd.setCursor(7,3);
lcd.print(twelveI);
lcd.setCursor(14,3);
lcd.print("A");
delay(4);
VroneVo = analogRead(Vrone)*5.0/1023.0;
//calibration
VroneI = (VroneVo - 2.5 )/0.185;
lcd2.setCursor(0,0);
lcd2.print(VroneI);
lcd2.setCursor(5,0);
lcd2.print("A");
delay(4);
VrtwoVo = analogRead(Vrtwo)*5.0/1023.0;
//calibration
VrtwoI = (VrtwoVo - 2.5 )/0.185;
lcd2.setCursor(0,1);
lcd2.print(VrtwoI);
lcd2.setCursor(5,1);
lcd2.print("A");
delay(4);
}
//--(end main loop )---
//*********( THE END )***********