Categories
PhysicalComputing

final project – surprise surprise surprise

what is up. charley and i broke through tonight. phwew!


light flight from ben yee on Vimeo.


light flight from ben yee on Vimeo.


light flight guts from ben yee on Vimeo.

and here’s the working code we implemented

/* code modified by Ben and Charley
from James and Christian’s Balloon Tree
*/

int photoSwitch = 2;
int motorPin0 = 3; // pin in hbridge to arduino for motor
int motorPin1 = 4; // pin in hbridge to arduino for motor

int switchPin1 = 7; // pin for switch 1 to arduino
int switchPin2 = 8; // pin for switch 2 to arduino

int state1 = 0; // initial state of switch 1 is open
int state2 = 0; // initial state of switch 2 is open
int motorPinSwap = 0; //variable used to switch direction of motor
int motorPin0value = HIGH; // variable for motor direction
int motorPin1value = LOW; // variable for motor direction

boolean previouslyPressed1 = false; //BOOLEAN STATEMENT USED TO UNDERSTAND THE PREVIOUS STATE OF SWITCH1
boolean previouslyPressed2 = false; //BOOLEAN STATEMENT USED TO UNDERSTAND THE PREVIOUS STATE OF SWITCH2

void setup() {
Serial.begin(9600);
pinMode(motorPin0, OUTPUT);
pinMode(motorPin1, OUTPUT);
//the switch is an input
pinMode(photoSwitch, INPUT);
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
}

void loop() {

if (digitalRead(photoSwitch) == HIGH) {
digitalWrite(motorPin0,motorPin0value); //starts motor in one direction using variable motorPin0value
digitalWrite(motorPin1,motorPin1value); //starts motor in one direction using variable motorPin1value

//
state1 = digitalRead(switchPin1); //READING THE STATE SWITCH1
Serial.print(motorPin0value,DEC); //PRINT LINE
Serial.println(motorPin1value,DEC); //PRINT LINE
//********************************* IF STATEMENT FOR SWITCH1 ******************************
if(state1 == 1 && previouslyPressed1 == false) //IF STATEMENT IN ORDER TO CHANGE THE MOTORS DIRECTION
{ //IF SWITCH1 IS TURNED ON, AND IT WAS NOT PREVIOUSLY PRESSED
motorPinSwap = motorPin0value; //THEN SWITCH THE PIN AND REVERSE THE DIRECTION OF THE MOTOR
motorPin0value = motorPin1value; //WHICH IN RETURN MEANS THE SWITCH AS BEEN PREVIOUSLY PRESSED
motorPin1value = motorPinSwap; //WHICH IS WHY IT IS NOW “TRUE”

previouslyPressed1 = true;
}
else if(state1 == 0) //ELSE IF THE SWITCH IS NOT TURNED ON THAN IT HAS ALSO NOT
previouslyPressed1 = false; //BEEN PREVIOUSLY PRESSED

//
state2 = digitalRead(switchPin2); //READING A SECOND STATE USING SWITCH2
Serial.print(motorPin0value,DEC);
Serial.println (motorPin1value,DEC);
//******************************************* IF STATEMENT FOR SWITCH2 **************************************
if(state2 == 1 && previouslyPressed2 == false) //IF STATEMENT IN ORDER TO CHANGE THE MOTORS DIRECTION
{
motorPinSwap = motorPin0value;
motorPin0value = motorPin1value;
motorPin1value = motorPinSwap;

previouslyPressed2 = true;
}
else if(state2 == 0)
previouslyPressed2 = false;

}
else {
digitalWrite(motorPin0, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motorPin1, HIGH); // set leg 2 of the H-bridge
}

}

Leave a Reply

Your email address will not be published. Required fields are marked *