takeup/ino/demo/demo.ino

67 lines
1.5 KiB
Arduino
Raw Normal View History

2021-11-16 03:45:31 +00:00
/**
* Prototype
* Arduino Duemilanove
* L298N shield V03
* https://traction-design.be/home/arduino-l298n-shield-v03-from-flamingoeda-com/
2021-11-16 03:45:31 +00:00
*
* Pin 13 = motor A or coil A +
* Pin 12 = motor A or coil A
* Pin 11 = motor B or coil B +
* Pin 10 = motor A or coil A enable
* Pin 9 = motor B or coil B enable
* Pin 8 = motor B or coil B
**/
#define Apos 9
#define Aneg 10
2021-11-16 03:45:31 +00:00
#define Aenable 10
void setup() {
pinMode(Apos, OUTPUT);
pinMode(Aneg, OUTPUT);
pinMode(Aenable, OUTPUT);
}
void loop() {
clockwise();
set_speed(250);
2021-11-16 03:45:31 +00:00
delay(5000);
brake();
delay(2000);
counter_clockwise();
set_speed(250);
2021-11-16 03:45:31 +00:00
delay(5000);
brake();
delay(2000);
}
//input value from 0 to 255
void set_speed (int val){
analogWrite(Aenable, val);
}
void clockwise(){
digitalWrite(Apos, HIGH);
digitalWrite(Aneg, LOW);
}
void counter_clockwise(){
digitalWrite(Apos, LOW);
digitalWrite(Aneg, HIGH);
}
void brake (){
digitalWrite(Aenable, LOW);
}
/**
* Vex = higher voltage that can power the motor and/or the shield as well as the Arduino if wanted
* 5V = Must be a clean 5V that can power the Arduino and shield, and if wanted also the motor itself
* GND = ass always, the ground of everything
* B- = Connection of the first motor or first winding of the stepper motor
* B+ = Connection of the first motor or first winding of the stepper motor
* A- = Connection of the second motor or second winding of the stepper motor
* A+ = Connection of the second motor or second winding of the stepper motor
**/