Week 6: Tip the Can Week 2

4th of March 2020

This week is second of the Tip the Can challenge. This week is for anyone who didn’t get an opportunity to tip the can in week 1.

We once again tried to change our code and chassis to resolve the problem of what happened in week 1 but once again, none of that worked. By the end of the challenge, we decided to shift our attention to prepping our robot for the Robosumo tournament for next week.

Final circuit diagram by Nathan

Code for Tip the Can Challenge week 2

int trigPin = 9; //Defining trigpin
int echoPin = 10; //Defining echopin
long duration, cm, inches;

void setup()
{
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT); //triggerpin on rangefinder as an output
 pinMode(echoPin, INPUT); //Echopin on rangefinder as an input
 pinMode(3, OUTPUT); //motors
 pinMode(4, OUTPUT); //motors
 pinMode(6, OUTPUT); //motors
 pinMode(7, OUTPUT); //motors
 pinMode(5, INPUT); //Switch input
}

void loop()
{
long duration, distance; //defining variables
//pulse from HC-SR04
digitalWrite(trigPin, LOW); //Calibrate Trigpin
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); //send out signal from trigpin
delayMicroseconds(10);
duration = pulseIn(echoPin, HIGH); //Recieve signal in echopin
distance = duration*0.034/2; //defines distance to object in cm
Serial.print(distance);
Serial.println("cm");
//check echo pulse
if (distance <60 ) //If the distance is less than 60cm
{

 digitalWrite (4,LOW); //move towards object
 digitalWrite (3,HIGH);
 digitalWrite (7,HIGH);
 digitalWrite (6,LOW);

}
else {
digitalWrite (4,LOW); //rotate until distance is less than 60cm
digitalWrite (3,LOW);
digitalWrite (6,LOW );
digitalWrite (7,LOW);
}
int x; //defining x
x = digitalRead(5); //read input
Serial.print("The Switch is now:");
Serial.println(x);
//If switch is pressed
if (x == 1){


 digitalWrite (3,HIGH); //reverse for 5 seconds
 digitalWrite (4,LOW);
 digitalWrite (6,HIGH);
 digitalWrite (7,LOW);
delay(5000);

 digitalWrite (3,LOW); //stop for 10 seconds
 digitalWrite (4,LOW);
 digitalWrite (6,LOW);
 digitalWrite (7,LOW);
delay(10000);
}
}
Naders design

Leave a comment

Design a site like this with WordPress.com
Get started