I wrote code to control the speed of the motor by breath, which was made by combining the code with
Control the speed of the motor by breath (숨으로 속도조절을 위한 코드)
const intdirPin = 4;const intstepPin = 5;const intenablePin = 6;const int MQ135 = A0;int SensorVal = 0;
intcustomDelay ,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 );
}
intspeedUP ( ) {
intcustomDelay =analogRead ( A0);
intnewCustom = map( customDelay , 30, 400, 90, 1200);
return newCustom;
}
No comments:
Post a Comment