safwan092

Untitled

Mar 24th, 2021
510
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define INA 9
  2. #define INB 8
  3. #define ldrPin A0
  4. #define ntcPin A1
  5.  
  6. int ldrStatus = 0;
  7. int ntcStatus = 0;
  8.  
  9.  
  10. void setup()
  11. {
  12.   Serial.begin(9600);
  13.   pinMode(ntcPin, INPUT);
  14.   pinMode(ldrPin, INPUT);
  15.   pinMode(INA,    OUTPUT);
  16.   pinMode(INB,    OUTPUT);
  17. }
  18.  
  19. void loop()
  20. {
  21.  
  22.   ldrStatus = analogRead(ldrPin);
  23.   ntcStatus = analogRead(ntcPin);
  24.   Serial.print(ldrStatus);
  25.   Serial.print("  ");
  26.   Serial.println(ntcStatus);
  27.  
  28.   if (ldrStatus > 800) {
  29.     if (ntcStatus > 500) {
  30.       BTH();//Back
  31.     }
  32.     else {
  33.       FTH();//Front
  34.     }
  35.   }
  36.   else {
  37.     stopM();//STOP
  38.   }
  39.   delay(100);
  40. }
  41.  
  42. void BTH() {
  43.   digitalWrite(INA, LOW);
  44.   digitalWrite(INB, HIGH);
  45.   delay(10);
  46. }
  47.  
  48. void FTH() {
  49.   digitalWrite(INA, HIGH);
  50.   digitalWrite(INB, LOW);
  51.   delay(10);
  52. }
  53.  
  54. void stopM() {
  55.   digitalWrite(INA, LOW);
  56.   digitalWrite(INB, LOW);
  57.   delay(10);
  58. }
RAW Paste Data