Tuesday, November 26, 2013

Week 4 Design Update

In order for our mechanism's gear to be fabricated, it needs to have a specific thickness of either 0.125" of 0.25". In SolidWorks the gear's thickness was adjusted from 0.5" to 0.25". To ensure that an appropriate amount of material was used, the gear, having a 4 inch diameter, was shelled to make the majority of the inside hollow. This gave the gear an appropriate volume of material, only 2.07 in.^3. Here is a picture of the final product, ready for fabrication.

Gear to be fabricated, with adjusted thickness and material volume.

The Arduino code was also updated so that the LCD screen displays "RELOAD" when the servo motor is in its initial position. In this position, rubber bands can be loaded onto the mechanism, so that they can be fired as the servo motor changes positions. The code was also adjusted so that after it is uploaded, the servo motor moves directly to its initial position. Here is the code:

/*
Arduino code - Code is used to:
* control servo motor with push button
* display LED at all times
* display LCD at servo's initial position
*/
// introduce servo motor and LCD
#include <Servo.h>
#include <LiquidCrystal.h>
Servo Servo1;
LiquidCrystal lcd(12,11,5,4,3,2);
// global variables
const int buttonPin = 8;
boolean currentState = LOW;
boolean lastState = LOW;
boolean stateChange = false;
int currentButton = 0;
int lastButton = 4;
int pos = 0;
int led = 13;
// setup button, sevo, LED, and LCD
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(9600);
Servo1.attach(9);
while (pos==lastButton);{
pinMode(led, OUTPUT);
lcd.begin(16, 2);
lcd.clear();
}
}
// main loop
// call functions and keep LED on at all times
void loop(){
currentState = debounceButton();
stateChange = checkForChange(currentState, lastState);
currentButton = getButtonNumber(lastButton, currentState, stateChange);
servoControl(currentButton);
lastState = currentState;
lastButton = currentButton;
digitalWrite(led, HIGH);
printfunction(currentButton);
}
// function debounceButton
boolean debounceButton()
{
boolean firstCheck = LOW;
boolean secondCheck = LOW;
boolean current = LOW;
firstCheck = digitalRead(buttonPin);
delay(50);
secondCheck = digitalRead(buttonPin);
if (firstCheck == secondCheck){
current = firstCheck;
}
return current;
}
// function checkForChange
boolean checkForChange(boolean current, boolean last)
{
boolean change;
if (current != last){
change = true;
}
else {
change = false;
}
return change;
}
// function getButtonNumber
int getButtonNumber(int button, boolean state, boolean change)
{
if (change == true && state == LOW){
button++;
if (button > 4){
button = 0;
}
Serial.println(button);
}
return button;
}
// function servoControl
// base servo position off of button state
// make sure that first position is intended initial position
void servoControl(int button)
{
if(button == 4) {Servo1.write(10);}
if(button == 0) {Servo1.write(30);}
if(button == 1) {Servo1.write(50);}
if(button == 2) {Servo1.write(70);}
if(button == 3) {Servo1.write(90);}
}
// function printfunction
// base LCD display off of button state
void printfunction (int button)
{
if(button == 4) {
lcd.setCursor(0,0);
lcd.print ("!!!! RELOAD !!!!!");
}
else{lcd.clear();
}
}
view raw gistfile1.txt hosted with ❤ by GitHub
And here is a video of the code in action:

No comments:

Post a Comment