Motor Drive Shield Board Module L293D for Arduino код из видео.
// код из видео https://www.youtube.com/watch?v=aLGFBG-VDdo #include <Shift595.h> // https://sites.google.com/site/shift595arduino/downloads #define M1A 2 #define M1B 3 #define M2A 1 #define M2B 4 #define M4A 0 #define M4B 6 #define M3A 5 #define M3B 7 #define PWM_M1 11 #define PWM_M2 3 #define PWM_M3 6 #define PWM_M4 5 #define SER1 10 #define SER2 9 #define PWRON 7 Shift595 Shifter(8, 12, 4, 1); void setup() { Serial.begin(9600); Shifter.clearRegisters(); pinMode(PWRON, OUTPUT); digitalWrite(PWRON, LOW); // включение 74HC595 pinMode(PWM_M1, OUTPUT); // включение L293D pinMode(PWM_M2, OUTPUT); pinMode(PWM_M3, OUTPUT); pinMode(PWM_M4, OUTPUT); digitalWrite(PWM_M1, HIGH); digitalWrite(PWM_M2, HIGH); digitalWrite(PWM_M3, HIGH); digitalWrite(PWM_M4, HIGH); /* analogWrite(PWM_M1, 255); analogWrite(PWM_M2, 255); analogWrite(PWM_M3, 255); analogWrite(PWM_M4, 255); */ } void loop(){ Shifter.setRegisterPin(M1A, LOW); Shifter.setRegisterPin(M3B, HIGH); delay(500); Shifter.setRegisterPin(M1A, HIGH); Shifter.setRegisterPin(M3B, LOW); delay(500); analogWrite(PWM_M1, 30); Shifter.setRegisterPin(M1A, LOW); Shifter.setRegisterPin(M3B, LOW); delay(500); Shifter.setRegisterPin(M1A, HIGH); Shifter.setRegisterPin(M3B, HIGH); delay(500); analogWrite(PWM_M1, 255); }
// код из видео https://www.youtube.com/watch?v=aLGFBG-VDdo #include <Shift595.h> // https://sites.google.com/site/shift595arduino/downloads #include <IRremote.h> #define POWER_KEY 0x40BF30CF // коды пульта ДУ #define KEY1 0x40BF7887 #define KEY2 0x40BFF807 #define KEY3 0xC03FC03F #define KEY4 0xC03F40BF #define M1A 2 #define M1B 3 #define M2A 1 #define M2B 4 #define M4A 0 #define M4B 6 #define M3A 5 #define M3B 7 #define PWM_M1 11 #define PWM_M2 3 #define PWM_M3 6 #define PWM_M4 5 #define SER1 10 #define SER2 9 #define PWRON 7 IRrecv irrecv(SER1); Shift595 Shifter(8, 12, 4, 1); decode_results results; void setup() { irrecv.enableIRIn(); pinMode(PWRON, OUTPUT); digitalWrite(PWRON, LOW); // включение 74HC595 pinMode(PWM_M1, OUTPUT); // включение L293D pinMode(PWM_M2, OUTPUT); pinMode(PWM_M3, OUTPUT); pinMode(PWM_M4, OUTPUT); digitalWrite(PWM_M1, HIGH); digitalWrite(PWM_M2, HIGH); digitalWrite(PWM_M3, HIGH); digitalWrite(PWM_M4, HIGH); /* analogWrite(PWM_M1, 255); analogWrite(PWM_M2, 255); analogWrite(PWM_M3, 255); analogWrite(PWM_M4, 255); */ } void loop(){ if (irrecv.decode(&results)) { if (results.value == KEY1){ Shifter.setRegisterPin(M1A, HIGH); Shifter.setRegisterPin(M1B, HIGH); Shifter.setRegisterPin(M2A, HIGH); Shifter.setRegisterPin(M2B, HIGH); } else if (results.value == KEY2){ Shifter.setRegisterPin(M1A, LOW); Shifter.setRegisterPin(M1B, LOW); Shifter.setRegisterPin(M2A, LOW); Shifter.setRegisterPin(M2B, LOW); } else if (results.value == KEY3){ Shifter.setRegisterPin(M3A, HIGH); Shifter.setRegisterPin(M3B, HIGH); Shifter.setRegisterPin(M4A, HIGH); Shifter.setRegisterPin(M4B, HIGH); } else if (results.value == KEY4){ Shifter.setRegisterPin(M3A, LOW); Shifter.setRegisterPin(M3B, LOW); Shifter.setRegisterPin(M4A, LOW); Shifter.setRegisterPin(M4B, LOW); } else if (results.value == POWER_KEY) digitalWrite(PWRON, !digitalRead(PWRON)); irrecv.resume(); // Receive the next value } }