Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define bot1 10
- #define bot2 11
- #define bot3 12
- #define led1 5
- #define led2 6
- #define led3 7
- #define led4 8
- int motor;
- //--------------------------------------
- void setup() {
- pinMode (bot1, INPUT_PULLUP);
- pinMode (bot2, INPUT_PULLUP);
- pinMode (bot3, INPUT_PULLUP);
- pinMode (led1, OUTPUT);
- pinMode (led2, OUTPUT);
- pinMode (led3, OUTPUT);
- pinMode (led4, OUTPUT);
- digitalWrite (led1, 0);
- digitalWrite (led2, 0);
- digitalWrite (led3, 0);
- digitalWrite (led4, 0);
- Serial.begin (9600);
- motor = 1;
- }
- //-------------------------------------
- void loop()
- {
- if (motor == 1)
- {
- while(digitalRead (bot1)==LOW)
- {
- delay(10);
- GiraWise();
- }
- }
- if (motor == 1)
- {
- while(digitalRead (bot2)==LOW)
- {
- delay(10);
- GiraCounterWise();
- }
- }
- while(digitalRead (bot3)==LOW)
- {
- delay(10);
- Stop();
- }
- Serial.println(motor);
- }
- //-------------------------------------
- void GiraWise()
- {
- digitalWrite (led1, 1);
- digitalWrite (led2, 1);
- digitalWrite (led3, 0);
- digitalWrite (led4, 0);
- motor = 0;
- }
- //-------------------------------------
- void GiraCounterWise()
- {
- digitalWrite (led1, 0);
- digitalWrite (led2, 0);
- digitalWrite (led3, 1);
- digitalWrite (led4, 1);
- motor = 0;
- }
- //-------------------------------------
- void Stop()
- {
- digitalWrite (led1, 0);
- digitalWrite (led2, 0);
- digitalWrite (led3, 0);
- digitalWrite (led4, 0);
- motor = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement