Sunday, December 1, 2013

Over break, more wiring and programming for our board was done.  The h-bridge is not yet connected and the motors are still at school so the testing for the motors couldn't be done unfortunately.  Since the video, more progress was made on the automatic-fire debounce program which will hopefully be completed soon.

This video shows what the board looks like so far.
This is the coding so for for both the servo and the motors.  It is still not fully tested and not completed so don't judge.
/*
PushOnce
realeases pingpong ball
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
const int buttonPin = 2; // the number of the pushbutton pin
const int servoPin = 9; // the number of the servo pin
int buttonState1 = 0; // variables for reading the pushbutton status
int buttonState2 = 0;
int buttonState = 0;
int buttonCount = 0; // variable to record number of times button has been pushed
boolean lastButton = HIGH; // Boolean variable to hold last state of button
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// initialize the servo pin as an output:
pinMode(servoPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
// Begin serial communication
Serial.begin(9600);
}
void loop(){
buttonState1 = digitalRead(buttonPin);
delay(50);
buttonState2 = digitalRead(buttonPin);
if (buttonState1 == buttonState2){ // if a valid button state is detected proceed...
buttonState = buttonState2;
// check if the pushbutton is pressed.
// if it is, the buttonState is LOW:
if (buttonState == HIGH) {
// turn servo stays at 20 degrees:
myservo.write(pos = 20); //pos doesnt matter, as long as the difference between initial and final is 70 degrees
}
else {
for(pos = 20; pos < 90; pos += 1) { // goes from 20 degrees to 90 degrees in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5); // waits 5ms for the servo to reach the position
}
if (buttonState2 != buttonState)
myservo.write(pos = 90)
if (buttonState1 = buttonState)
for(pos = 90; pos>=1; pos-=1) { // goes from 90 degrees to 20 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 1ms for the servo to reach the position to allow only 1 ball through
}
// check to see if button has changed state since last pass through loop
if (buttonState != lastButton) {
if (buttonState == LOW){ // if the state has changed and is now LOW
buttonCount++; // increment by 1
}
lastButton = buttonState; // update value of lastButton
}
}
}
// Arduino code for the H_BRIDGE MOTORS
// int switchPin = 7; // switch input
int motor11Pin = 12; // H-bridge leg 1
int motor12Pin = 11; // H-bridge leg 2
// int motor21Pin = 10; // H-bridge leg 3
// int motor22Pin = 8; // H-bridge leg 4
int speedPin = 13; // H-bridge enable pin
// int ledPin = 13; //LED
int potPin = 0;
int speed = 0;
void setup() {
// set the switch as an input:
Serial.begin (9600);
// pinMode(switchPin, INPUT);
// set all the other pins you're using as outputs:
pinMode(motor11Pin, OUTPUT);
pinMode(motor12Pin, OUTPUT);
// pinMode(motor21Pin, OUTPUT);
// pinMode(motor22Pin, OUTPUT);
pinMode(speedPin, OUTPUT);
// set speedPin high so that motor can turn on:
digitalWrite(speedPin, HIGH);
// blink the LED 3 times. This should happen only once.
// if you see the LED blink three times, it means that the module
// reset itself,. probably because the motor caused a bownout
// or a short.
}
void loop() {
digitalWrite(motor11Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor12Pin, HIGH); // set leg 2 of the H-bridge high
speed = analogRead(potPin);
speed = 793 + (speed/6);
analogWrite (speedPin, speed);
// digitalWrite(motor21Pin, HIGH); // set leg 1 of the H-bridge high
// digitalWrite(motor22Pin, LOW); // set leg 2 of the H-bridge low
}

No comments:

Post a Comment