종합설계2 9조 OSS 코드
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
1.0 KiB

  1. #include <Stepper.h>
  2. #define STEPS 4096 // 한바퀴를 이루는 스텝 갯수 입력
  3. Stepper stepper(STEPS, 4, 5, 6, 7); // 고정자 권선 순서 설정
  4. int dust_sensor = A0;
  5. float dust_value=0;
  6. float dustDensityug=0;
  7. int sensor_led =12;
  8. int sampling=280;
  9. int waiting =40;
  10. float stop_time=9680;
  11. void setup(){
  12. Serial.begin(9600);
  13. pinMode(sensor_led,OUTPUT);
  14. pinMode(4,OUTPUT);
  15. stepper.setSpeed(6); // 회전 속도 지정
  16. }
  17. void loop(){
  18. digitalWrite(sensor_led, LOW);
  19. delayMicroseconds(sampling);
  20. dust_value=analogRead(dust_sensor);
  21. delayMicroseconds(waiting);
  22. digitalWrite(sensor_led, HIGH);
  23. delayMicroseconds(stop_time);
  24. dustDensityug =(0.17*(dust_value*(5.0/1024))-0.1)*1000;
  25. Serial.print("Dust Density [ug/m3]: ");
  26. if(dustDensityug <=75.0){
  27. stepper.step(STEPS); // 정방향 회전
  28. delay(1000);
  29. }else if (80.0 < dustDensityug && dustDensityug <=150.0){
  30. stepper.step(-STEPS); // 역방향 회전
  31. delay(1000);
  32. }
  33. delay(2000);
  34. }