Assignment #3 – Garbage Trash Cans

Problem: At the Chick-fil-a near Waterfront, they have some trash cans.  They’re bad, they’re garbage, and they’re intended to stop users from putting in new trash while they compress down the previous user’s inputted garbage.  While this is a good idea in saving space, it’s annoying to wait for the trash can to finish compressing, and the only feedback is the audio of the trash can compressing.  There is no warning for “you cannot put trash in right now.”  There is, I think, a place for it on the top of the trash can, but its either always burnt out or never working, so here is my solution instead.

Solution: An interruptable trash can state machine that effectively warns patient users when it is busy and allows impatient users to dump their trash in and move on.

Proof of Concept: The trash can will have three added lights, one for “trash allowed” and two for “compressing, please wait.”  Additionally, users will be able to interrupt the compressing state to dump their trash in anyway, which may then lengthen the next compressing state.  This is intended to allow it to compress primarily when people are not using it.  For simplicity, the putting trash in the trash door is represented by a momentary switch.

Video: Chance Assignment #3

Fritzing Sketch:

Chance Assignment #3

Still shaking off the rust of my circuitry skills, but after this I’m pretty comfortable.

Arduino Sketch:

Assignment3_Chance files

Basic psuedo-state machine.  The RED state defaults back to the GREEN state after X amount of time, user definable.  I hope to write proper states and transitions moving forward, something I know but just didn’t have time for this assignment.

// Chance, Assignment 3.  Honestly just glad I got something working well.

#define Serial SerialUSB

const int buttonPin = 2;     // momentary button
const int greenLED =  13;    // green LED
const int redLED = 11;      // red LED
const int red2LED = 9;      // second red LED


void setup() {
  // initialize the LED pins as an outputs:
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  pinMode(red2LED, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

// state vars
int reading, previous = LOW;
int state = LOW;

// timer stuff
long time = 0;
long debounce = 200;

void loop() {
   reading = digitalRead(buttonPin);

  // check for state toggle and account for input delay
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();
  }

  manageState();

  previous = reading;
}

// quick and easy psuedo timer thats badly CPU bound
int counter = 0;

// i didnt write a ""good"" state machine with transitionsn yet, short on time
void manageState() {
  bool tempState = sin(0.025 * millis()) > 0.0; // sloppy timer solution
  Serial.println(counter);
  switch(state) {
    case HIGH:
      counter = 0;
      digitalWrite(greenLED, HIGH);
      digitalWrite(redLED, LOW);
      digitalWrite(red2LED, LOW);
    break;
    case LOW:
      counter++;
      if(counter++ > 1000 * 20) {
        state = HIGH;
        previous = HIGH;
      }
      digitalWrite(greenLED, LOW);
      digitalWrite(redLED, tempState ? HIGH : LOW);
      digitalWrite(red2LED, tempState ? LOW : HIGH);
    break;
    default:
        digitalWrite(greenLED, LOW);
        digitalWrite(greenLED, LOW);
  }
}