<file_sep>#include <Servo.h>

#include <Ultrasonic.h>

int sensor;
int angle;
Ultrasonic ultrasonic(9, 10);
Servo myservo;

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
  myservo.attach(8);
}

void loop() {
  sensor = ultrasonic.distanceRead();
  if (sensor<100){
    //Serial.println(sensor);

   Serial.write(sensor);
    }
//   angle = Serial.read();
//   Serial.println(angle, DEC);
//   myservo.write(angle);
  delay(300);
}
<file_sep>/*
   This sketch was modified by the second easing code example
   created by <NAME>
   for Phsical Computing Week 5 class.
   https://github.com/phillipdavidstearns/PGTE_5585_F2019/blob/master/notes/week5/arduino/easing/easing.ino
*/

#define LED_PIN 5
#define SENSOR_PIN A0

float progress;
int value;

void setup() {
  Serial.begin(9600);

  progress = 0.0;
  value = 0;
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  int sensor = analogRead(SENSOR_PIN);

//  int current_time = millis();

  if (sensor > 500) {
    value = int(255 * (0.5 * sin(progress) + 0.5));
    progress+=0.2;
  }
  analogWrite(LED_PIN, value);

  Serial.println(progress);
  Serial.println(value);

  delay(100);

}
<file_sep>/*
   This sketch was modified by the first and the second easing code examples
   created by <NAME>
   for Phsical Computing Week 5 class.
   https://github.com/phillipdavidstearns/PGTE_5585_F2019/blob/master/notes/week5/arduino/easing/easing.ino
*/
#define LED_PIN 5
#define BUTTON_PIN 4

unsigned int trigger_time;
float progress, ease_time;
int value1, value2;
int value;

void setup() {
  Serial.begin(9600);

  trigger_time = 0;
  ease_time = 2500.0;
  progress = 0.0;
  value = 0;
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  int current_time = millis();

  if (buttonIsPressed() || progress > (PI * 3 / 2)) {
    trigger_time = current_time;
    progress = 0;
  }

  progress = (current_time - trigger_time) / ease_time;

  value1 = int(255 * (pow(progress, 2)));
  value2 = int(255 * (0.5 * sin(progress) + 0.5));

  //  Serial.println(value1);
  //  Serial.println(value2);

  if (progress <= 0.96) {
    value = value1;
  }

  if (progress > 0.96) {
    value = value2;
  }

  analogWrite(LED_PIN, value);

  Serial.println(progress);
  Serial.println(value);


}

bool buttonIsPressed() {
  boolean button_state = digitalRead(BUTTON_PIN);
  boolean button;

  if (button_state == LOW) {
    button = true;
  }
  if (button == HIGH) {
    button = false;
  }

  return button;

}
<file_sep>#define PIN_TRIG 12
#define PIN_ECHO 11
  
float cm;
float temp;
  
void setup() {  
  Serial.begin(9600);  
  pinMode(PIN_TRIG, OUTPUT);  
  pinMode(PIN_ECHO, INPUT);  
}  
  
