Greetings!
I am currently a first year student in Electronic Maintenance. We've been learning Arduino for a while and we just started talking about Serial Peripheral Interface. We also made our own H-Bridge in order to run motors. I've been messing around and finding out how to make a DC run slowly accelerate through SPI and arrays, as I've already managed to do it through conventional methods, using an L2938N motor driver. I made a first array for the motor speed comprised of just pure bits (0-16). Then I made a second array that maps the first array and stores the speed as a float.
This is the code :
#include <SPI.h>
byte velo_motor[] = {
B00000000,
B00000001,
B00000010,
B00000011,
B00000100,
B00000101,
B00000110,
B00000111,
B00001000,
B00001001,
B00001010,
B00001011,
B00001100,
B00001101,
B00001110,
B00001111,
};
const int IN1 = 3;
const int IN2 = 4;
const int ENA = 5;
const int ESPERA = 6;
const int SS_PIN = 10;
void setup() {
Serial.begin(9600);
SPI.begin();
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ESPERA, OUTPUT);
}
void loop() {
float velo_motor2[16]; // Second array which stores the speed as a float
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(ESPERA, HIGH);
for (int i = 0; i < 16; i++) {
velo_motor2[i] = map(velo_motor[i], 0, 255, 0, 4500); // Map to range 0-255
digitalWrite(ENA, map(velo_motor[i], 0, 255, 0, 4500));
Serial.println(velo_motor2[i]); // Print each mapped value
delay(800); // Wait for 400 milliseconds before printing the next value
}
}
I hooked up the motor but it doesnt slowly accelerate despite the values being quite correct. Is there something I'm doing wrong? I am a complete beginner at this and am eager to learn, so any input would help. Thank you!