Week 33. April 22.26 2019 - michelle-qin/Portfolio GitHub Wiki

I’ve been continuing to work on the outline of the Ball Gate code for the Ball Wall project. I spoke with mentors and teachers to get more information and advice on how to map out the code. See below for the current working draft.

**Description** Ball Gate: 3 sensors for ball/rotation of gate 4 for Button RGB/open/close 1 for pot. (Analog) Potentiometer: min - TBD max - TBD calibration (?) current idea: When turn on, read current position & set that to 0 Horizontal Feeder: 3 sensors control GPIO Vertical Feeder: top/bottom sensors control GPIO

Potential issues: Jam detection (vertical feeder) vertical motor running but no balls detected going by. How to get out or indicate to user it is jammed? Full State (horizontal feeder) 3 sensors - when all 3 are high, we are Full - stop Horizontal

**Code below is for 1 Ball Gate. Final project will have 4 Ball Gates.** 3 modes/states: Initial, Active Button, Intermittent (inactive button) Variables: sensor1, sensor2, sensor3, 10s_timer, 15s_timer, Intermittent_timer

**Initial** ENTRY: power on • Set 10s_timer, 15s_timer • If sensor3 does NOT detect metal - rotate Ball Gate until sensor3 detects metal

• If potentiometer is turned to 0 - move to Active Button state • else - move to Intermittent state

**Active Button** - throughout this state, check that potentiometer is turned to 0. If potentiometer is turned elsewhere, change to Initial state(may be able to skip?) (where it will be redirected to Intermittent State). ENTRY: potentiometer is turned to 0 • If sensor1 detects metal - turn LED green - if button is pushed - start 10s_timer - turn LED red & make button inactive - rotate Ball Gate until sensor3 detects metal (180 deg - ball will release to other side) - if sensor2 detects metal - cycle complete - reset 10s_timer • Else - turn LED red & make button inactive

EXIT: - if potentiometer != 0 - reset 10s_timer - MOVE TO INITIAL STATE.

**Intermittent** - throughout this state, check that potentiometer is NOT turned to 0. If potentiometer is turned to 0, change to Initial state (where it will be redirected to Active State). ENTRY: potentiometer is NOT turned to 0 • Turn LED purple • Loop: Read potentiometer value - wait 15(Maybe 2?) seconds after potentiometer value stops changing - start 15s_timer - if potentiometer value doesn’t change - reset 15s_timer - else - check potentiometer value again - set Intermittent_timer to potentiometer value - release ball - start Intermittent_timer for interrupt -check potentiometer value again (only do this once inside loop — go back to top of Loop)

EXIT: - if potentiometer = 0 - turn off timer - MOVE TO INITIAL STATE.

TBD: -manage 4 Ball Gates -PWM for motors?? How do they work (timers?) -Master-Slave

I had a discussion with my teachers today and received even more information for the project. One of the main things we talked about was the potentiometer knob and calibration. In the chance that the potentiometers are NOT turned to 0 and the machine is turned ON, the machine won't know where the 0 value for the potentiometer is. Currently, we settled on an idea of creating a calibration mode/state specifically for turning the potentiometer knob to 0, but this may be implemented later on in the project. I am in the pseudo code phase right now.

Another thing that I need to be aware of: there are 2 main states controlling the Ball Gate (Active Button and Intermittent). What determines which state the machine will be in is the potentiometer value - if the potentiometer is turned to 0 it will be in active button state, otherwise it will be in intermittent state. When writing the code, the machine needs to continuously check the potentiometer value even if it's in the middle of another state (because if the potentiometer turns to 0 or away from 0, the state needs to immediately change). This is something that I am working into my code currently - possibly via an interrupt service routine that fires a signal when the potentiometer is moved to/away from 0.

My goal for next week is to have a pretty solid peudocode written and get that approved by my teachers.