void loop() {
  digitalWrite(PIN_TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(PIN_TRIG, LOW);
    
  temp = float(pulseIn(PIN_ECHO, HIGH));
  cm = (temp * 17 )/1000;

  
  
  Serial.print("Echo = ");  
  Serial.print(temp);
  Serial.print(",  Distance = ");  
  Serial.print(cm);
  Serial.println("cm");  
  delay(300);

  Serial.println(cm);  
  delay(100); 
}
<file_sep>#define PIN_TRIG 12
#define PIN_ECHO 11

#define LED_PIN 7
  
float cm;
float temp;

char LEDstate;
  
void setup() {  
  Serial.begin(9600);  
  pinMode(PIN_TRIG, OUTPUT);  
  pinMode(PIN_ECHO, INPUT);  
  pinMode(LED_PIN, OUTPUT);
}  
  
void loop() {
  digitalWrite(PIN_TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(PIN_TRIG, LOW);
    
  temp = float(pulseIn(PIN_ECHO, HIGH));
  cm = (temp * 17 )/1000;

//  Serial.print("Echo = ");  
//  Serial.print(temp);
//  Serial.print(",  Distance = ");  
//  Serial.print(cm);
//  Serial.println("cm");  
//  delay(300);

  Serial.println(cm);  
  delay(100); 

  checkUART();
}

void checkUART(){
  while(Serial.available()>0){

    LEDstate = Serial.read();
    if(LEDstate == 'H'){
      digitalWrite(LED_PIN, HIGH);
    }
    if(LEDstate == 'L'){
      digitalWrite(LED_PIN,LOW);
    }
    delay(50);
  }
}
<file_sep>#define P1A 3
#define P2A 7
#define EN12 8
#define KnobPin 4

boolean ButtonState;
float Speed;

void setup() {
  Serial.begin(9600);
  pinMode(P1A, OUTPUT);
  pinMode(P2A, OUTPUT);
  pinMode(EN12, OUTPUT);
  pinMode(KnobPin, INPUT);
}

void loop() {
  float Speed = analogRead(KnobPin);
  Speed = map(Speed, 0, 1024, 0, 255);

  Serial.println("CW");
  digitalWrite(EN12, HIGH);
  analogWrite(P1A , Speed);
  digitalWrite(P2A, LOW);

  Serial.println(Speed);
  delay(1000);
}
<file_sep>#define relayPin 7
#define trigPin 9
#define echoPin 10
#define buttonPin 4

long duration;
int distance;

boolean flag = false;

int flag1 = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(relayPin, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(buttonPin) == LOW) {
    if (flag == false) {
      flag = true;
    }
  }

  if (flag == true) {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);

    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    duration = pulseIn(echoPin, HIGH);
    distance = duration * 0.034 / 2;

    //  Serial.print("Distance: ");
    //  Serial.println(distance);

    if (distance < 100 && flag1 == 0) {

      flag1 = 1;
      Serial.println(flag1);
      //     delay(800);
      digitalWrite(7, HIGH);
      delay(1000);
      digitalWrite(7, LOW);
      flag1 = 2;

    }

    if (distance > 150 && distance < 400) {
      digitalWrite(7, LOW);
      flag1 = 0;
      Serial.println(flag1);
    }
  }
}
<file_sep>#define P1A 2 
#define P2A 7 
#define EN12 8 
#define ButtonPin 4

boolean ButtonState;

void setup() {
  Serial.begin(9600);
  pinMode(P1A, OUTPUT);
  pinMode(P2A, OUTPUT);
  pinMode(EN12, OUTPUT);
  pinMode(ButtonPin, INPUT_PULLUP); 
}

void loop() {
    ButtonState = digitalRead(ButtonPin);
    if(ButtonState == HIGH){
    Serial.println("CW");
    digitalWrite(EN12 ,HIGH);
    digitalWrite(P1A,HIGH);
    digitalWrite(P2A,LOW);   
    }else{
    Serial.println("CCW");  
    digitalWrite(EN12 ,HIGH);     
    digitalWrite(P1A,LOW);
    digitalWrite(P2A,HIGH);
    }
  delay(100);
}
<file_sep>#define P1A 3
#define P2A 7
#define EN12 8
#define KnobPin 4

#define switch1Pin 12
#define switch2Pin 13

#define LEDPin 2

float knobValue;

int counter;

unsigned long delay_time = 50;
unsigned long last_time = 0;
boolean led_state = false;

unsigned long start_time = 0;
unsigned long duration = 5000;
boolean flag = false;

void setup() {
  Serial.begin(9600);
  pinMode(P1A, OUTPUT);
  pinMode(P2A, OUTPUT);
  pinMode(EN12, OUTPUT);
  pinMode(KnobPin, INPUT);
  pinMode(switch1Pin, INPUT_PULLUP);
  pinMode(switch2Pin, INPUT_PULLUP);

  counter = 0;

  pinMode(LEDPin, OUTPUT);

}

void loop() {
  float knobValue = analogRead(KnobPin);

  if (knobValue < 500) {
    digitalWrite(EN12, HIGH);
    digitalWrite(P1A , HIGH);
    digitalWrite(P2A, LOW);
  }
  if (knobValue >= 500 && knobValue <= 550) {
    digitalWrite(EN12 , LOW);
    Serial.println(" Motor Stopped");
  }
  if (knobValue > 550) {
    digitalWrite(EN12 , HIGH);
    digitalWrite(P1A, LOW);
    digitalWrite(P2A, HIGH);
  }

  boolean switch1State = digitalRead(switch1Pin);
  boolean switch2State = digitalRead(switch2Pin);

  if (switch1State == LOW && switch2State == HIGH) {
    counter--;
  }

  if (switch1State == HIGH && switch2State == LOW) {
    counter++;
  }
  
  long current_time = millis();
  
  if (counter >= 5) {
    if(flag == false){
    start_time = current_time;
    flag = true;
    }
    if (current_time - last_time > delay_time) {
      digitalWrite(LEDPin, !led_state);
      led_state = !led_state;
      last_time = current_time;
    }
    if(current_time - start_time > duration){
      counter = 0;
      flag = false;
    }
  }else if(counter<5){
    digitalWrite(LEDPin, LOW);
  }

  Serial.println(knobValue);
  Serial.println(counter);

  delay(1000);
}
<file_sep>#define knob 0

int knobValue;

void setup() {
  // Begin the Serial at 9600 Baud
  Serial.begin(9600);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
}

void loop() {
  knobValue = analogRead(knob);
  int value = map(knobValue,0,1023,0,180);
  Serial.write(value);
  delay(300);

  if(Serial.available()){
    int receive = Serial.read();
    Serial.println(receive,DEC);

    if(receive>0&&receive<10){
      digitalWrite(7,HIGH);
      digitalWrite(8,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(10,HIGH);
    }else if(receive>=10&&receive<20){
      digitalWrite(7,HIGH);
      digitalWrite(8,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(10,LOW);
    } else if(receive>=20&&receive<30){
      digitalWrite(7,HIGH);
      digitalWrite(8,HIGH);
      digitalWrite(9,LOW);
      digitalWrite(10,LOW);
    } else if(receive>=30&&receive<40){
      digitalWrite(7,HIGH);
      digitalWrite(8,LOW);
      digitalWrite(9,LOW);
      digitalWrite(10,LOW);
    }
  }
}
<file_sep>/*
   This sketch was modified by the fisrt easing code example
   created by <NAME>
   for Phsical Computing Week 5 class.
   https://github.com/phillipdavidstearns/PGTE_5585_F2019/blob/master/notes/week5/arduino/easing/easing.ino
*/

#define LED_PIN 3
#define PIN_TRIG 12
#define PIN_ECHO 11

float cm;
float temp;

float currentValue;
float targetValue;
float easingAmount;

void setup() {
  currentValue = 0;
  easingAmount = .225;

  Serial.begin(9600);

  pinMode(PIN_TRIG, OUTPUT);
  pinMode(PIN_ECHO, INPUT);
}

void loop() {
  digitalWrite(PIN_TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(PIN_TRIG, LOW);

  temp = float(pulseIn(PIN_ECHO, HIGH));
  cm = (temp * 17 ) / 1000;

  Serial.println(cm);

  if (cm > 30) {
    easingOff();
  } else {
    easingOn();
  }

  delay(300);
}

void easingOn() {
  targetValue = 255;
  currentValue += easingAmount * ( targetValue - currentValue );
  analogWrite(LED_PIN, (int) currentValue);
  delay(250);
}

void easingOff() {
  targetValue = 0;
  currentValue -= easingAmount * ( currentValue - targetValue );
  analogWrite(LED_PIN, (int) currentValue);
  delay(250);
}
