Wednesday, 23 October 2019

Exp_Code_03

모터의 속도를 숨으로 조절하기 위한 코드를 작성하였고 이는 가변저항을 활용한 코드와 숨 코드 두개를 합쳐 만들었다.

I wrote code to control the speed of the motor by breath, which was made by combining the code with variable resistor and the breath code.

Control the speed of the motor by breath (숨으로 속도조절을 위한 코드)

const int dirPin = 4;
const int stepPin = 5;
const int enablePin = 6;
const int MQ135 = A0;
int SensorVal = 0;
int customDelay, customDelayMapped;
void setup()
{
  Serial.begin(9600);
  pinMode(enablePin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  digitalWrite(enablePin, LOW);
  digitalWrite(dirPin, HIGH);
}
void loop() {
  customDelayMapped = speedUP();
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
}
int speedUP() {
  int customDelay = analogRead(A0);
  int newCustom = map(customDelay, 30, 400, 90, 1200);
  return newCustom;
}

No comments:

Post a Comment