Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- // Latest v1.7 as of 12.3.11pm
- LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); // LCD pin rs rw en d4 d5 d6 d7.
- int StartPin = 9; // switch input
- int motor1Pin = 7; // H-bridge leg 1 (pin 2, 1A)
- int motor2Pin = 6; // H-bridge leg 2 (pin 7, 2A)
- int enablePin = 8; // H-bridge enable pin
- int DirPin = 13; // Motor direction select
- int DirSwCounter = 0;
- int LastDirState = 0;
- bool Dir = true;
- byte runningCan = 0;
- int cansCrushed; // Initial number of cans crushed set to 0
- byte endStop = 0;
- void writeLCD(int cans) {
- if (cans == 0) {
- lcd.begin(16, 2);
- lcd.print("Adams CanCrshr1");
- delay(3000);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Crushed:");
- lcd.setCursor(10, 0);
- lcd.print((int) cansCrushed);
- lcd.setCursor(0, 1);
- lcd.print("Weight:");
- lcd.setCursor(9, 1);
- lcd.print((int) cansCrushed * .034375);
- } else {
- lcd.begin(16, 2);
- lcd.print("Adams CanCrshr1");
- delay(3000);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Crushed:");
- lcd.setCursor(10, 0);
- lcd.print((int) cans);
- lcd.setCursor(0, 1);
- lcd.print("Weight:");
- lcd.setCursor(9, 1);
- lcd.print((int) cans * .034375);
- }
- }
- void setup()
- {
- Serial.begin(9600);
- // INITIALIZE
- pinMode(StartPin, INPUT);
- pinMode(DirPin, INPUT);
- pinMode(motor1Pin, OUTPUT);
- pinMode(motor2Pin, OUTPUT);
- pinMode(enablePin, OUTPUT);
- digitalWrite(enablePin, LOW);
- lcd.begin(16, 2);
- //cansCrushed = 0;
- }
- /////////////This is where it is done at///////////////////////////
- byte canCycler() {
- // Start if statment.
- if (digitalRead(StartPin) == HIGH && runningCan == false) {
- // Check if crusher is ready for operation.
- if (digitalRead(DirPin) == HIGH) {
- digitalWrite(motor1Pin, HIGH);
- digitalWrite(motor2Pin, LOW); // forward motors.
- runningCan = 1; // Passes function to stage 2.
- Serial.println("Crushing started.");
- delay(500);
- }
- }
- //phase 2 return action called.
- if (digitalRead(endStop) == HIGH && runningCan == 1) {
- digitalWrite(motor1Pin, LOW);
- digitalWrite(motor2Pin, HIGH);
- Serial.println("StartPin Enabled and Dir True");
- delay(500);
- runningCan = 2; // Pass the function to stage 3.
- }
- if (DirPin == HIGH && runningCan == 2) {
- digitalWrite(motor1Pin, LOW);
- digitalWrite(motor2Pin, LOW);
- Serial.println("Motor stopped");
- }
- return cansCrushed++; // Add to the total amount of cans crushed.
- }
- void loop() {
- writeLCD(canCycler());
- // // READ PINS
- // int DirState = digitalRead(DirPin);
- // if (LastDirState == LOW && DirState == HIGH) {
- // DirSwCounter++;
- // Serial.println("dirPin triggered");
- // }
- // LastDirState = DirState; /// ?????
- // // PROCESS
- // if (DirSwCounter % 2 == 0) {
- // Dir = false;
- // cansCrushed++;
- // } else {
- // Dir = true;
- // }
- // if (digitalRead(StartPin) == HIGH && Dir == false) {
- // digitalWrite(motor1Pin, HIGH);
- // digitalWrite(motor2Pin, LOW);
- // Serial.println("Start Enabled and Dir False");
- // }
- // else if (digitalRead(StartPin) == HIGH && Dir == true)
- // {
- // digitalWrite(motor1Pin, LOW);
- // digitalWrite(motor2Pin, HIGH);
- // Serial.println("StartPin Enabled and Dir True");
- // } else {
- // //delay(10000);
- // digitalWrite(motor1Pin, LOW);
- // digitalWrite(motor2Pin, LOW);
- // Serial.println("Motor stopped");
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement