Advertisement
Maderdash

another draft

Dec 14th, 2021
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. // Latest v1.7 as of 12.3.11pm
  3. LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); // LCD pin rs rw en d4 d5 d6 d7.
  4. int StartPin                = 9;      // switch input
  5. int motor1Pin               = 7;      // H-bridge leg 1 (pin 2, 1A)
  6. int motor2Pin               = 6;      // H-bridge leg 2 (pin 7, 2A)
  7. int enablePin               = 8;      // H-bridge enable pin
  8. int DirPin                  = 13;     // Motor direction select
  9. int DirSwCounter            = 0;
  10. int LastDirState            = 0;
  11. bool Dir                    = true;
  12. byte runningCan             = 0;
  13. int cansCrushed;                       // Initial number of cans crushed set to 0
  14. void writeLCD(int cans) {
  15.   if (cans == 0) {
  16.     lcd.begin(16, 2);
  17.     lcd.print("Adams CanCrshr1");
  18.     delay(3000);
  19.     lcd.clear();
  20.     lcd.setCursor(0, 0);
  21.     lcd.print("Crushed:");
  22.     lcd.setCursor(10, 0);
  23.     lcd.print((int) cansCrushed);
  24.     lcd.setCursor(0, 1);
  25.     lcd.print("Weight:");
  26.     lcd.setCursor(9, 1);
  27.     lcd.print((int) cansCrushed * .034375);
  28.   } else {
  29.     lcd.begin(16, 2);
  30.     lcd.print("Adams CanCrshr1");
  31.     delay(3000);
  32.     lcd.clear();
  33.     lcd.setCursor(0, 0);
  34.     lcd.print("Crushed:");
  35.     lcd.setCursor(10, 0);
  36.     lcd.print((int) cans);
  37.     lcd.setCursor(0, 1);
  38.     lcd.print("Weight:");
  39.     lcd.setCursor(9, 1);
  40.     lcd.print((int) cans * .034375);
  41.   }
  42. }
  43.  
  44. void setup()
  45. {
  46.   Serial.begin(9600);
  47.   // INITIALIZE
  48.   pinMode(StartPin, INPUT);
  49.   pinMode(DirPin, INPUT);
  50.   pinMode(motor1Pin, OUTPUT);
  51.   pinMode(motor2Pin, OUTPUT);
  52.   pinMode(enablePin, OUTPUT);
  53.   digitalWrite(enablePin, LOW);
  54.   lcd.begin(16, 2);
  55.   //cansCrushed = 0;
  56. }
  57. /////////////This is where it is done at///////////////////////////
  58. byte canCycler() {
  59.   // Start if statment.
  60.   if (digitalRead(StartPin) == HIGH && runningCan == 0) {
  61.     // Check if crusher is ready for operation.
  62.     if (digitalRead(DirPin) == HIGH) {
  63.       digitalWrite(motor1Pin, HIGH);
  64.       digitalWrite(motor2Pin, LOW); // forward motors.
  65.       runningCan = 1; // Passes function to stage 2.
  66.       Serial.println("Crushing started.");
  67.       delay(500);
  68.     }
  69.   }
  70.   //phase 2 return action called.
  71.   if (digitalRead(DirPin) == HIGH && runningCan == 1) {
  72.     digitalWrite(motor1Pin, LOW);
  73.     digitalWrite(motor2Pin, HIGH);
  74.     Serial.println("StartPin Enabled and Dir True");
  75.     delay(500);
  76.     runningCan = 2; // Pass the function to stage 3.
  77.   }
  78.   if (digitalRead(DirPin) == HIGH && runningCan == 2) {
  79.     digitalWrite(motor1Pin, LOW);
  80.     digitalWrite(motor2Pin, LOW);
  81.     Serial.println("Motor stopped");
  82.   }
  83.   runningCan = 0;
  84.   return cansCrushed++; // Add to the total amount of cans crushed.
  85. }
  86.  
  87.  
  88.  
  89. void loop() {
  90.   writeLCD(canCycler());
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement