I thought I'd share this project I've been working on. Comparatively, I'm in my programming infancy and in actuality this was probably WAY above my head, but I stumbled my way through it anyway over the last 2 weeks with countless hours of Google, YouTube, and brute force. I'm a "dive head first" kind of guy, sometimes into shark infested waters, so I'm sure there are plenty of areas that could be optimized. Constructive feedback is always welcomed.
There isn't need to go into the weeds about cartridge reloading or metallurgy in this, so I'll spare you the details. I will bring up a few points though;
- Annealing brass cartridge cases improves longevity as well as accuracy if done correctly.
- Consistency is key.
- Reloading presses move in a reciprocal manner.
- Progressive reloading presses (which I am using for this) move a cartridge case through the station with every pull of the handle.
The way I have this laid out is Arduino B is married up to a keypad and a has an LCD for seconds down to 2 decimal places. It also has rolling digits. Put in 1.58, press 0, becomes 5.80. * is a clear function, and # sends the integer group to Arduino A to input for the timer as milliseconds.
The top button ("Trigger") will be a micro switch inside the top of the press that will activate when the ram is raised, bringing the case into the annealer coil. Once triggered, the 120VDC induction coil will activate via relay (simulated on TinkerCAD by a lightbulb) for the amount of time sent from Arduino B's keypad and then shut off even if the ram is left in the up position. I didn't want the loop reheating the same case if left for too long. The relay completely isolates the induction coil from the loop until the system is reset.
Bringing the ram into the down position, and cycling in a new brass case, will trip another micro switch at the bottom of the stroke ("Reset") which unlocks the trigger pin again as well as doing a plus up on the case counter on Arduino A's LCD.
The ping and pong of the micro switches can continue up to 9999 times to have a solid count on the LCD if one chooses, I never batch more than 200 pieces of brass usually, but I like symmetry, hence why the counter is 4 digits and 6 blanks on either side.
Once you are satisfied with the count, there is another button ("Reset") that is next to the light bulb relay on TinkerCAD, and will just be mounted on my press station for real, that will clear out the count and bring it back to "0000".
Have noticed that it runs an little slow currently and the buttons need to be held in order to move along the program, but I can't confirm if that is issues within the code or just my computer and internet match-up.
I will soon be actually building this so if there is a glaring issue, please let me know what to address before I put it to perf/PCB. The actual device will likely be with Nanos.
I will say, I am truly impressed that I was able to come up with this, making the essentially "stop and wait" without digitally stopping the loop with a wait function that freezes the program in my minute experience. Very incredible what these controllers are capable of
Arduino A Code;
#include <Adafruit_LiquidCrystal.h>
const int LED = 6;
const int PowerSupply = 8;
const int Clear = 7;
const int TriggerRelay = 3;
const int Trigger = 5;
const int Reset = 4;
const int ResetRelay = 2;
Adafruit_LiquidCrystal lcd_1(0);
char currentCountValue[4];
int buttonState=0;
int d1=0, d2=0, d3=0, d4=0;
unsigned int integerValue=0;
unsigned int integerMil=0;
char incomingByte;
void setup() {
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
  pinMode(PowerSupply, OUTPUT);
  pinMode(Clear, INPUT);
  pinMode(Trigger, INPUT);
  pinMode(Reset, INPUT);
  pinMode(TriggerRelay, OUTPUT);
  pinMode(ResetRelay, OUTPUT);
  lcd_1.begin(16, 2);
  
  displayCountEntryScreen();
}
void loop() {
  
  buttonState = digitalRead(Trigger);
  if (buttonState == HIGH) { 
  digitalWrite(PowerSupply, HIGH);
    delay(integerMil);
    digitalWrite(PowerSupply, LOW);
    digitalWrite(TriggerRelay, HIGH);
    digitalWrite(ResetRelay, HIGH);
  digitalWrite(LED, HIGH);
    
  }
    
  buttonState = digitalRead(Reset);
  if (buttonState == HIGH) { 
    digitalWrite(TriggerRelay, LOW);
    d1=d1+1;
    if(d1>9){d1=0; d2=d2+1;}
    if(d2>9){d2=0; d3=d3+1;} 
    if(d3>9){d3=0; d4=d4+1;}  
    if(d4>9){d4=0;} 
    
    
  	digitalWrite(LED, LOW);
  	digitalWrite(ResetRelay, LOW);   
 
  }
  
  buttonState = digitalRead(Clear);
  if (buttonState == HIGH) { 
    d1=0, d2=0, d3=0, d4=0;
  }
  
   if (Serial.available() > 0) {
    integerValue = 0;
    integerMil = 0;
    while(1) {
      incomingByte = Serial.read();
      if (incomingByte == '\n') break; 
      if (incomingByte == -1) continue;
      integerValue *= 10;
      integerValue = ((incomingByte - 48) + integerValue);
      integerMil = (integerValue +35);
    }
    Serial.println(integerMil);
   }
lcd_1.setCursor (0,0);
lcd_1.print(" CASES COMPLETE ");
lcd_1.setCursor(6,1);
lcd_1.print(d4);
lcd_1.print(d3);
lcd_1.print(d2);
lcd_1.print(d1);
  
}
void displayCountEntryScreen()
{
  clearScreen();
  lcd_1.setCursor(0,0);
  lcd_1.print(" CASES COMPLETE ");
  lcd_1.setCursor(0,1);
  lcd_1.print("      0000      ");
}
void clearScreen()
{
  lcd_1.setCursor(0,0);
  lcd_1.print("                  ");
  lcd_1.setCursor(0,1);
  lcd_1.print("                  ");
}
Arduino B Code;
#include <Adafruit_LiquidCrystal.h>
#include <Keypad.h>
char currentTimeValue[3];
int currentState = 1;
int timerSeconds = 0;
int lpcnt = 0;
const byte rows = 4;
const byte cols = 3;
char keys[rows][cols] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[rows] = {11,10,9,8};
byte colPins[cols] = {7,6,5};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
Adafruit_LiquidCrystal lcd_1(0);
void setup()
{
  Serial.begin(9600);
  lcd_1.begin(16, 2);
  
  displayTimeEntryScreen();
  
  currentTimeValue[0]='0';
  currentTimeValue[1]='0';
  currentTimeValue[2]='0';
  showEnteredTime();
}
void loop()
{
 
  int l;
  char tempVal[3];
  
  char key = keypad.getKey();
  
  if (int(key) != 0 and currentState == 1) {
    
    switch (key) {
      case '*':
      	currentTimeValue[0]='0';
     	currentTimeValue[1]='0';
      	currentTimeValue[2]='0';
      	showEnteredTime();
      	currentState = 1;
      	lpcnt = 0;
      	timerSeconds = 0;
      	break;
      
      case '#':
      	Serial.println(currentTimeValue);
      	break;
      
     
      default:
      	currentTimeValue[0] = currentTimeValue[1];
      	currentTimeValue[1] = currentTimeValue[2];
      	currentTimeValue[2] = key;
      	showEnteredTime();
      	break;
    }
  }
}
void showEnteredTime()
{
  lcd_1.setCursor(6,1);
  lcd_1.print(currentTimeValue[0]);
  lcd_1.print(".");
  lcd_1.print(currentTimeValue[1]);
  lcd_1.print(currentTimeValue[2]);
}
void displayTimeEntryScreen()
{
  clearScreen();
  lcd_1.setCursor(0,0);
  lcd_1.print(" ANNEALING TIME ");
  lcd_1.setCursor(0,1);
  lcd_1.print("      0.00      ");
}
void clearScreen()
{
  lcd_1.setCursor(0,0);
  lcd_1.print("                  ");
  lcd_1.setCursor(0,1);
  lcd_1.print("                  ");
}
 
  
  
 
