Friday, November 22, 2013

Project Update 22NOV2013

22NOV2013-

Team "ThinkStation" met in the computer lab to finalize design of the box, "finger", and discuss building a prototype over the weekend. Below is a picture of the finalized picture of the box along with cut outs for the LCD screen, LED, and switch. The code has also been updated to make it that the top line of the LCD will write “THE USELESS GAME” and on the bottom will write “Points =”. Then whenever the button is pressed the LED will go on until the finger pushes the switch back. For each time you press the button it will display the amount pressed after “points =”.
Once the prototype of the "useless machine" is built a video will be posted on here for your enjoyment!
Arduino Code-
//THE USELESS MACHINE
#include <Servo.h> //Including the servor library in the code
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int LED = 8;
// this constant won't change:
const int onoffswitch = 2; // the pin that the pushbutton is attached to
// Variables will change:
int switchCounter = 0; // counter for the number of button presses
int switchState = 0; // current state of the button
int lastSwitchState = 0; // previous state of the button
//Set servo as myservo
Servo myservo;
void setup () { //Starting off the code

// initialize the button pin as a input:
pinMode(onoffswitch, INPUT);

//myservo is set to pin 12
myservo.attach(12);

//and is placed at 180 degree
myservo.write(180);

// initialize serial communication:
Serial.begin(9600);

//Start LCD Scrren by clearing and writing "Points ="
lcd.begin(16, 2);
lcd.clear();
lcd.print("THE USELESS GAME");
lcd.setCursor(0,1);
lcd.print("Points =");
int switchCounter = 0;
}

void loop () //Start loop
{

// read the switch input pin:
switchState = digitalRead(onoffswitch);

// compare the switchState to its previous state
if (switchState != lastSwitchState)
{
switchCounter++;
// if the state has changed, increment the counter
digitalWrite(LED,HIGH);
delay(500);

if (switchState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
myservo.write (180); //so place servo at 180 degree so that
//the finger will push the switch back to off
switchCounter++;
lcd.setCursor(9,1);
lcd.print(switchCounter); //write out button presses
}
delay(100); //pause for 10th of a second
if ((switchCounter <= 5) && (switchCounter >= 8))
{
lcd.setCursor(11,1);
lcd.print(">:[");
} //close IF statement
if (switchCounter <= 9)
{
lcd.setCursor(9,1);
lcd.print("XO stop!");
}
else{
myservo.write (25); //move servo to position 25 degree
digitalWrite(LED,LOW);
delay (100); //then pause for 10th of a second
} //close ELSE statement


} //close IF statement
// save the current state as the last state,
//for next time through the loop
lastSwitchState = switchState;
} //close LOOP
The box-

No comments:

Post a Comment