NoNnYhA55

Untitled

Feb 26th, 2024
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.11 KB | Source Code | 0 0
  1. // config pin
  2. const int motor_1_pin = 1;
  3. const int motor_2_pin = 2;
  4.  
  5. const int switch_1_pin = 3;
  6. const int switch_2_pin = 4;
  7.  
  8. const int led_1_pin = 5;
  9. const int led_2_pin = 6;
  10. const int led_3_pin = 7;
  11.  
  12. const int delayToStop = 1000;
  13.  
  14. void setup(){
  15.   Serial.begin(115200);
  16.   pinMode(motor_1_pin, OUTPUT);
  17.   pinMode(motor_2_pin, OUTPUT);
  18.   pinMode(switch_1_pin, OUTPUT);
  19.   pinMode(switch_2_pin, OUTPUT);
  20.   pinMode(led_1_pin, OUTPUT);
  21.   pinMode(led_2_pin, OUTPUT);
  22.   pinMode(led_3_pin, OUTPUT);
  23.  
  24.  
  25. }
  26.  
  27. void loop(){
  28.   int readSwitch1 = digitalRead(switch_1_pin);
  29.   int readSwitch2 = digitalRead(switch_2_pin);
  30.  
  31.   if(readSwitch1 == 0){ // if 0 that mean pushing the switch
  32.     motor1();
  33.   }
  34.   if(readSwitch2 == 0){
  35.     motor2();
  36.   }
  37.   delay(100);
  38. }
  39.  
  40.  
  41. void turnLedOn(){
  42.   digitalWrite(led_1_pin, HIGH);
  43.   digitalWrite(led_2_pin, HIGH);
  44.   digitalWrite(led_3_pin, HIGH);
  45. }
  46. void motor1(){
  47.   digitalWrite(motor_1_pin, HIGH);
  48.   delay(delayToStop);
  49.   digitalWrite(motor_1_pin, LOW);
  50. }
  51. void motor2(){
  52.   digitalWrite(motor_2_pin, HIGH);
  53.   delay(delayToStop);
  54.   digitalWrite(motor_2_pin, LOW);
  55. }
Add Comment
Please, Sign In to add comment