Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // config pin
- const int motor_1_pin = 1;
- const int motor_2_pin = 2;
- const int switch_1_pin = 3;
- const int switch_2_pin = 4;
- const int led_1_pin = 5;
- const int led_2_pin = 6;
- const int led_3_pin = 7;
- const int delayToStop = 1000;
- void setup(){
- Serial.begin(115200);
- pinMode(motor_1_pin, OUTPUT);
- pinMode(motor_2_pin, OUTPUT);
- pinMode(switch_1_pin, OUTPUT);
- pinMode(switch_2_pin, OUTPUT);
- pinMode(led_1_pin, OUTPUT);
- pinMode(led_2_pin, OUTPUT);
- pinMode(led_3_pin, OUTPUT);
- }
- void loop(){
- int readSwitch1 = digitalRead(switch_1_pin);
- int readSwitch2 = digitalRead(switch_2_pin);
- if(readSwitch1 == 0){ // if 0 that mean pushing the switch
- motor1();
- }
- if(readSwitch2 == 0){
- motor2();
- }
- delay(100);
- }
- void turnLedOn(){
- digitalWrite(led_1_pin, HIGH);
- digitalWrite(led_2_pin, HIGH);
- digitalWrite(led_3_pin, HIGH);
- }
- void motor1(){
- digitalWrite(motor_1_pin, HIGH);
- delay(delayToStop);
- digitalWrite(motor_1_pin, LOW);
- }
- void motor2(){
- digitalWrite(motor_2_pin, HIGH);
- delay(delayToStop);
- digitalWrite(motor_2_pin, LOW);
- }
Add Comment
Please, Sign In to add comment