Day 17 Oct 24

For this homework we had to modify the seismic code to allow the user to enter the threshold value and print out the events detected

Here's a screenshot

For lab we had to control the motor using a joystick. Here's a link to the motor working.
Here's the code

// Arduino pin numbers
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output




const int Y_pin = 1; // analog pin connected to Y output
int M1_Left = 6; //Motor Input 1
int M1_Right = 5;
int M2_Left = 10;
int M2_Right = 9;
boolean inPin1 = LOW;
boolean inPin2 = HIGH;
boolean inPin5 = LOW;
boolean inPin6 = HIGH;
char data;

void setup() {
    pinMode(M1_Left, OUTPUT);
  pinMode(M1_Right , OUTPUT);
  pinMode(M2_Right, OUTPUT);
  pinMode(M2_Left, OUTPUT);
 pinMode(SW_pin, INPUT);
 digitalWrite(SW_pin, HIGH);
 Serial.begin(115200);
void forward();
void reverse();



}
void loop() {
// Serial.print("\n Switch: ");
// Serial.print(digitalRead(SW_pin));
// Serial.print("\n");
// Serial.print("X-axis: ");
// Serial.print(analogRead(X_pin));
// Serial.print("\n");
// Serial.print("Y-axis: ");
// Serial.println(analogRead(Y_pin));
// Serial.print("\n\n");
// delay(50);
int x,y;
x=analogRead(X_pin);
y=analogRead(Y_pin);
x=map(x, 0, 1023, -100, 100);
y=map(y, 0, 1023, -100, 100);
  if (y > 5)
  {
    speedup(100-y);
 
  }
  else if (y < -5)
  {
    speeddown(100+y);
 
  }
 else
 {
  stop();
  }
  //Serial.println(x);
  Serial.println(y);
}
void forward()
{
  digitalWrite(M1_Left, HIGH);
  digitalWrite(M1_Right, LOW);
  digitalWrite(M2_Left, HIGH);
  digitalWrite(M2_Right, LOW);

}
void reverse()
{
   digitalWrite(M1_Left,LOW);
  digitalWrite(M1_Right,HIGH);
   digitalWrite(M2_Left, LOW);
  digitalWrite(M2_Right, HIGH);

}

void speedup(int val)
{

    forward();
    delay(val); //1 sg
    stop();
   // delay(20);
}
void speeddown(int val)
{

    reverse();
    delay(val); //1 sg
    stop();
    //delay(20);
}
void stop()
{
  digitalWrite(M1_Left, LOW);
  digitalWrite(M1_Right , LOW);
  digitalWrite(M2_Left, LOW);
  digitalWrite(M2_Right, LOW);
}

Comments

Popular posts from this blog

Day 5

Day 22 Nov 14

Day 21 Nov 9