Hi.
THE divider is not as complicated project as I made it, I am working on it.
THE sainsmart lcd keypad came in, Squirrels in the CHINGLISH translation.
Pins are not exactly what they should set up as, THE drivers for #include libraries had me puzzled, they have to be in exactly the right directory to not give a error. Had me scratching my head for a bit. Working great, highly visible 16x2 display with 5 useable buttons, one reset.. (blind man could hardly see) They throw a analog signal by using resistors, different numbers come back and the driver chooses what input.
I got a pretty good grasp of the millisecond timer now thou, grab it as a millis() call..store it in a variable, then compare to actual-desired time instead of locking the program in a "STOP RIGHT HERE" delay(ms) loop. This will come in handy throwing a 6ms pulse to the stepper drive step pin..
Spot welder code works good enough to put in, I am awaiting the uno's to implement it. I'll start fabbing a panel for it.
'*************** code rewritten this morning 12-31-13 *****
/* Written by Cofer, NORF Gawgia, USA on 12-29-13
I Modified code for creating a sequence timer for a spot welder, this unit
first applies a solenoid output to clamp the spot welder tongs, then times to close fully
and apply pressure, then the SSR fires for a timed output, the SSR times out then
the unit loops on one line till you lift your footpedal switch, then it resets to
the beginning of the program to loop for next sequence. THIS unit uses a PB4 Opto22
ttl-relay module based board, it SINKS the TTL power to turn on the modules, so it
appears reversed, would be if your output device is different. 12/31/13 Modified to
use the sainsmart keypad LCD. It connects A0 analog to buttons divided by resistors
to differentiate the buttons in voltages into the analog input. DF Robot code, plus
SainSmart Code, plus mine added by cut and paste.
(millis()/1000)
*/
#include <LiquidCrystal.h> // include this library of lcd operations
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,13,9,4,5,6,7);// Set up for my MEga 2560 pins
//**************************************************
int button1 = 38; // change to reflect pins on the UNO
int button2 = 39; // change button
int Solenoid1 = 48; // air solenoid clamp for welder
int SSR1 =49; // SSR welder output
int footpedal = 41; // foot pedal input
int buttonstate1; // variable to store state in.
int buttonstate2;
int Clamp_flg;
long startTime;
long endTime;
//******************************************
// variables for Timer variables
int ClampTime = 9000; // setpoint for clamp timer
int WeldTime = 3000 ; // variable for weld timer
// set up the analog input pin for keypad
//int sensorPin = A0; //
//int sensorValue = 0; // variable to store the value coming from the sensor
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons ***************************
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// input for analog voltage divider, multiple inputs for one A-Input
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16,2); // set up the display type
// Print a message to the LCD.
lcd.print(0x00); // display off
//delay(50);
lcd.print(0x04); // display on
lcd.print(0x01); // clear the display
lcd.print(0x02); // reset to home
lcd.print(0x04);
// set up pins, inputs outputs
pinMode(Solenoid1,OUTPUT);
pinMode(SSR1,OUTPUT);
pinMode(button1,INPUT);
pinMode(button2,INPUT);
pinMode(footpedal,INPUT);
//Serial.begin(19200);
digitalWrite(Solenoid1,HIGH);
digitalWrite(SSR1,HIGH);
//SetupScreen;
lcd.setCursor(0, 0);
lcd.print("Clamp Time "+ String(ClampTime));
lcd.setCursor(0,1);
lcd.print("Weld time " + String(WeldTime));
}
void loop()
{
lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
lcd.setCursor(11, 0);
lcd.print(" "); //blank the space
ClampTime = ClampTime + 10;
lcd.setCursor(0, 0);
lcd.print("Clamp Time " + String(ClampTime));
delay(200);
break;
}
case btnLEFT:
{
lcd.setCursor(11, 0);
lcd.print(" "); //blank the space
ClampTime = ClampTime - 10;
lcd.setCursor(0, 0);
lcd.print("Clamp Time " + String(ClampTime));
delay(200);
break;
}
case btnUP:
{
lcd.setCursor(11, 1);
lcd.print(" "); //blank the space
WeldTime = WeldTime + 10;
lcd.setCursor(0,1);
lcd.print("Weld time " + String(WeldTime));
delay(200);
break;
}
case btnDOWN:
{
lcd.setCursor(11, 1);
lcd.print(" "); //blank the space
WeldTime = WeldTime - 10;
lcd.setCursor(0,1);
lcd.print("Weld time " + String(WeldTime));
delay(200);
break;
}
case btnSELECT:
{
//lcd.print("SELECT");
Clamp_flg = 1; // set the flag
break;
}
case btnNONE:
{
//lcd.print("NONE ");
break;
}
}
//******Confirm variables in tolerance
if (WeldTime > 9999){
WeldTime = 9999;
}
if (WeldTime < 500){
WeldTime = 500;
}
if (ClampTime > 9999){
ClampTime = 9999;
}
if (ClampTime < 500){
ClampTime = 500;
}
// if foot switch then cycle turn the ledPin on
while (Clamp_flg == 1){
//while (digitalRead(footpedal) == LOW ) { // appears reversed logic
// digitalWrite(ledPin, HIGH );
// TURN ON SOLENOID to clamp
startTime = millis();
endTime = (ClampTime + millis());
digitalWrite(Solenoid1,LOW);
lcd.clear(); // clear the display
while (millis() < endTime) {
lcd.setCursor(0, 0);
lcd.print("Solenoid on " + String(endTime - millis()));
delay(500); // slow down screen update
}
lcd.setCursor(0, 0);
lcd.print("CLAMPED ");
// TURN ON SSR and count down
startTime = millis();
digitalWrite(SSR1,LOW); // turn the SSR module on
endTime = (WeldTime + millis());
while (millis() < endTime) {
lcd.setCursor(0, 1);
lcd.print("SSR on " + String(endTime - millis()));
delay(500); // slow down screen update
}
// OFF SSR
digitalWrite(SSR1,HIGH);
// clean up display, status
lcd.clear(); // clear the display
lcd.setCursor(0, 0);
lcd.print("Solenoid on ");
lcd.setCursor(0, 1);
lcd.print("SSR off ");
delay(5000);
// stay looping here till pedal up
//while (digitalRead(footpedal) == LOW );
// stay here till footpedal up
// OFF SOLENOID clamp
digitalWrite(Solenoid1,HIGH);
//************ reset the screen *****
lcd.clear();
lcd.print("Input Ready ");
delay(5000);
lcd.clear();
lcd.print("Clamp Time " + String(ClampTime));
lcd.setCursor(0,1);
lcd.print("Weld time " + String(WeldTime));
//************ reset the flag *********
Clamp_flg = 0; // set the flag
}
}